summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rocklib.c
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-10-24 21:40:01 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2018-10-25 05:59:42 -0400
commite4c5f5d412d94b10545980eea0b47d98e79712da (patch)
tree407022885faeda259ab40192dd74cae1a477f3f3 /apps/plugins/lua/rocklib.c
parentb670fcd50d42085a2db978bbcf2ccfd889d740ef (diff)
downloadrockbox-e4c5f5d412d94b10545980eea0b47d98e79712da.zip
rockbox-e4c5f5d412d94b10545980eea0b47d98e79712da.tar.gz
rockbox-e4c5f5d412d94b10545980eea0b47d98e79712da.tar.bz2
rockbox-e4c5f5d412d94b10545980eea0b47d98e79712da.tar.xz
lua consolidate playlist_ functions
The way to call the playlist functions has changed rb.playlist("option", var) rb.playlist_add(filename) = becomes rb.playlist("add", filename) added playlist.lua to the includes for conversion to old functions if your script is broken by this change you simply add `require("playlist")` to the top for the old functionality added rb.playlist_tracks(dir, filename) to playlist.lua this will allow you to add all tracks in a playlist.m3u8 to a lua table Change-Id: I87fcc56be365d8495d214f069331b6ddbfbef1db
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c128
1 files changed, 77 insertions, 51 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 8713365..5166291 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -267,55 +267,84 @@ RB_WRAP(do_menu)
return 1;
}
-RB_WRAP(playlist_sync)
+RB_WRAP(playlist)
{
- /* just pass NULL to work with the current playlist */
- rb->playlist_sync(NULL);
- return 1;
-}
-
-RB_WRAP(playlist_remove_all_tracks)
-{
- /* just pass NULL to work with the current playlist */
- int result = rb->playlist_remove_all_tracks(NULL);
- lua_pushinteger(L, result);
- return 1;
-}
-
-RB_WRAP(playlist_insert_track)
-{
- const char *filename;
- int position, queue, sync;
-
- /* for now don't take a playlist_info pointer, but just pass NULL to use
- the current playlist. If this changes later, all the other
- parameters can be shifted back. */
- filename = luaL_checkstring(L, 1); /* only required parameter */
- position = luaL_optint(L, 2, PLAYLIST_INSERT);
- queue = lua_toboolean(L, 3); /* default to false */
- sync = lua_toboolean(L, 4); /* default to false */
-
- int result = rb->playlist_insert_track(NULL, filename, position,
- queue, sync);
-
- lua_pushinteger(L, result);
- return 1;
-}
-
-RB_WRAP(playlist_insert_directory)
-{
- const char* dirname;
- int position, queue, recurse;
-
- /* just like in playlist_insert_track, only works with current playlist. */
- dirname = luaL_checkstring(L, 1); /* only required parameter */
- position = luaL_optint(L, 2, PLAYLIST_INSERT);
- queue = lua_toboolean(L, 3); /* default to false */
- recurse = lua_toboolean(L, 4); /* default to false */
-
- int result = rb->playlist_insert_directory(NULL, dirname, position,
- queue, recurse);
+ /* just passes NULL to work with the current playlist */
+ enum e_playlist {PLAYL_AMOUNT = 0, PLAYL_ADD, PLAYL_CREATE,
+ PLAYL_START, PLAYL_RESUMETRACK, PLAYL_RESUME,
+ PLAYL_SHUFFLE, PLAYL_SYNC, PLAYL_REMOVEALLTRACKS,
+ PLAYL_INSERTTRACK, PLAYL_INSERTDIRECTORY, PLAYL_ECOUNT};
+
+ const char *playlist_option[] = {"amount", "add", "create", "start", "resumetrack",
+ "resume", "shuffle", "sync", "removealltracks",
+ "inserttrack", "insertdirectory", NULL};
+
+ const char *filename, *dir;
+ int result = 0;
+ bool queue, recurse, sync;
+ int pos, crc, index, random_seed;
+ unsigned long elapsed, offset;
+
+ int option = luaL_checkoption (L, 1, NULL, playlist_option);
+ switch(option)
+ {
+ default:
+ case PLAYL_AMOUNT:
+ result = rb->playlist_amount();
+ break;
+ case PLAYL_ADD:
+ filename = luaL_checkstring(L, 2);
+ result = rb->playlist_add(filename);
+ break;
+ case PLAYL_CREATE:
+ dir = luaL_checkstring(L, 2);
+ filename = luaL_checkstring(L, 3);
+ result = rb->playlist_create(dir, filename);
+ break;
+ case PLAYL_START:
+ index = luaL_checkint(L, 2);
+ elapsed = luaL_checkint(L, 3);
+ offset = luaL_checkint(L, 4);
+ rb->playlist_start(index, elapsed, offset);
+ break;
+ case PLAYL_RESUMETRACK:
+ index = luaL_checkint(L, 2);
+ crc = luaL_checkint(L, 3);
+ elapsed = luaL_checkint(L, 4);
+ offset = luaL_checkint(L, 5);
+ rb->playlist_resume_track(index, (unsigned) crc, elapsed, offset);
+ break;
+ case PLAYL_RESUME:
+ result = rb->playlist_resume();
+ break;
+ case PLAYL_SHUFFLE:
+ random_seed = luaL_checkint(L, 2);
+ index = luaL_checkint(L, 3);
+ result = rb->playlist_shuffle(random_seed, index);
+ break;
+ case PLAYL_SYNC:
+ rb->playlist_sync(NULL);
+ break;
+ case PLAYL_REMOVEALLTRACKS:
+ result = rb->playlist_remove_all_tracks(NULL);
+ break;
+ case PLAYL_INSERTTRACK:
+ filename = luaL_checkstring(L, 2); /* only required parameter */
+ pos = luaL_optint(L, 3, PLAYLIST_INSERT);
+ queue = lua_toboolean(L, 4); /* default to false */
+ sync = lua_toboolean(L, 5); /* default to false */
+ result = rb->playlist_insert_track(NULL, filename, pos, queue, sync);
+ break;
+ case PLAYL_INSERTDIRECTORY:
+ dir = luaL_checkstring(L, 2); /* only required parameter */
+ pos = luaL_optint(L, 3, PLAYLIST_INSERT);
+ queue = lua_toboolean(L, 4); /* default to false */
+ recurse = lua_toboolean(L, 5); /* default to false */
+ result = rb->playlist_insert_directory(NULL, dir, pos, queue, recurse);
+ break;
+ }
+ rb->yield();
lua_pushinteger(L, result);
return 1;
}
@@ -482,10 +511,6 @@ static const luaL_Reg rocklib[] =
RB_FUNC(clear_viewport),
RB_FUNC(current_path),
RB_FUNC(gui_syncyesno_run),
- RB_FUNC(playlist_sync),
- RB_FUNC(playlist_remove_all_tracks),
- RB_FUNC(playlist_insert_track),
- RB_FUNC(playlist_insert_directory),
RB_FUNC(do_menu),
/* Backlight helper */
@@ -513,6 +538,7 @@ static const luaL_Reg rocklib[] =
RB_FUNC(create_numbered_filename),
RB_FUNC(audio),
+ RB_FUNC(playlist),
{NULL, NULL}
};