Commit 9af53fb9 authored by Dmitry Kolesnikov's avatar Dmitry Kolesnikov Committed by Nate Graham
Browse files

Ensure that the current track becomes the first one when shuffling

Previously, when shuffling tracks, the current track was also moved to a
random position. This is very annoying, especially when its position is
close to the end of the playlist.

This fix puts the current track at the top of the queue and only then
shuffles the rest. This type of shuffling is used, for example, by
parent e6b0c721
Pipeline #219223 passed with stage
in 5 minutes and 13 seconds
......@@ -252,8 +252,10 @@ void MediaPlayListProxyModel::setShufflePlayList(const bool value)
QModelIndexList from;
std::swap(d->mRandomMapping[0], d->mRandomMapping[currentTrackRow()]);
from.append(index(d->, 0));
// Fisher-Yates algorithm
for (int i = 0; i < playListSize - 1; ++i) {
for (int i = 1; i < playListSize - 1; ++i) {
const int swapIndex = d->mRandomGenerator.bounded(i, playListSize);
std::swap(d->mRandomMapping[i], d->mRandomMapping[swapIndex]);
from.append(index(d->, 0));
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment