Resending the patch after I screwed up with git patch formatting.

Fix for the problem where order with priorities gets out of whack in case it's
reordered by SetRandom() while another song is currently playing.
What happens is, if some song is already playing and you have set some
priorities before switching on the random mode, and then turn the mode on, the
original code swaps position of the first song in the order (i.e., the highest
priority song) with current, so that current is 0 (which it should be). The
problem is, the "original" first song then goes to the place "current" song was
after reordering, wherever that is, instead of going after the "current" song.
This patch fixes the issue.
Also the fix makes MoveOrder() public, because why shouldn't it be, anyway.  It
certainly makes more sense than just having SwapOrders() public for some
reason.

Signed-off-by: Eugene Baklanov <miltenfirem...@gmail.com>
---
 src/queue/Playlist.cxx |  2 +-
 src/queue/Queue.hxx    | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/queue/Playlist.cxx b/src/queue/Playlist.cxx
index cc0a9ef..361cf9d 100644
--- a/src/queue/Playlist.cxx
+++ b/src/queue/Playlist.cxx
@@ -310,7 +310,7 @@ playlist::SetRandom(PlayerControl &pc, bool status)
                           playlist is played after that */
                        unsigned current_order =
                                queue.PositionToOrder(current_position);
-                       queue.SwapOrders(0, current_order);
+                       queue.MoveOrder(current_order, 0);
                        current = 0;
                } else
                        current = -1;
diff --git a/src/queue/Queue.hxx b/src/queue/Queue.hxx
index 4acde76..314a752 100644
--- a/src/queue/Queue.hxx
+++ b/src/queue/Queue.hxx
@@ -283,6 +283,11 @@ struct Queue {
        }
 
        /**
+        * Moves a song to a new position in the "order" list.
+        */
+       void MoveOrder(unsigned from_order, unsigned to_order);
+
+       /**
         * Moves a song to a new position.
         */
        void MovePostion(unsigned from, unsigned to);
@@ -350,11 +355,6 @@ struct Queue {
                              uint8_t priority, int after_order);
 
 private:
-       /**
-        * Moves a song to a new position in the "order" list.
-        */
-       void MoveOrder(unsigned from_order, unsigned to_order);
-
        void MoveItemTo(unsigned from, unsigned to) {
                unsigned from_id = items[from].id;
 
-- 
2.9.3.dirty

_______________________________________________
mpd-devel mailing list
mpd-devel@musicpd.org
http://mailman.blarg.de/listinfo/mpd-devel

Reply via email to