diff --git a/wobuzz/player/player.py b/wobuzz/player/player.py index df6cb06..ef5fc83 100644 --- a/wobuzz/player/player.py +++ b/wobuzz/player/player.py @@ -18,6 +18,7 @@ class Player: self.track_progress = TrackProgress(self.app) self.current_playlist = Playlist(self.app, "None") + self.history = Playlist(self.app, "History") self.playing = False self.paused = False @@ -38,15 +39,19 @@ class Player: def track_finished(self): if not self.current_playlist.on_last_track(): - previous_track = self.current_playlist.current_track self.current_sound, self.current_sound_duration = self.current_playlist.next_track() self.play() self.track_progress.start() - self.app.gui.on_track_change(previous_track, self.current_playlist.current_track) + + self.history.append_track(self.current_playlist.current_track) + + last_track = self.history.h_last_track() + + self.app.gui.on_track_change(last_track, self.current_playlist.current_track) if self.app.settings.clear_track_cache: - previous_track.clear_cache() + last_track.clear_cache() else: self.stop() @@ -58,6 +63,8 @@ class Player: self.play() self.track_progress.start() + self.history.append_track(self.current_playlist.current_track) + self.app.gui.on_track_change(None, self.current_playlist.current_track) self.app.gui.track_control.on_playstate_update() @@ -65,16 +72,26 @@ class Player: def play_track_in_playlist(self, track_index): self.stop() - previous_track = self.current_playlist.current_track + if len(self.history.tracks) == 0: + self.history.append_track(self.current_playlist.current_track) self.current_sound, self.current_sound_duration = self.current_playlist.set_track(track_index) self.play() self.track_progress.start() - self.app.gui.on_track_change(previous_track, self.current_playlist.current_track) - if self.app.settings.clear_track_cache and not previous_track == self.current_playlist.current_track: - previous_track.clear_cache() + self.history.append_track(self.current_playlist.current_track) + + last_track = self.history.h_last_track() + + self.app.gui.on_track_change(last_track, self.current_playlist.current_track) + + if ( + self.app.settings.clear_track_cache and + not last_track is None and + not last_track == self.current_playlist.current_track + ): + last_track.clear_cache() def pause(self): self.music_channel.pause() @@ -102,8 +119,6 @@ class Player: if not self.current_playlist.on_first_track(): self.music_channel.stop() - last_track = self.current_playlist.current_track - self.current_sound, self.current_sound_duration = self.current_playlist.previous_track() self.track_progress.stop() @@ -111,7 +126,9 @@ class Player: self.play() self.track_progress.start() - self.app.gui.on_track_change(last_track, self.current_playlist.current_track) + self.history.append_track(self.current_playlist.current_track) + + self.app.gui.on_track_change(self.history.h_last_track(), self.current_playlist.current_track) def stop(self): self.music_channel.stop() diff --git a/wobuzz/player/playlist.py b/wobuzz/player/playlist.py index cdc2156..604db73 100644 --- a/wobuzz/player/playlist.py +++ b/wobuzz/player/playlist.py @@ -116,3 +116,15 @@ class Playlist: wbz.write(wbz_data) wbz.close() + def append_track(self, track): + self.tracks.append(track) + + if self.view: + self.view.append_track(track) + + def h_last_track(self): + # get last track in history (only gets used in player.history) + + if len(self.tracks) > 1: + return self.tracks[-2] + diff --git a/wobuzz/ui/playlist.py b/wobuzz/ui/playlist.py index 04df5d3..9e6b4da 100644 --- a/wobuzz/ui/playlist.py +++ b/wobuzz/ui/playlist.py @@ -19,12 +19,11 @@ class PlaylistView(QTreeWidget): playlist.view = self self.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove) - #self.setAcceptDrops(True) self.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) self.setColumnCount(4) - self.play_icon = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart) + self.playing_mark = QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart) headers = [ "", @@ -107,7 +106,7 @@ class PlaylistView(QTreeWidget): i += 1 if not self.topLevelItemCount() == 0: - self.topLevelItem(0).setIcon(0, self.play_icon) + self.topLevelItem(0).setIcon(0, self.playing_mark) def on_track_activation(self, item, column): if not self.app.player.current_playlist == self.playlist: @@ -117,10 +116,16 @@ class PlaylistView(QTreeWidget): self.app.player.play_track_in_playlist(index) def on_track_change(self, previous_track, track): + # remove playing mark from first track bc it may not be in the history + self.topLevelItem(0).setIcon(0, QIcon(None)) + # unmark the previous track and mark the current track as playing if previous_track: previous_track.item.setIcon(0, QIcon(None)) if track: - track.item.setIcon(0, self.play_icon) + track.item.setIcon(0, self.playing_mark) + + def append_track(self, track): + TrackItem(track, self.topLevelItemCount() - 1, self)