project loading fixes, also some zoom improvements

This commit is contained in:
2026-01-16 08:26:15 +11:00
parent 1cdd04f67b
commit c2db7f6aca
7 changed files with 25 additions and 38 deletions

View File

@@ -23,30 +23,6 @@ if __name__ == "__main__":
*librosa.load("120 bpm amen break.mp3", mono=False, sr=test_project.sample_rate),
name="120 bpm amen break.mp3"
))
drum_channel.chunks.append(AudioChannelChunk(
drum_channel,
position=1,
*librosa.load("120 bpm amen break.mp3", mono=False, sr=test_project.sample_rate),
name="120 bpm amen break.mp3"
))
drum_channel.chunks.append(AudioChannelChunk(
drum_channel,
position=2,
*librosa.load("120 bpm amen break.mp3", mono=False, sr=test_project.sample_rate),
name="120 bpm amen break.mp3"
))
drum_channel.chunks.append(AudioChannelChunk(
drum_channel,
position=3,
*librosa.load("120 bpm amen break.mp3", mono=False, sr=test_project.sample_rate),
name="120 bpm amen break.mp3"
))
drum_channel.chunks.append(AudioChannelChunk(
drum_channel,
position=4,
*librosa.load("120 bpm amen break.mp3", mono=False, sr=test_project.sample_rate),
name="120 bpm amen break.mp3"
))
piano_channel = ProjectChannel(
test_project,
@@ -65,9 +41,9 @@ if __name__ == "__main__":
test_project.channels.append(piano_channel)
test_project.write_to_file("test_project.tdp")"""
test_project = Project()#.from_file("test_project.tdp")
#test_project = Project.from_file("test_project.tdp")
# start the ui
print("Starting UI...")
app = AppUI(test_project)
app = AppUI(Project())
app.run()

Binary file not shown.

View File

@@ -10,7 +10,8 @@ from ui.widgets.project_settings import ProjectSettings
from ui.widgets.channel import Channel
from ui.widgets.context_menu import ContextMenu, NoSelectStatic
from project import ProjectChannel, Project
from project import ProjectChannel, Project, ChunkType
from ui.widgets.chunk_types.audio import AudioChunk, Chunk
class AppUI(App):
@@ -71,8 +72,9 @@ class AppUI(App):
self.push_screen(FileSave(
filters=Filters(
("Any", lambda _: True),
("TerminalDAW Project File", lambda p: p.suffix.lower() == ".tdp")
("TerminalDAW Project File", lambda p: p.suffix.lower() == ".tdp"),
("Any", lambda _: True)
)
), callback=callback)
@@ -113,6 +115,7 @@ class AppUI(App):
row.styles.width = timeline.bar_offset * self.project.song_length
rows.mount(row)
for chunk in channel.chunks:
@@ -121,14 +124,14 @@ class AppUI(App):
elif chunk.chunk_type == ChunkType.AUDIO:
row.mount(AudioChunk(chunk.audio_data, chunk.sample_rate, chunk.name, chunk.position))
rows.mount(row)
self.notify(f"Loaded \"{path}\"")
self.push_screen(FileOpen(
filters=Filters(
("Any", lambda _: True),
("TerminalDAW Project File", lambda p: p.suffix.lower() == ".tdp")
("TerminalDAW Project File", lambda p: p.suffix.lower() == ".tdp"),
("Any", lambda _: True)
)
), callback=callback)

View File

@@ -57,6 +57,7 @@ class Channel(VerticalGroup):
self.solo = solo
self.pan = pan
self.volume = volume
print(self.channel_name)
def on_checkbox_changed(self, event: Checkbox.Changed):
if event.checkbox.id == "mute":

View File

@@ -86,7 +86,7 @@ class AudioChunk(Chunk):
# get the decibel values from that
y = librosa.amplitude_to_db(rms, ref=np.min)
print(x)
plot.bar(
x,
y,

View File

@@ -32,6 +32,7 @@ class Sidebar(Vertical):
for i, channel in enumerate(self.app.project.channels):
yield Channel(
i,
channel,
channel.name,
channel.mute,
channel.solo,

View File

@@ -83,7 +83,7 @@ class Timeline(Vertical):
self.app.zoom_level += (self.app.scroll_sensitivity_x / 200)
self.calc_bar_offset()
self.app.last_zoom_level = self.app.zoom_level
self.handle_zoom()
await self.handle_zoom()
@on(events.MouseScrollUp)
async def mouse_scroll_up(self, event: events.MouseScrollUp):
@@ -92,7 +92,7 @@ class Timeline(Vertical):
if self.app.zoom_level != self.app.last_zoom_level:
self.app.last_zoom_level = self.app.zoom_level
self.calc_bar_offset()
self.handle_zoom()
await self.handle_zoom()
@on(events.MouseDown)
async def mouse_down(self, event: events.MouseDown):
@@ -107,7 +107,7 @@ class Timeline(Vertical):
# seek to number of seconds
self.song_player.seek(seconds)
def handle_zoom(self):
async def handle_zoom(self):
for chunk in self.query(Chunk):
chunk.calculate_size()
chunk.update_offset(self)
@@ -119,10 +119,16 @@ class Timeline(Vertical):
if self.app.zoom_level >= 0.09 and bar_line.has_class("beat-line"):
bar_line.display = False
else:
if self.app.zoom_level < 0.18:
bar_line.display = True
else:
if bar_line.has_class("bar-line") and bar_line.index % 16 == 0:
bar_line.display = True
else:
bar_line.display = False
if self.song_player.paused and self.song_player.project:
self.run_worker(self.song_player.update_visual_playhead())
await self.song_player.update_visual_playhead()
def compose(self) -> ComposeResult: