summaryrefslogtreecommitdiff
path: root/apps/plugins/lua
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua')
-rw-r--r--apps/plugins/lua/include_lua/playlist.lua80
-rw-r--r--apps/plugins/lua/lua.make3
-rw-r--r--apps/plugins/lua/rocklib.c128
-rwxr-xr-xapps/plugins/lua/rocklib_aux.pl1
4 files changed, 160 insertions, 52 deletions
diff --git a/apps/plugins/lua/include_lua/playlist.lua b/apps/plugins/lua/include_lua/playlist.lua
new file mode 100644
index 0000000..3952334
--- /dev/null
+++ b/apps/plugins/lua/include_lua/playlist.lua
@@ -0,0 +1,80 @@
+--[[ Lua RB Playlist Operations
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2018 William Wilgus
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+]]
+
+-- [[ conversion to old style playlist_ functions ]]
+if not rb.playlist then rb.splash(rb.HZ, "No Support!") return nil end
+
+rb.playlist_amount = function()
+ return rb.playlist("amount")
+ end
+rb.playlist_add = function (filename)
+ return rb.playlist("add", filename)
+ end
+rb.playlist_create = function(dir, filename)
+ return rb.playlist("create", dir, filename)
+ end
+rb.playlist_start = function(index, elapsed, offset)
+ rb.playlist("start", index, elapsed, offset)
+ end
+rb.playlist_resume_track = function(index, crc, elapsed, offset)
+ rb.playlist("resumetrack", index, crc, elapsed, offset)
+ end
+rb.playlist_resume = function() return rb.playlist("resume") end
+rb.playlist_shuffle = function(random_seed, index)
+ rb.playlist("shuffle", random_seed, index)
+ end
+rb.playlist_sync = function () rb.playlist("sync") end
+rb.playlist_remove_all_tracks = function() return rb.playlist("removealltracks") end
+rb.playlist_insert_track = function(filename, pos, bqueue, bsync)
+ return rb.playlist("inserttrack", filename, pos, bqueue, bsync)
+ end
+rb.playlist_insert_directory = function(dir, pos, bqueue, brecurse)
+ return rb.playlist("insertdirectory", dir, pos, bqueue, brecurse)
+ end
+rb.playlist_tracks = function(dir, filename)
+ local tracks = {}
+ local count = 0
+ local fullpath = dir .. "/" .. filename
+ local file = io.open('/' .. fullpath, "r")
+
+ if not file then
+ rb.splash(rb.HZ, "Error opening /" .. fullpath)
+ return tracks
+ end
+
+ -- strip BOM --"\xEF\xBB\xBF"
+ local bom = file:read(3)
+ if not string.find(bom, "\239\187\191") then
+ file:seek("set", 0)
+ end
+
+ for line in file:lines() do
+ if string.len(line) > 3 and (not string.find(line, "%s*#.*")) then
+ count = count + 1
+ tracks[count] = line
+ end
+ end
+ file:close()
+ return tracks
+ end
+
diff --git a/apps/plugins/lua/lua.make b/apps/plugins/lua/lua.make
index 5931b65..ece71cc 100644
--- a/apps/plugins/lua/lua.make
+++ b/apps/plugins/lua/lua.make
@@ -16,7 +16,8 @@ LUA_OBJ := $(call c2obj, $(LUA_SRC))
OTHER_SRC += $(LUA_SRC)
LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua
-LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua image.lua lcd.lua math_ex.lua print.lua timer.lua)
+LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua image.lua lcd.lua math_ex.lua print.lua timer.lua playlist.lua)
+
ifndef APP_TYPE
ifneq (,$(strip $(foreach tgt,RECORDER ONDIO,$(findstring $(tgt),$(TARGET)))))
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}
};
diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl
index e47a898..5114e7b 100755
--- a/apps/plugins/lua/rocklib_aux.pl
+++ b/apps/plugins/lua/rocklib_aux.pl
@@ -76,6 +76,7 @@ my @forbidden_functions = ('^open$',
'^__.+$',
'^.+_(un)?cached$',
'^audio_.+$',
+ 'playlist_.+$',
'^round_value_to_list32$');
my $rocklib = sprintf("%s/rocklib.c", $ARGV[0]);