Skip to content

Commit 87372bf

Browse files
ITotalJusticeHookedBehemoth
authored andcommitted
added support for re-shuffling the playlist when shuffle mode is toggled on.
this allows for a new list to be created, similar to how it works in youtube music.
1 parent dc35be9 commit 87372bf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sys-tune/source/impl/music_player.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ namespace tune::impl {
9696
return true;
9797
}
9898

99+
void Shuffle() {
100+
const auto size = m_shuffle_playlist.size();
101+
if (!size) {
102+
return;
103+
}
104+
105+
for (auto& e : m_shuffle_playlist) {
106+
const auto index = randomGet64() % size;
107+
std::swap(e, m_shuffle_playlist[index]);
108+
}
109+
}
110+
99111
const char* GetPath(u32 index, ShuffleMode shuffle) const {
100112
return GetPath(Get(index, shuffle));
101113
}
@@ -564,6 +576,11 @@ namespace tune::impl {
564576
void SetShuffleMode(ShuffleMode mode) {
565577
std::scoped_lock lk(g_mutex);
566578

579+
// if we just enabled shuffle mode, re-shuffle the playlist.
580+
if (g_shuffle == ShuffleMode::Off && mode == ShuffleMode::On) {
581+
g_playlist.Shuffle();
582+
}
583+
567584
g_shuffle = mode;
568585
}
569586

0 commit comments

Comments
 (0)