diff options
Diffstat (limited to 'apps/playlist.c')
-rw-r--r-- | apps/playlist.c | 21 |
1 files changed, 20 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 | ||
257 | static 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 | */ | ||
268 | void 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") |