From eae8870d4d154253e54bb73a252bd2ecfd7aff86 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Thu, 16 Nov 2023 19:09:41 +0000 Subject: [PATCH] WIP V3: resume working --- app/classes.py | 1 + app/musicmuster.py | 57 ++++++++++++++++------------------------------ 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/app/classes.py b/app/classes.py index 2fa2993..fc21b37 100644 --- a/app/classes.py +++ b/app/classes.py @@ -114,6 +114,7 @@ class PlaylistTrack: self.playlist_id: Optional[int] = None self.plr_id: Optional[int] = None self.plr_rownum: Optional[int] = None + self.resume_marker: Optional[float] = None self.silence_at: Optional[int] = None self.start_gap: Optional[int] = None self.start_time: Optional[datetime] = None diff --git a/app/musicmuster.py b/app/musicmuster.py index 055b696..4bf7761 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -197,7 +197,6 @@ class Window(QMainWindow, Ui_MainWindow): self.music: music.Music = music.Music() self.playing: bool = False - self.previous_track_position: Optional[float] = None self.selected_plrs: Optional[List[PlaylistRows]] = None self.set_main_window_size() @@ -1217,45 +1216,27 @@ class Window(QMainWindow, Ui_MainWindow): - If a track is playing, make that the next track """ - return - # TODO Reimplement without reference to playlist_tab - # # Return if no saved position - # if not self.previous_track_position: - # return + # Return if no saved position + if not track_sequence.previous.resume_marker: + return - # # Note any playing track as this will become the next track - # playing_track = None - # if self.current_track.track_id: - # playing_track = self.current_track + # We want to use play_next() to resume, so copy the previous + # track to the next track: + track_sequence.next = track_sequence.previous - # # Set next plr to be track to resume - # if not self.previous_track.plr_id: - # return - # # TODO Reimplement following two lines - # # if not self.previous_track.playlist_tab: - # # return + # Now resume playing the now-next track + self.play_next(track_sequence.next.resume_marker) - # # Resume last track - # # TODO Reimplement next four lines - # # self.set_next_plr_id( - # # self.previous_track.plr_id, self.previous_track.playlist_tab - # # ) - # # self.play_next(self.previous_track_position) - - # # Adjust track info so that clocks and graph are correct. - # # Easiest way is to fake the start time. - # if self.current_track.start_time and self.current_track.duration: - # elapsed_ms = self.current_track.duration * self.previous_track_position - # self.current_track.start_time -= timedelta(milliseconds=elapsed_ms) - - # # If a track was playing when we were called, get details to - # # set it as the next track - # if playing_track: - # if not playing_track.plr_id: - # return - # if not playing_track.playlist_tab: - # return - # self.set_next_plr_id(playing_track.plr_id, playing_track.playlist_tab) + # Adjust track info so that clocks and graph are correct. + # We need to fake the start time to reflect where we resumed the + # track + if ( + track_sequence.now.start_time + and track_sequence.now.duration + and track_sequence.now.resume_marker + ): + elapsed_ms = track_sequence.now.duration * track_sequence.now.resume_marker + track_sequence.now.start_time -= timedelta(milliseconds=elapsed_ms) def save_as_template(self) -> None: """Save current playlist as template""" @@ -1451,7 +1432,7 @@ class Window(QMainWindow, Ui_MainWindow): return # Stop/fade track - self.previous_track_position = self.music.get_position() + track_sequence.now.resume_marker = self.music.get_position() if fade: self.music.fade() else: