diff options
author | Daniel Stenberg <daniel@haxx.se> | 2002-08-02 13:20:03 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2002-08-02 13:20:03 +0000 |
commit | 360ae3ebdcfb5392fad4383b90248f15f563694f (patch) | |
tree | 721e0aea1503cf231fc9ac002b9aef834986eb66 | |
parent | 81e7c72792358036fc73d7cbaec3d3acefcc741b (diff) |
Magnus Holmgren's fix that now enables us to toggle shuffle on/off from the
menu and it'll "take effect" immediately when needing to reload the playlist.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1526 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/playlist.c | 21 | ||||
-rw-r--r-- | apps/playlist.h | 1 | ||||
-rw-r--r-- | apps/settings_menu.c | 13 |
3 files changed, 34 insertions, 1 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 622750f5c3..fdd88a17bc 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -242,7 +242,7 @@ void randomise_playlist( playlist_info_t *playlist, unsigned int seed ) srand( seed ); /* randomise entire indices list */ - for(count = playlist->amount - 1; count ; count--) + for(count = playlist->amount - 1; count >= 0; count--) { /* the rand is from 0 to RAND_MAX, so adjust to our value range */ candidate = rand() % (count + 1); @@ -254,6 +254,25 @@ void randomise_playlist( playlist_info_t *playlist, unsigned int seed ) } } +static int compare(const void* p1, const void* p2) +{ + int* e1 = (int*) p1; + int* e2 = (int*) p2; + + return *e1 - *e2; +} + +/* + * sort the array of indices for the playlist + */ +void sort_playlist( playlist_info_t *playlist ) +{ + if (playlist->amount > 0) + { + qsort(&playlist->indices, playlist->amount, sizeof(playlist->indices[0]), compare); + } +} + /* ----------------------------------------------------------------- * local variables: * eval: (load-file "../firmware/rockbox-mode.el") diff --git a/apps/playlist.h b/apps/playlist.h index 59e0a78bf6..3d37c5da5f 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -41,6 +41,7 @@ extern bool playlist_shuffle; void play_list(char *dir, char *file); char* playlist_next(int steps, char *dirname); void randomise_playlist( playlist_info_t *playlist, unsigned int seed ); +void sort_playlist( playlist_info_t *playlist ); void empty_playlist( playlist_info_t *playlist ); void add_indices_to_playlist( playlist_info_t *playlist ); diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 95fec0dd33..5c718869d9 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -78,9 +78,22 @@ void settings_menu(void) { "Scroll speed", scroll_speed }, { "While Playing", wps_set }, }; + bool old_shuffle = global_settings.playlist_shuffle; m=menu_init( items, sizeof items / sizeof(struct menu_items) ); menu_run(m); menu_exit(m); settings_save(); + + if (old_shuffle != global_settings.playlist_shuffle) + { + if (global_settings.playlist_shuffle) + { + randomise_playlist(&playlist, current_tick); + } + else + { + sort_playlist(&playlist); + } + } } |