From da06f1fff5c4afaf584fd4df7d52349dcd0b1b0e Mon Sep 17 00:00:00 2001 From: coderkun Date: Sat, 16 Apr 2016 19:14:34 +0200 Subject: [PATCH] fix changing of song by storing playlist position for each track (fixes #1) --- mcg/mcg.py | 14 +++++++++++++- mcg/mcgGtk.py | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/mcg/mcg.py b/mcg/mcg.py index adcaddc..1d5ed35 100644 --- a/mcg/mcg.py +++ b/mcg/mcg.py @@ -423,7 +423,7 @@ class Client(Base): song['time'] = 0 if 'date' not in song: song['date'] = None - track = MCGTrack(song['artist'], song['title'], song['track'], song['time'], song['date'], song['file']) + track = MCGPlaylistTrack(song['artist'], song['title'], song['track'], song['time'], song['date'], song['file'], song['pos']) self._logger.debug("track: %r", track) # Album if 'album' not in song: @@ -857,6 +857,18 @@ class MCGTrack: +class MCGPlaylistTrack(MCGTrack): + def __init__(self, artists, title, track, length, date, file, pos): + MCGTrack.__init__(self, artists, title, track, length, date, file) + self._pos = int(pos) + + + def get_pos(self): + return self._pos + + + + class MCGConfig(configparser.ConfigParser): CONFIG_DIR = '~/.config/mcg/' diff --git a/mcg/mcgGtk.py b/mcg/mcgGtk.py index b9600fe..7bba182 100755 --- a/mcg/mcgGtk.py +++ b/mcg/mcgGtk.py @@ -828,10 +828,10 @@ class CoverPanel(Panel, Gtk.VBox): value = int(self._songs_scale.get_value()) time = self._current_album.get_length() tracks = self._current_album.get_tracks() - pos = len(tracks) - for index in range(pos-1, -1, -1): + pos = 0 + for index in range(len(tracks)-1, -1, -1): time = time - tracks[index].get_length() - pos = pos - 1 + pos = tracks[index].get_pos() if time < value: break time = max(value - time - 1, 0)