Commit fe8e7af7 authored by Matthieu Gallien's avatar Matthieu Gallien 🎵 Committed by Nate Graham
Browse files

update current track if needed when adding new tracks in random playlist

the current position and the current track should match in random mode

when inserting tracks one by one in a randomly sorted playlist, we might
have ended up having the current track be at a random position even
though we also maintain a current position that would have been
discordant (and causing user visible annoyances/bugs)
parent fa5ad219
......@@ -1930,42 +1930,39 @@ void MediaPlayListProxyModelTest::testShuffleMode()
{DataTypes::DatabaseIdRole, myDatabaseContent.trackIdFromTitleAlbumTrackDiscNumber(QStringLiteral("track1"), QStringLiteral("artist1"), QStringLiteral("album2"), 1, 1)}},
QStringLiteral("track1"), {}}}, {}, {});
QCOMPARE(currentTrackChangedSpy.count(), 1);
QVERIFY(currentTrackChangedSpy.count() >= 1);
QCOMPARE(shufflePlayListChangedSpy.count(), 1);
QCOMPARE(repeatModeChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
QCOMPARE(myPlayListProxyModel.currentTrack(), QPersistentModelIndex(myPlayListProxyModel.index(0, 0)));
QCOMPARE(currentTrackChangedSpy.count(), 1);
QCOMPARE(shufflePlayListChangedSpy.count(), 1);
QCOMPARE(repeatModeChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
const auto oldCurrentTrackChangedCount = currentTrackChangedSpy.count();
myPlayListProxyModel.skipNextTrack();
QCOMPARE(currentTrackChangedSpy.count(), 2);
QCOMPARE(currentTrackChangedSpy.count(), oldCurrentTrackChangedCount + 1);
QCOMPARE(shufflePlayListChangedSpy.count(), 1);
QCOMPARE(repeatModeChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
myPlayListProxyModel.skipNextTrack();
QCOMPARE(currentTrackChangedSpy.count(), 3);
QCOMPARE(currentTrackChangedSpy.count(), oldCurrentTrackChangedCount + 2);
QCOMPARE(shufflePlayListChangedSpy.count(), 1);
QCOMPARE(repeatModeChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
myPlayListProxyModel.skipNextTrack();
QCOMPARE(currentTrackChangedSpy.count(), 4);
QCOMPARE(currentTrackChangedSpy.count(), oldCurrentTrackChangedCount + 3);
QCOMPARE(shufflePlayListChangedSpy.count(), 1);
QCOMPARE(repeatModeChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
myPlayListProxyModel.skipPreviousTrack(0);
QCOMPARE(currentTrackChangedSpy.count(), 5);
QCOMPARE(currentTrackChangedSpy.count(), oldCurrentTrackChangedCount + 4);
QCOMPARE(shufflePlayListChangedSpy.count(), 1);
QCOMPARE(repeatModeChangedSpy.count(), 1);
QCOMPARE(playListFinishedSpy.count(), 0);
......
......@@ -690,7 +690,7 @@ void MediaPlayListProxyModel::undoClearPlayList()
void MediaPlayListProxyModel::determineTracks()
{
if (!d->mCurrentTrack.isValid()) {
if (!d->mCurrentTrack.isValid() || d->mCurrentPlayListPosition != d->mCurrentTrack.row()) {
for (int row = 0; row < rowCount(); ++row) {
auto candidateTrack = index(row, 0);
const auto type = candidateTrack.data(MediaPlayList::ElementTypeRole).value<ElisaUtils::PlayListEntryType>();
......
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