[gnome-music/gnome-3-10] Skip current track when shuffling tracks



commit a225e35804ab99b701ede744cc0f72b3c504db3a
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Mon Feb 10 19:03:40 2014 +0100

    Skip current track when shuffling tracks
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721297

 gnomemusic/player.py |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index d868740..981ee52 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -190,6 +190,16 @@ class Player(GObject.GObject):
     def _on_playlist_size_changed(self, path, _iter=None, data=None):
         self._sync_prev_next()
 
+    def _get_random_iter(self, currentTrack):
+        currentPath = int(self.playlist.get_path(currentTrack).to_string())
+        rows = self.playlist.iter_n_children(None)
+        if rows == 1:
+            return currentTrack
+        rand = currentPath
+        while rand == currentPath:
+            rand = randint(0, rows - 1)
+        return self.playlist.get_iter_from_string(str(rand))
+
     def _get_next_track(self):
         if self.currentTrack and self.currentTrack.valid():
             currentTrack = self.playlist.get_iter(self.currentTrack.get_path())
@@ -212,10 +222,8 @@ class Player(GObject.GObject):
             if currentTrack:
                 nextTrack = self.playlist.iter_next(currentTrack)
         elif self.repeat == RepeatType.SHUFFLE:
-            nextTrack = self.playlist.get_iter_first()
-            rows = self.playlist.iter_n_children(None)
-            for i in range(1, randint(1, rows)):
-                nextTrack = self.playlist.iter_next(nextTrack)
+            if currentTrack:
+                nextTrack = self._get_random_iter(currentTrack)
 
         if nextTrack:
             return Gtk.TreeRowReference.new(self.playlist, self.playlist.get_path(nextTrack))
@@ -254,10 +262,8 @@ class Player(GObject.GObject):
             if currentTrack:
                 previousTrack = self.playlist.iter_previous(currentTrack)
         elif self.repeat == RepeatType.SHUFFLE:
-            previousTrack = self.playlist.get_iter_first()
-            rows = self.playlist.iter_n_children(None)
-            for i in range(1, randint(1, rows)):
-                previousTrack = self.playlist.iter_next(previousTrack)
+            if currentTrack:
+                previousTrack = self._get_random_iter(currentTrack)
 
         if previousTrack:
             return Gtk.TreeRowReference.new(self.playlist, self.playlist.get_path(previousTrack))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]