1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Frank Gevaerts 2009-07-01 16:59:43 +00:00
parent c468273e6d
commit d5180f7870
4 changed files with 76 additions and 1 deletions

View file

@ -658,6 +658,7 @@ static const struct plugin_api rockbox_api = {
appsversion,
/* new stuff at the end, sort into place next time
the API gets incompatible */
playlist_insert_directory,
};
int plugin_load(const char* plugin, const void* parameter)

View file

@ -128,7 +128,7 @@ void* plugin_get_buffer(size_t *buffer_size);
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 157
#define PLUGIN_API_VERSION 158
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
@ -821,6 +821,9 @@ struct plugin_api {
const char *appsversion;
/* new stuff at the end, sort into place next time
the API gets incompatible */
int (*playlist_insert_directory)(struct playlist_info* playlist,
const char *dirname, int position, bool queue,
bool recurse);
};
/* plugin header */

View file

@ -19,6 +19,7 @@
*
****************************************************************************/
#include "plugin.h"
#include "file.h"
PLUGIN_HEADER
@ -30,6 +31,7 @@ static int lasttick;
#define RFADIR_FILE ROCKBOX_DIR "/folder_advance_dir.txt"
#define RFA_FILE_TEXT ROCKBOX_DIR "/folder_advance_list.txt"
#define MAX_REMOVED_DIRS 10
#define MAX_SHUFFLE_SIZE (PLUGIN_BUFFER_SIZE/4 - 10000)
char *buffer = NULL;
ssize_t buffer_size;
@ -40,6 +42,7 @@ struct file_format {
char folder[][MAX_PATH];
};
struct file_format *list = NULL;
static int order[MAX_SHUFFLE_SIZE];
void update_screen(bool clear)
{
@ -460,6 +463,68 @@ int import_list_from_file_text(void)
return list->count;
}
int start_shuffled_play(void)
{
int i = 0;
/* load the dat file if not already done */
if ((list == NULL || list->count == 0) && (i = load_list()) != 0)
{
rb->splashf(HZ*2, "Could not load %s, rv = %d", RFA_FILE, i);
return 0;
}
if (list->count <= 0)
{
rb->splashf(HZ*2, "no dirs in list file: %s", RFA_FILE);
return 0;
}
/* shuffle the thing */
rb->srand(*rb->current_tick);
if(list->count>MAX_SHUFFLE_SIZE)
{
rb->splashf(HZ*2, "Too many files: %d", list->count);
return 0;
}
for(i=0;i<list->count;i++)
order[i]=i;
for(i = list->count - 1; i >= 0; i--)
{
/* the rand is from 0 to RAND_MAX, so adjust to our value range */
int candidate = rb->rand() % (i + 1);
/* now swap the values at the 'i' and 'candidate' positions */
int store = order[candidate];
order[candidate] = order[i];
order[i] = store;
}
/* We don't want whatever is playing */
if (!(rb->playlist_remove_all_tracks(NULL) == 0
&& rb->playlist_create(NULL, NULL) == 0))
{
rb->splashf(HZ*2, "Could not clear playlist");
return 0;
}
/* add the lot to the playlist */
for (i = 0; i < list->count; i++)
{
if (list->folder[order[i]][0] != ' ')
{
rb->playlist_insert_directory(NULL,list->folder[order[i]],PLAYLIST_INSERT_LAST,false,false);
}
if (rb->action_userabort(TIMEOUT_NOBLOCK))
{
break;
}
}
rb->splash(HZ, "Done");
rb->playlist_start(0,0);
return 1;
}
int main_menu(void)
{
bool exit = false;
@ -469,6 +534,7 @@ int main_menu(void)
"Edit Folder List",
"Export List To Textfile",
"Import List From Textfile",
"Play Shuffled",
"Quit");
switch (rb->do_menu(&menu, NULL, NULL, false))
@ -527,6 +593,10 @@ int main_menu(void)
rb->backlight_on();
break;
case 4:
start_shuffled_play();
exit=true;
break;
case 5:
return 1;
}
return exit?1:0;

View file

@ -21,6 +21,7 @@ it you need to have both \fname{-/CDs} and \fname{CDs} as entries.
\fname{/.rockbox/folder\_advance\_list.txt}
\item[Import List From Textfile] Imports the list from
\fname{/.rockbox/folder\_advance\_list.txt}
\item[Play Shuffled] Starts playback with the selected directories in random order. Tracks within a directory will be played in normal order. The plugin will exit after starting playback.
\item[Quit]
\end{description}