summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/playlist.c21
-rw-r--r--apps/playlist.h1
-rw-r--r--apps/settings_menu.c13
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 )
242 srand( seed ); 242 srand( seed );
243 243
244 /* randomise entire indices list */ 244 /* randomise entire indices list */
245 for(count = playlist->amount - 1; count ; count--) 245 for(count = playlist->amount - 1; count >= 0; count--)
246 { 246 {
247 /* the rand is from 0 to RAND_MAX, so adjust to our value range */ 247 /* the rand is from 0 to RAND_MAX, so adjust to our value range */
248 candidate = rand() % (count + 1); 248 candidate = rand() % (count + 1);
@@ -254,6 +254,25 @@ void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
254 } 254 }
255} 255}
256 256
257static int compare(const void* p1, const void* p2)
258{
259 int* e1 = (int*) p1;
260 int* e2 = (int*) p2;
261
262 return *e1 - *e2;
263}
264
265/*
266 * sort the array of indices for the playlist
267 */
268void sort_playlist( playlist_info_t *playlist )
269{
270 if (playlist->amount > 0)
271 {
272 qsort(&playlist->indices, playlist->amount, sizeof(playlist->indices[0]), compare);
273 }
274}
275
257/* ----------------------------------------------------------------- 276/* -----------------------------------------------------------------
258 * local variables: 277 * local variables:
259 * eval: (load-file "../firmware/rockbox-mode.el") 278 * 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;
41void play_list(char *dir, char *file); 41void play_list(char *dir, char *file);
42char* playlist_next(int steps, char *dirname); 42char* playlist_next(int steps, char *dirname);
43void randomise_playlist( playlist_info_t *playlist, unsigned int seed ); 43void randomise_playlist( playlist_info_t *playlist, unsigned int seed );
44void sort_playlist( playlist_info_t *playlist );
44void empty_playlist( playlist_info_t *playlist ); 45void empty_playlist( playlist_info_t *playlist );
45void add_indices_to_playlist( playlist_info_t *playlist ); 46void add_indices_to_playlist( playlist_info_t *playlist );
46 47
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)
78 { "Scroll speed", scroll_speed }, 78 { "Scroll speed", scroll_speed },
79 { "While Playing", wps_set }, 79 { "While Playing", wps_set },
80 }; 80 };
81 bool old_shuffle = global_settings.playlist_shuffle;
81 82
82 m=menu_init( items, sizeof items / sizeof(struct menu_items) ); 83 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
83 menu_run(m); 84 menu_run(m);
84 menu_exit(m); 85 menu_exit(m);
85 settings_save(); 86 settings_save();
87
88 if (old_shuffle != global_settings.playlist_shuffle)
89 {
90 if (global_settings.playlist_shuffle)
91 {
92 randomise_playlist(&playlist, current_tick);
93 }
94 else
95 {
96 sort_playlist(&playlist);
97 }
98 }
86} 99}