diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index e8fe84e9d1..99dec9009d 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -9352,29 +9352,7 @@ static enum menu_action materialui_parse_menu_entry_action( else if ((mui->flags & MUI_FLAG_IS_PLAYLIST) || (mui->flags & MUI_FLAG_IS_EXPLORE_LIST)) { - struct menu_state *menu_st = menu_state_get_ptr(); - size_t selection_start = 0; - size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0; - size_t selection = menu_st->selection_ptr; - size_t new_selection = selection; - - /* Skip header items (Search Name + Add Additional Filter + Save as View) */ - if (mui->flags & MUI_FLAG_IS_EXPLORE_LIST) - { - menu_entry_t entry; - MENU_ENTRY_INITIALIZE(entry); - menu_entry_get(&entry, 0, 0, NULL, true); - - if (entry.type == MENU_SETTINGS_LAST + 1) - selection_start = 1; - else if (entry.type == FILE_TYPE_RDB) - selection_start = 2; - } - - new_selection = random_range(selection_start, selection_total - 1); - - while (new_selection == selection && selection_start != selection_total - 1) - new_selection = random_range(selection_start, selection_total - 1); + size_t new_selection = menu_playlist_random_selection(selection, mui->flags & MUI_FLAG_IS_EXPLORE_LIST); if (new_selection != selection) { diff --git a/menu/drivers/ozone.c b/menu/drivers/ozone.c index 22d12e3945..06e816aca3 100644 --- a/menu/drivers/ozone.c +++ b/menu/drivers/ozone.c @@ -8218,27 +8218,9 @@ static enum menu_action ozone_parse_menu_entry_action( else if ((ozone->flags & OZONE_FLAG_IS_PLAYLIST) || (ozone->flags & OZONE_FLAG_IS_EXPLORE_LIST)) { - size_t selection_start = 0; + size_t new_selection = menu_playlist_random_selection(selection, ozone->flags & OZONE_FLAG_IS_EXPLORE_LIST); - /* Skip header items (Search Name + Add Additional Filter + Save as View) */ - if (ozone->flags & OZONE_FLAG_IS_EXPLORE_LIST) - { - menu_entry_t entry; - MENU_ENTRY_INITIALIZE(entry); - menu_entry_get(&entry, 0, 0, NULL, true); - - if (entry.type == MENU_SETTINGS_LAST + 1) - selection_start = 1; - else if (entry.type == FILE_TYPE_RDB) - selection_start = 2; - } - - new_selection = random_range(selection_start, selection_total - 1); - - while (new_selection == (int)selection && selection_start != selection_total - 1) - new_selection = random_range(selection_start, selection_total - 1); - - if (new_selection != (int)selection) + if (new_selection != selection) { menu_st->selection_ptr = new_selection; ozone_selection_changed(ozone, false); @@ -8248,7 +8230,7 @@ static enum menu_action ozone_parse_menu_entry_action( new_action = MENU_ACTION_NOOP; #ifdef HAVE_AUDIOMIXER - if (new_selection != (int)selection) + if (new_selection != selection) audio_driver_mixer_play_scroll_sound(true); #endif break; diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 1319fdef3f..53c13b7b06 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -7989,6 +7989,7 @@ static enum menu_action rgui_parse_menu_entry_action( menu_entry_t *entry, enum menu_action action) { + struct menu_state *menu_st = menu_state_get_ptr(); enum menu_action new_action = action; /* Scan user inputs */ @@ -8056,7 +8057,6 @@ static enum menu_action rgui_parse_menu_entry_action( if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MAIN_MENU))) { - struct menu_state *menu_st = menu_state_get_ptr(); /* Jump to first item on Main Menu */ menu_st->selection_ptr = 0; new_action = MENU_ACTION_NOOP; @@ -8112,7 +8112,6 @@ static enum menu_action rgui_parse_menu_entry_action( case MENU_ACTION_SCAN: if (rgui->flags & RGUI_FLAG_IS_PLAYLISTS_TAB) { - struct menu_state *menu_st = menu_state_get_ptr(); size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0; size_t selection = menu_st->selection_ptr; size_t new_selection = random_range(0, selection_total - 1); @@ -8145,29 +8144,8 @@ static enum menu_action rgui_parse_menu_entry_action( else if ((rgui->flags & RGUI_FLAG_IS_PLAYLIST) || (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)) { - struct menu_state *menu_st = menu_state_get_ptr(); - size_t selection_start = 0; - size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0; - size_t selection = menu_st->selection_ptr; - size_t new_selection = selection; - - /* Skip header items (Search Name + Add Additional Filter + Save as View) */ - if (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST) - { - menu_entry_t entry; - MENU_ENTRY_INITIALIZE(entry); - menu_entry_get(&entry, 0, 0, NULL, true); - - if (entry.type == MENU_SETTINGS_LAST + 1) - selection_start = 1; - else if (entry.type == FILE_TYPE_RDB) - selection_start = 2; - } - - new_selection = random_range(selection_start, selection_total - 1); - - while (new_selection == selection && selection_start != selection_total - 1) - new_selection = random_range(selection_start, selection_total - 1); + size_t selection = menu_st->selection_ptr; + size_t new_selection = menu_playlist_random_selection(selection, rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST); if (new_selection != selection) { diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index e965c9bb46..717e489155 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -5591,28 +5591,8 @@ static enum menu_action xmb_parse_menu_entry_action( else if ((xmb->is_playlist) || (xmb->is_explore_list)) { - size_t selection_start = 0; - size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0; - size_t selection = menu_st->selection_ptr; - size_t new_selection = selection; - - /* Skip header items (Search Name + Add Additional Filter + Save as View) */ - if (xmb->is_explore_list) - { - menu_entry_t entry; - MENU_ENTRY_INITIALIZE(entry); - menu_entry_get(&entry, 0, 0, NULL, true); - - if (entry.type == MENU_SETTINGS_LAST + 1) - selection_start = 1; - else if (entry.type == FILE_TYPE_RDB) - selection_start = 2; - } - - new_selection = random_range(selection_start, selection_total - 1); - - while (new_selection == selection && selection_start != selection_total - 1) - new_selection = random_range(selection_start, selection_total - 1); + size_t selection = menu_st->selection_ptr; + size_t new_selection = menu_playlist_random_selection(selection, xmb->is_explore_list); if (new_selection != selection) { diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 4633bf36a5..b5bf94534e 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -21,6 +21,7 @@ #endif #include +#include #include #include #include @@ -8106,3 +8107,32 @@ void menu_update_runahead_mode(void) menu_st->runahead_mode = MENU_RUNAHEAD_MODE_OFF; } #endif + +/* Common method for ignoring specifics while picking random playlist items. */ +size_t menu_playlist_random_selection(size_t selection, bool is_explore_list) +{ + struct menu_state *menu_st = menu_state_get_ptr(); + size_t selection_start = 0; + size_t selection_total = menu_st->entries.list ? MENU_LIST_GET_SELECTION(menu_st->entries.list, 0)->size : 0; + size_t new_selection = selection; + + /* Skip header items (Search Name + Add Additional Filter + Save as View + Delete this View) */ + if (is_explore_list) + { + menu_entry_t entry; + MENU_ENTRY_INITIALIZE(entry); + menu_entry_get(&entry, 0, 0, NULL, true); + + if (entry.type == MENU_SETTINGS_LAST + 1 || entry.type == FILE_TYPE_PLAIN) + selection_start = 1; + else if (entry.type == FILE_TYPE_RDB) + selection_start = 2; + } + + new_selection = random_range(selection_start, selection_total - 1); + + while (new_selection == selection && selection_start != selection_total - 1) + new_selection = random_range(selection_start, selection_total - 1); + + return new_selection; +} diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 56db326ec2..20ab4a9960 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -745,6 +745,9 @@ bool menu_input_key_bind_set_mode( void menu_update_runahead_mode(void); #endif +size_t menu_playlist_random_selection( + size_t selection, bool is_explore_list); + extern const menu_ctx_driver_t *menu_ctx_drivers[]; extern menu_ctx_driver_t menu_ctx_ozone;