diff options
author | Max Kellermann <max@musicpd.org> | 2017-12-03 16:22:08 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-12-03 16:22:08 +0100 |
commit | fbc4bb29dcc471a08e47f10ffaa24ad8da6d40a2 (patch) | |
tree | bfbf5c75d1511145d6570697959ad52787e952bd /src/queue | |
parent | 7ba7ce3af7f013de10f458540e2cd9e7ff3c212f (diff) | |
parent | 12085038881a4aba94c74b7104c5090bc777001e (diff) |
Merge branch 'v0.20.x'
Diffstat (limited to 'src/queue')
-rw-r--r-- | src/queue/PlaylistControl.cxx | 3 | ||||
-rw-r--r-- | src/queue/PlaylistEdit.cxx | 2 | ||||
-rw-r--r-- | src/queue/Queue.cxx | 14 | ||||
-rw-r--r-- | src/queue/Queue.hxx | 9 |
4 files changed, 20 insertions, 8 deletions
diff --git a/src/queue/PlaylistControl.cxx b/src/queue/PlaylistControl.cxx index c744e42c8..e0e07b87e 100644 --- a/src/queue/PlaylistControl.cxx +++ b/src/queue/PlaylistControl.cxx @@ -75,8 +75,7 @@ playlist::MoveOrderToCurrent(unsigned old_order) } else { /* not playing anything: move the specified song to the front */ - queue.SwapOrders(old_order, 0); - return 0; + return queue.MoveOrderBefore(old_order, 0); } } diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx index a4a1a29e2..24ee1faab 100644 --- a/src/queue/PlaylistEdit.cxx +++ b/src/queue/PlaylistEdit.cxx @@ -112,7 +112,7 @@ playlist::AppendSong(PlayerControl &pc, DetachedSong &&song) else start = current + 1; if (start < queue.GetLength()) - queue.ShuffleOrderLast(start, queue.GetLength()); + queue.ShuffleOrderLastWithPriority(start, queue.GetLength()); } UpdateQueuedSong(pc, queued_song); diff --git a/src/queue/Queue.cxx b/src/queue/Queue.cxx index ea6ee9e0d..ada0346d3 100644 --- a/src/queue/Queue.cxx +++ b/src/queue/Queue.cxx @@ -359,8 +359,20 @@ Queue::ShuffleOrderFirst(unsigned start, unsigned end) noexcept } void -Queue::ShuffleOrderLast(unsigned start, unsigned end) noexcept +Queue::ShuffleOrderLastWithPriority(unsigned start, unsigned end) noexcept { + assert(end <= length); + assert(start < end); + + /* skip all items at the start which have a higher priority, + because the last item shall only be shuffled within its + priority group */ + const auto last_priority = items[OrderToPosition(end - 1)].priority; + while (items[OrderToPosition(start)].priority != last_priority) { + ++start; + assert(start < end); + } + rand.AutoCreate(); std::uniform_int_distribution<unsigned> distribution(start, end - 1); diff --git a/src/queue/Queue.hxx b/src/queue/Queue.hxx index 9a1d46f7a..557f74ed8 100644 --- a/src/queue/Queue.hxx +++ b/src/queue/Queue.hxx @@ -357,11 +357,12 @@ struct Queue { void ShuffleOrderFirst(unsigned start, unsigned end) noexcept; /** - * Shuffles the virtual order of the last song in the specified - * (order) range. This is used in random mode after a song has been - * appended by queue_append(). + * Shuffles the virtual order of the last song in the + * specified (order) range; only songs which match this song's + * priority are considered. This is used in random mode after + * a song has been appended by Append(). */ - void ShuffleOrderLast(unsigned start, unsigned end) noexcept; + void ShuffleOrderLastWithPriority(unsigned start, unsigned end) noexcept; /** * Shuffles a (position) range in the queue. The songs are physically |