[banshee] Shuffler: fix shuffle for 2 tracks when repeat is enabled (bgo#671221)



commit 6781516ac468a0bc3b1d45beec0d560ea40ac30f
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Mon Feb 17 02:00:47 2014 +0100

    Shuffler: fix shuffle for 2 tracks when repeat is enabled (bgo#671221)
    
    Use last_track.LastPlayed datetime value instead of last_random,
    because it would avoid a glitch about the way the current logic
    resets the RandomByTrack mode.
    
    We can explain this glitch by explaining here the hypothetical
    sequence of events of 2 tracks being played, whose duration is
    exactly 1 minute each:
    
    0:00 play track1 manually
    --
    0:58 requestnexttrack fired, lastplayedstamp of track1 updated to 0:58
    0:59 query to find a random track from a set which have lastplayedstamp < 0:00 , found track2
    0:59 chosen track2, set last_random to 0:59
    1:00 track2 begins to play, lastplayedstamp of track1 updated to 1:00
    --
    1:58 requestnexttrack fired, lastplayedstamp of track2 updated to 1:58
    1:59 query to find a random track from a set which have lastplayedstamp < 0:00 , found nothing
    1:59 query to find a random track from a set which have lastplayedstamp < 0:59 (last_random) , found 
nothing
    
    This glitch makes the Repeat-All mode not work when the source to
    play has 2 tracks, as you just have seen. If we add a 3rd track to
    the mix, the random mode is sub-optimal, but at least the Repeat-All
    mode works, and here would be the sequence of events:
    
    0:00 play track1 manually
    --
    0:58 requestnexttrack fired, lastplayedstamp of track1 updated to 0:58
    0:59 query to find a random track from a set which have lastplayedstamp < 0:00 , found track2 & track3
    0:59 chosen track2, set last_random to 0:59
    1:00 track2 begins to play, lastplayedstamp of track1 updated to 1:00
    --
    1:58 requestnexttrack fired, lastplayedstamp of track2 updated to 1:58
    1:59 query to find a random track from a set which have lastplayedstamp < 0:00 , found track3
    1:59 chosen track3, set last_random to 1:59
    2:00 track3 begins to play, lastplayedstamp of track2 updated to 2:00
    --
    2:58 requestnexttrack fired, lastplayedstamp of track3 updated to 2:58
    2:59 query to find a random track from a set which have lastplayedstamp < 0:00, found nothing
    2:59 query to find a random track from a set which have lastplayedstamp < 1:59 (last_random) , found 
track1
    2:59 chosen track1 , set last_random to 2:59
    3:00 track1 begins to play, lastplayedstamp of track3 updated to 3:00
    ...
    
    
    Partial fix for bgo#671221 (when there are 2 tracks to play)

 .../Banshee.Collection.Database/Shuffler.cs        |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/Shuffler.cs 
b/src/Core/Banshee.Services/Banshee.Collection.Database/Shuffler.cs
index 1f4fd45..335c19d 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/Shuffler.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/Shuffler.cs
@@ -58,7 +58,6 @@ namespace Banshee.Collection.Database
         private static HyenaSqliteCommand add_discard_cmd = new HyenaSqliteCommand (String.Format ("{0} 
VALUES (?, ?, ?, ?)", modify_sql));
 
         private DateTime random_began_at = DateTime.MinValue;
-        private DateTime last_random = DateTime.MinValue;
         private List<RandomBy> random_modes;
         private Dictionary<TypeExtensionNode, RandomBy> node_map = new Dictionary<TypeExtensionNode, 
RandomBy> ();
         private DatabaseTrackListModel model;
@@ -81,6 +80,8 @@ namespace Banshee.Collection.Database
 
         private void OnPlayerEvent (Banshee.MediaEngine.PlayerEventArgs args)
         {
+            // TODO: check if we can assign last_track before returning the track inside GetRandom(), to 
avoid subscribing
+            //       to an event (if yes, the field should probably be renamed to last_random_track)
             last_track = ServiceManager.PlayerEngine.CurrentTrack;
         }
 
@@ -164,16 +165,14 @@ namespace Banshee.Collection.Database
                 }
 
                 if (random_began_at < notPlayedSince) {
-                    random_began_at = last_random = notPlayedSince;
+                    random_began_at = notPlayedSince;
                 }
 
                 TrackInfo track = GetRandomTrack (mode, repeat, resetSinceTime);
                 if (track == null && repeat) {
-                    random_began_at = (random_began_at == last_random) ? DateTime.Now : last_random;
+                    random_began_at = last_track.LastPlayed;
                     track = GetRandomTrack (mode, repeat, true);
                 }
-
-                last_random = DateTime.Now;
                 return track;
             }
         }
@@ -222,7 +221,7 @@ namespace Banshee.Collection.Database
 
                 if (!random.IsReady) {
                     if (!random.Next (random_began_at) && repeat) {
-                        random_began_at = last_random;
+                        random_began_at = last_track.LastPlayed;
                         random.Next (random_began_at);
                     }
                 }


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