diff options
author | Frank Gevaerts <frank@gevaerts.be> | 2009-07-01 16:59:43 +0000 |
---|---|---|
committer | Frank Gevaerts <frank@gevaerts.be> | 2009-07-01 16:59:43 +0000 |
commit | d5180f7870643e19c37b62909d0e0c545cc23337 (patch) | |
tree | be828862cde4fa4603d40f9bc1c1aa2038c4973c /apps/plugins/random_folder_advance_config.c | |
parent | c468273e6d59ddf17c72d94a5d3c97df33c0f0ca (diff) | |
download | rockbox-d5180f7870643e19c37b62909d0e0c545cc23337.tar.gz rockbox-d5180f7870643e19c37b62909d0e0c545cc23337.zip |
Add "Play Shuffled" menu item to random_folder_advance_config, which adds all configured configured directories to the current playlist in random order.
(FS#10403)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21594 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/random_folder_advance_config.c')
-rw-r--r-- | apps/plugins/random_folder_advance_config.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c index d0a6a26800..0f540baf8a 100644 --- a/apps/plugins/random_folder_advance_config.c +++ b/apps/plugins/random_folder_advance_config.c | |||
@@ -19,6 +19,7 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "plugin.h" | 21 | #include "plugin.h" |
22 | #include "file.h" | ||
22 | 23 | ||
23 | PLUGIN_HEADER | 24 | PLUGIN_HEADER |
24 | 25 | ||
@@ -30,6 +31,7 @@ static int lasttick; | |||
30 | #define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt" | 31 | #define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt" |
31 | #define RFA_FILE_TEXT ROCKBOX_DIR "/folder_advance_list.txt" | 32 | #define RFA_FILE_TEXT ROCKBOX_DIR "/folder_advance_list.txt" |
32 | #define MAX_REMOVED_DIRS 10 | 33 | #define MAX_REMOVED_DIRS 10 |
34 | #define MAX_SHUFFLE_SIZE (PLUGIN_BUFFER_SIZE/4 - 10000) | ||
33 | 35 | ||
34 | char *buffer = NULL; | 36 | char *buffer = NULL; |
35 | ssize_t buffer_size; | 37 | ssize_t buffer_size; |
@@ -40,6 +42,7 @@ struct file_format { | |||
40 | char folder[][MAX_PATH]; | 42 | char folder[][MAX_PATH]; |
41 | }; | 43 | }; |
42 | struct file_format *list = NULL; | 44 | struct file_format *list = NULL; |
45 | static int order[MAX_SHUFFLE_SIZE]; | ||
43 | 46 | ||
44 | void update_screen(bool clear) | 47 | void update_screen(bool clear) |
45 | { | 48 | { |
@@ -460,6 +463,68 @@ int import_list_from_file_text(void) | |||
460 | return list->count; | 463 | return list->count; |
461 | } | 464 | } |
462 | 465 | ||
466 | int start_shuffled_play(void) | ||
467 | { | ||
468 | int i = 0; | ||
469 | /* load the dat file if not already done */ | ||
470 | if ((list == NULL || list->count == 0) && (i = load_list()) != 0) | ||
471 | { | ||
472 | rb->splashf(HZ*2, "Could not load %s, rv = %d", RFA_FILE, i); | ||
473 | return 0; | ||
474 | } | ||
475 | |||
476 | if (list->count <= 0) | ||
477 | { | ||
478 | rb->splashf(HZ*2, "no dirs in list file: %s", RFA_FILE); | ||
479 | return 0; | ||
480 | } | ||
481 | |||
482 | /* shuffle the thing */ | ||
483 | rb->srand(*rb->current_tick); | ||
484 | if(list->count>MAX_SHUFFLE_SIZE) | ||
485 | { | ||
486 | rb->splashf(HZ*2, "Too many files: %d", list->count); | ||
487 | return 0; | ||
488 | } | ||
489 | for(i=0;i<list->count;i++) | ||
490 | order[i]=i; | ||
491 | |||
492 | for(i = list->count - 1; i >= 0; i--) | ||
493 | { | ||
494 | /* the rand is from 0 to RAND_MAX, so adjust to our value range */ | ||
495 | int candidate = rb->rand() % (i + 1); | ||
496 | |||
497 | /* now swap the values at the 'i' and 'candidate' positions */ | ||
498 | int store = order[candidate]; | ||
499 | order[candidate] = order[i]; | ||
500 | order[i] = store; | ||
501 | } | ||
502 | |||
503 | /* We don't want whatever is playing */ | ||
504 | if (!(rb->playlist_remove_all_tracks(NULL) == 0 | ||
505 | && rb->playlist_create(NULL, NULL) == 0)) | ||
506 | { | ||
507 | rb->splashf(HZ*2, "Could not clear playlist"); | ||
508 | return 0; | ||
509 | } | ||
510 | |||
511 | /* add the lot to the playlist */ | ||
512 | for (i = 0; i < list->count; i++) | ||
513 | { | ||
514 | if (list->folder[order[i]][0] != ' ') | ||
515 | { | ||
516 | rb->playlist_insert_directory(NULL,list->folder[order[i]],PLAYLIST_INSERT_LAST,false,false); | ||
517 | } | ||
518 | if (rb->action_userabort(TIMEOUT_NOBLOCK)) | ||
519 | { | ||
520 | break; | ||
521 | } | ||
522 | } | ||
523 | rb->splash(HZ, "Done"); | ||
524 | rb->playlist_start(0,0); | ||
525 | return 1; | ||
526 | } | ||
527 | |||
463 | int main_menu(void) | 528 | int main_menu(void) |
464 | { | 529 | { |
465 | bool exit = false; | 530 | bool exit = false; |
@@ -469,6 +534,7 @@ int main_menu(void) | |||
469 | "Edit Folder List", | 534 | "Edit Folder List", |
470 | "Export List To Textfile", | 535 | "Export List To Textfile", |
471 | "Import List From Textfile", | 536 | "Import List From Textfile", |
537 | "Play Shuffled", | ||
472 | "Quit"); | 538 | "Quit"); |
473 | 539 | ||
474 | switch (rb->do_menu(&menu, NULL, NULL, false)) | 540 | switch (rb->do_menu(&menu, NULL, NULL, false)) |
@@ -527,6 +593,10 @@ int main_menu(void) | |||
527 | rb->backlight_on(); | 593 | rb->backlight_on(); |
528 | break; | 594 | break; |
529 | case 4: | 595 | case 4: |
596 | start_shuffled_play(); | ||
597 | exit=true; | ||
598 | break; | ||
599 | case 5: | ||
530 | return 1; | 600 | return 1; |
531 | } | 601 | } |
532 | return exit?1:0; | 602 | return exit?1:0; |