From 813588e8e9181394ad7ee53a4f856a9664771d18 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Tue, 7 Nov 2023 20:11:12 +0000 Subject: [PATCH] WIP V3: track stop implemented --- app/musicmuster.py | 99 +++++++++++++++++--------------------------- app/playlistmodel.py | 32 +++++++++++++- 2 files changed, 68 insertions(+), 63 deletions(-) diff --git a/app/musicmuster.py b/app/musicmuster.py index 423fe27..1349e66 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -684,51 +684,6 @@ class Window(QMainWindow, Ui_MainWindow): self.actionPlay_next.setEnabled(True) self.statusbar.showMessage("Play controls: Enabled", 0) - def end_of_track_actions(self) -> None: - """ - Clean up after track played - - Actions required: - - Set flag to say we're not playing a track - - Tell playlist_tab track has finished - - Reset PlaylistTrack objects - - Reset clocks - - Reset fade graph - - Update headers - - Enable controls - """ - - # Set flag to say we're not playing a track so that timer ticks - # don't see player=None and kick off end-of-track actions - self.playing = False - - # Tell playlist_tab track has finished - # TODO Reimplement as a signal - # if self.current_track.playlist_tab: - # self.current_track.playlist_tab.play_ended() - - # Reset fade graph - if track_sequence.now.fade_graph: - track_sequence.now.fade_graph.clear() - - # Reset PlaylistTrack objects - if track_sequence.now.track_id: - track_sequence.previous = track_sequence.now - track_sequence.now = PlaylistTrack() - - # Reset clocks - self.frame_fade.setStyleSheet("") - self.frame_silent.setStyleSheet("") - self.label_elapsed_timer.setText("00:00 / 00:00") - self.label_fade_timer.setText("00:00") - self.label_silent_timer.setText("00:00") - - # Update headers - self.update_headers() - - # Enable controls - self.enable_play_next_controls() - def export_playlist_tab(self) -> None: """Export the current playlist to an m3u file""" @@ -1474,19 +1429,29 @@ class Window(QMainWindow, Ui_MainWindow): self.stop_playing(fade=False) - def stop_playing(self, fade=True) -> None: + def stop_playing(self, fade: bool = True) -> None: """ Stop playing current track Actions required: + - Set flag to say we're not playing a track - Return if not playing - Stop/fade track - Reset playlist_tab colour - - Run end-of-track actions + - Tell playlist_tab track has finished + - Reset PlaylistTrack objects + - Reset clocks + - Reset fade graph + - Update headers + - Enable controls """ - # Return if not playing - if not self.playing: + # Set flag to say we're not playing a track so that timer ticks + # don't see player=None and kick off end-of-track actions + if self.playing: + self.playing = False + else: + # Return if not playing return # Stop/fade track @@ -1496,20 +1461,30 @@ class Window(QMainWindow, Ui_MainWindow): else: self.music.stop() - # Reset playlist_tab colour - # TODO Reimplement - # if self.current_track.playlist_tab: - # if self.current_track.playlist_tab == self.next_track.playlist_tab: - # self.set_tab_colour( - # self.current_track.playlist_tab, QColor(Config.COLOUR_NEXT_TAB) - # ) - # else: - # self.set_tab_colour( - # self.current_track.playlist_tab, QColor(Config.COLOUR_NORMAL_TAB) - # ) + # Reset fade graph + if track_sequence.now.fade_graph: + track_sequence.now.fade_graph.clear() - # Run end-of-track actions - self.end_of_track_actions() + # Reset track_sequence objects + if track_sequence.now.track_id: + track_sequence.previous = track_sequence.now + track_sequence.now = PlaylistTrack() + + # Tell model previous track has finished + self.active_model().previous_track_ended() + + # Reset clocks + self.frame_fade.setStyleSheet("") + self.frame_silent.setStyleSheet("") + self.label_elapsed_timer.setText("00:00 / 00:00") + self.label_fade_timer.setText("00:00") + self.label_silent_timer.setText("00:00") + + # Update headers + self.update_headers() + + # Enable controls + self.enable_play_next_controls() def tab_change(self): """Called when active tab changed""" diff --git a/app/playlistmodel.py b/app/playlistmodel.py index b3ad2a4..76e76e1 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -257,6 +257,7 @@ class PlaylistModel(QAbstractTableModel): plr = session.get(PlaylistRows, track_sequence.now.plr_id) if plr: plr.played = True + self.refresh_row(session, plr.plr_rownum) # Find next track # Get all unplayed track rows @@ -581,6 +582,35 @@ class PlaylistModel(QAbstractTableModel): # Update display self.invalidate_rows(list(row_map.keys())) + def previous_track_ended(self) -> None: + """ + Notification from musicmuster that the previous track has ended. + + Actions required: + - sanity check + - update display + - update track times + """ + + # Sanity check + if not track_sequence.previous.track_id: + log.error( + "playlistmodel:previous_track_ended called with no current track" + ) + return + if track_sequence.previous.plr_rownum is None: + log.error( + "playlistmodel:previous_track_ended called with no row number " + f"({track_sequence.previous=})" + ) + return + + # Update display + self.invalidate_row(track_sequence.previous.plr_rownum) + + # Update track times + # TODO + def refresh_data(self, session: scoped_session): """Populate dicts for data calls""" @@ -593,7 +623,7 @@ class PlaylistModel(QAbstractTableModel): """Populate dict for one row for data calls""" p = PlaylistRows.deep_row(session, self.playlist_id, row_number) - self.playlist_rows[p.plr_rownum] = PlaylistRowData(p) + self.playlist_rows[row_number] = PlaylistRowData(p) def rowCount(self, index: QModelIndex = QModelIndex()) -> int: """Standard function for view"""