you can play your song now :D

This commit is contained in:
2026-01-15 07:58:09 +11:00
parent 6350de7899
commit 6a96bdd86a
7 changed files with 135 additions and 8 deletions

View File

@@ -7,6 +7,8 @@ from ui.widgets.chunk_types.audio import AudioChunk, Chunk
from ui.widgets.play_head import PlayHead
from project import ChunkType
from song_player import SongPlayer
class TimelineRow(Horizontal):
DEFAULT_CSS = """
@@ -64,6 +66,7 @@ class Timeline(Vertical):
super().__init__(id="timeline")
self.calc_bar_offset()
self.song_player = SongPlayer(self, self.app.project)
def calc_bar_offset(self):
self.bar_offset = self.app.project.bpm / 8 * (0.03333333333 / self.app.zoom_level)
@@ -87,6 +90,19 @@ class Timeline(Vertical):
self.calc_bar_offset()
self.handle_zoom()
@on(events.MouseDown)
async def mouse_down(self, event: events.MouseDown):
if event.button != 2: return
# get bar number
bar_number = event.x / self.bar_offset
# convert bar number to seconds
seconds = bar_number / self.app.project.seconds_per_bar
# seek to number of seconds
self.song_player.seek(seconds)
def handle_zoom(self):
for chunk in self.query(Chunk):
chunk.calculate_size()
@@ -100,6 +116,9 @@ class Timeline(Vertical):
bar_line.display = False
else:
bar_line.display = True
if self.song_player.paused and self.song_player.project:
self.run_worker(self.song_player.update_visual_playhead())
def compose(self) -> ComposeResult:
@@ -116,7 +135,7 @@ class Timeline(Vertical):
elif chunk.chunk_type == ChunkType.AUDIO:
yield AudioChunk(chunk.audio_data, chunk.sample_rate, chunk.name, chunk.position)
for i in range(1, self.app.project.song_length):
for i in range(1, self.app.project.song_length+1):
bar = None
if i % 4 == 0:
bar = Rule.vertical(classes="bar-line", line_style="double")