diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugin.c | 1 | ||||
-rw-r--r-- | apps/plugin.h | 5 | ||||
-rw-r--r-- | apps/plugins/random_folder_advance_config.c | 70 |
3 files changed, 75 insertions, 1 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index 20c7a3733c..ff80776f7e 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -658,6 +658,7 @@ static const struct plugin_api rockbox_api = { | |||
658 | appsversion, | 658 | appsversion, |
659 | /* new stuff at the end, sort into place next time | 659 | /* new stuff at the end, sort into place next time |
660 | the API gets incompatible */ | 660 | the API gets incompatible */ |
661 | playlist_insert_directory, | ||
661 | }; | 662 | }; |
662 | 663 | ||
663 | int plugin_load(const char* plugin, const void* parameter) | 664 | int plugin_load(const char* plugin, const void* parameter) |
diff --git a/apps/plugin.h b/apps/plugin.h index 160eb2b1e7..db16800309 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -128,7 +128,7 @@ void* plugin_get_buffer(size_t *buffer_size); | |||
128 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ | 128 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ |
129 | 129 | ||
130 | /* increase this every time the api struct changes */ | 130 | /* increase this every time the api struct changes */ |
131 | #define PLUGIN_API_VERSION 157 | 131 | #define PLUGIN_API_VERSION 158 |
132 | 132 | ||
133 | /* update this to latest version if a change to the api struct breaks | 133 | /* update this to latest version if a change to the api struct breaks |
134 | backwards compatibility (and please take the opportunity to sort in any | 134 | backwards compatibility (and please take the opportunity to sort in any |
@@ -821,6 +821,9 @@ struct plugin_api { | |||
821 | const char *appsversion; | 821 | const char *appsversion; |
822 | /* new stuff at the end, sort into place next time | 822 | /* new stuff at the end, sort into place next time |
823 | the API gets incompatible */ | 823 | the API gets incompatible */ |
824 | int (*playlist_insert_directory)(struct playlist_info* playlist, | ||
825 | const char *dirname, int position, bool queue, | ||
826 | bool recurse); | ||
824 | }; | 827 | }; |
825 | 828 | ||
826 | /* plugin header */ | 829 | /* plugin header */ |
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; |