1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

SoundPlayer: Implement playlist shuffle mode

The shuffling algorithm uses a naïve bloom filter to provide random
uniformity, avoiding items that were recently played.  With 32 bits,
double hashing, and an error rate of ~10%, this bloom filter should
be able to hold around ~16 keys, which should be sufficient to give the
illusion of fairness to the shuffling algorithm.

This avoids having to shuffle the playlist itself (user might have
spent quite a bit of time to sort them, so it's not a good idea to mess
with it), or having to create a proxy model that shuffles (that could
potentially use quite a bit of memory).
This commit is contained in:
Leandro Pereira 2021-09-30 07:41:00 -07:00 committed by Andreas Kling
parent 0812965f50
commit 314b8a374b
7 changed files with 106 additions and 11 deletions

View file

@ -38,6 +38,7 @@ public:
virtual void play_state_changed(PlayState) override;
virtual void loop_mode_changed(LoopMode) override;
virtual void shuffle_mode_changed(ShuffleMode) override;
virtual void time_elapsed(int) override;
virtual void file_name_changed(StringView) override;
virtual void playlist_loaded(StringView, bool) override;
@ -50,6 +51,8 @@ protected:
void keydown_event(GUI::KeyEvent&) override;
private:
void sync_previous_next_buttons();
void drop_event(GUI::DropEvent& event) override;
GUI::Window& m_window;