queue/PlaylistEdit: shuffle appended songs only within its priority group

Fixes #165.
This commit is contained in:
Max Kellermann 2017-12-02 17:08:20 +01:00
parent 4a3059f509
commit 478180ebe4
4 changed files with 20 additions and 6 deletions

1
NEWS
View File

@ -2,6 +2,7 @@ ver 0.20.13 (not yet released)
* database * database
- simple: don't purge mount points on update/rescan - simple: don't purge mount points on update/rescan
- upnp: work around libupnp 1.6.24 API breakage - upnp: work around libupnp 1.6.24 API breakage
* queue: fix spuriously misplaced prioritized songs
ver 0.20.12 (2017/11/25) ver 0.20.12 (2017/11/25)
* database * database

View File

@ -112,7 +112,7 @@ playlist::AppendSong(PlayerControl &pc, DetachedSong &&song)
else else
start = current + 1; start = current + 1;
if (start < queue.GetLength()) if (start < queue.GetLength())
queue.ShuffleOrderLast(start, queue.GetLength()); queue.ShuffleOrderLastWithPriority(start, queue.GetLength());
} }
UpdateQueuedSong(pc, queued_song); UpdateQueuedSong(pc, queued_song);

View File

@ -364,8 +364,20 @@ Queue::ShuffleOrderFirst(unsigned start, unsigned end)
} }
void void
Queue::ShuffleOrderLast(unsigned start, unsigned end) Queue::ShuffleOrderLastWithPriority(unsigned start, unsigned end)
{ {
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(); rand.AutoCreate();
std::uniform_int_distribution<unsigned> distribution(start, end - 1); std::uniform_int_distribution<unsigned> distribution(start, end - 1);

View File

@ -356,11 +356,12 @@ struct Queue {
void ShuffleOrderFirst(unsigned start, unsigned end); void ShuffleOrderFirst(unsigned start, unsigned end);
/** /**
* Shuffles the virtual order of the last song in the specified * Shuffles the virtual order of the last song in the
* (order) range. This is used in random mode after a song has been * specified (order) range; only songs which match this song's
* appended by queue_append(). * priority are considered. This is used in random mode after
* a song has been appended by Append().
*/ */
void ShuffleOrderLast(unsigned start, unsigned end); void ShuffleOrderLastWithPriority(unsigned start, unsigned end);
/** /**
* Shuffles a (position) range in the queue. The songs are physically * Shuffles a (position) range in the queue. The songs are physically