mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +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:
parent
0812965f50
commit
314b8a374b
7 changed files with 106 additions and 11 deletions
|
@ -157,8 +157,7 @@ void SoundPlayerWidgetAdvancedView::set_playlist_visible(bool visible)
|
|||
|
||||
void SoundPlayerWidgetAdvancedView::play_state_changed(Player::PlayState state)
|
||||
{
|
||||
m_back_button->set_enabled(playlist().size() > 1);
|
||||
m_next_button->set_enabled(playlist().size() > 1);
|
||||
sync_previous_next_buttons();
|
||||
|
||||
m_play_button->set_enabled(state != PlayState::NoFileLoaded);
|
||||
m_play_button->set_icon(state == PlayState::Playing ? *m_pause_icon : *m_play_icon);
|
||||
|
@ -172,6 +171,17 @@ void SoundPlayerWidgetAdvancedView::loop_mode_changed(Player::LoopMode)
|
|||
{
|
||||
}
|
||||
|
||||
void SoundPlayerWidgetAdvancedView::sync_previous_next_buttons()
|
||||
{
|
||||
m_back_button->set_enabled(playlist().size() > 1 && !playlist().shuffling());
|
||||
m_next_button->set_enabled(playlist().size() > 1);
|
||||
}
|
||||
|
||||
void SoundPlayerWidgetAdvancedView::shuffle_mode_changed(Player::ShuffleMode)
|
||||
{
|
||||
sync_previous_next_buttons();
|
||||
}
|
||||
|
||||
void SoundPlayerWidgetAdvancedView::time_elapsed(int seconds)
|
||||
{
|
||||
m_timestamp_label->set_text(String::formatted("Elapsed: {:02}:{:02}:{:02}", seconds / 3600, seconds / 60, seconds % 60));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue