summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-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 0000000000..3952334d9b
--- /dev/null
+++ b/apps/plugins/lua/include_lua/playlist.lua
@@ -0,0 +1,80 @@
1--[[ Lua RB Playlist Operations
2/***************************************************************************
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
10 *
11 * Copyright (C) 2018 William Wilgus
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22]]
23
24-- [[ conversion to old style playlist_ functions ]]
25if not rb.playlist then rb.splash(rb.HZ, "No Support!") return nil end
26
27rb.playlist_amount = function()
28 return rb.playlist("amount")
29 end
30rb.playlist_add = function (filename)
31 return rb.playlist("add", filename)
32 end
33rb.playlist_create = function(dir, filename)
34 return rb.playlist("create", dir, filename)
35 end
36rb.playlist_start = function(index, elapsed, offset)
37 rb.playlist("start", index, elapsed, offset)
38 end
39rb.playlist_resume_track = function(index, crc, elapsed, offset)
40 rb.playlist("resumetrack", index, crc, elapsed, offset)
41 end
42rb.playlist_resume = function() return rb.playlist("resume") end
43rb.playlist_shuffle = function(random_seed, index)
44 rb.playlist("shuffle", random_seed, index)
45 end
46rb.playlist_sync = function () rb.playlist("sync") end
47rb.playlist_remove_all_tracks = function() return rb.playlist("removealltracks") end
48rb.playlist_insert_track = function(filename, pos, bqueue, bsync)
49 return rb.playlist("inserttrack", filename, pos, bqueue, bsync)
50 end
51rb.playlist_insert_directory = function(dir, pos, bqueue, brecurse)
52 return rb.playlist("insertdirectory", dir, pos, bqueue, brecurse)
53 end
54rb.playlist_tracks = function(dir, filename)
55 local tracks = {}
56 local count = 0
57 local fullpath = dir .. "/" .. filename
58 local file = io.open('/' .. fullpath, "r")
59
60 if not file then
61 rb.splash(rb.HZ, "Error opening /" .. fullpath)
62 return tracks
63 end
64
65 -- strip BOM --"\xEF\xBB\xBF"
66 local bom = file:read(3)
67 if not string.find(bom, "\239\187\191") then
68 file:seek("set", 0)
69 end
70
71 for line in file:lines() do
72 if string.len(line) > 3 and (not string.find(line, "%s*#.*")) then
73 count = count + 1
74 tracks[count] = line
75 end
76 end
77 file:close()
78 return tracks
79 end
80
diff --git a/apps/plugins/lua/lua.make b/apps/plugins/lua/lua.make
index 5931b655e8..ece71cc4d6 100644
--- a/apps/plugins/lua/lua.make
+++ b/apps/plugins/lua/lua.make
@@ -16,7 +16,8 @@ LUA_OBJ := $(call c2obj, $(LUA_SRC))
16OTHER_SRC += $(LUA_SRC) 16OTHER_SRC += $(LUA_SRC)
17 17
18LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua 18LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua
19LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua image.lua lcd.lua math_ex.lua print.lua timer.lua) 19LUA_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)
20
20 21
21ifndef APP_TYPE 22ifndef APP_TYPE
22ifneq (,$(strip $(foreach tgt,RECORDER ONDIO,$(findstring $(tgt),$(TARGET))))) 23ifneq (,$(strip $(foreach tgt,RECORDER ONDIO,$(findstring $(tgt),$(TARGET)))))
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 871336505c..5166291cf5 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -267,55 +267,84 @@ RB_WRAP(do_menu)
267 return 1; 267 return 1;
268} 268}
269 269
270RB_WRAP(playlist_sync) 270RB_WRAP(playlist)
271{ 271{
272 /* just pass NULL to work with the current playlist */ 272 /* just passes NULL to work with the current playlist */
273 rb->playlist_sync(NULL); 273 enum e_playlist {PLAYL_AMOUNT = 0, PLAYL_ADD, PLAYL_CREATE,
274 return 1; 274 PLAYL_START, PLAYL_RESUMETRACK, PLAYL_RESUME,
275} 275 PLAYL_SHUFFLE, PLAYL_SYNC, PLAYL_REMOVEALLTRACKS,
276 276 PLAYL_INSERTTRACK, PLAYL_INSERTDIRECTORY, PLAYL_ECOUNT};
277RB_WRAP(playlist_remove_all_tracks) 277
278{ 278 const char *playlist_option[] = {"amount", "add", "create", "start", "resumetrack",
279 /* just pass NULL to work with the current playlist */ 279 "resume", "shuffle", "sync", "removealltracks",
280 int result = rb->playlist_remove_all_tracks(NULL); 280 "inserttrack", "insertdirectory", NULL};
281 lua_pushinteger(L, result); 281
282 return 1; 282 const char *filename, *dir;
283} 283 int result = 0;
284 284 bool queue, recurse, sync;
285RB_WRAP(playlist_insert_track) 285 int pos, crc, index, random_seed;
286{ 286 unsigned long elapsed, offset;
287 const char *filename; 287
288 int position, queue, sync; 288 int option = luaL_checkoption (L, 1, NULL, playlist_option);
289 289 switch(option)
290 /* for now don't take a playlist_info pointer, but just pass NULL to use 290 {
291 the current playlist. If this changes later, all the other 291 default:
292 parameters can be shifted back. */ 292 case PLAYL_AMOUNT:
293 filename = luaL_checkstring(L, 1); /* only required parameter */ 293 result = rb->playlist_amount();
294 position = luaL_optint(L, 2, PLAYLIST_INSERT); 294 break;
295 queue = lua_toboolean(L, 3); /* default to false */ 295 case PLAYL_ADD:
296 sync = lua_toboolean(L, 4); /* default to false */ 296 filename = luaL_checkstring(L, 2);
297 297 result = rb->playlist_add(filename);
298 int result = rb->playlist_insert_track(NULL, filename, position, 298 break;
299 queue, sync); 299 case PLAYL_CREATE:
300 300 dir = luaL_checkstring(L, 2);
301 lua_pushinteger(L, result); 301 filename = luaL_checkstring(L, 3);
302 return 1; 302 result = rb->playlist_create(dir, filename);
303} 303 break;
304 304 case PLAYL_START:
305RB_WRAP(playlist_insert_directory) 305 index = luaL_checkint(L, 2);
306{ 306 elapsed = luaL_checkint(L, 3);
307 const char* dirname; 307 offset = luaL_checkint(L, 4);
308 int position, queue, recurse; 308 rb->playlist_start(index, elapsed, offset);
309 309 break;
310 /* just like in playlist_insert_track, only works with current playlist. */ 310 case PLAYL_RESUMETRACK:
311 dirname = luaL_checkstring(L, 1); /* only required parameter */ 311 index = luaL_checkint(L, 2);
312 position = luaL_optint(L, 2, PLAYLIST_INSERT); 312 crc = luaL_checkint(L, 3);
313 queue = lua_toboolean(L, 3); /* default to false */ 313 elapsed = luaL_checkint(L, 4);
314 recurse = lua_toboolean(L, 4); /* default to false */ 314 offset = luaL_checkint(L, 5);
315 315 rb->playlist_resume_track(index, (unsigned) crc, elapsed, offset);
316 int result = rb->playlist_insert_directory(NULL, dirname, position, 316 break;
317 queue, recurse); 317 case PLAYL_RESUME:
318 result = rb->playlist_resume();
319 break;
320 case PLAYL_SHUFFLE:
321 random_seed = luaL_checkint(L, 2);
322 index = luaL_checkint(L, 3);
323 result = rb->playlist_shuffle(random_seed, index);
324 break;
325 case PLAYL_SYNC:
326 rb->playlist_sync(NULL);
327 break;
328 case PLAYL_REMOVEALLTRACKS:
329 result = rb->playlist_remove_all_tracks(NULL);
330 break;
331 case PLAYL_INSERTTRACK:
332 filename = luaL_checkstring(L, 2); /* only required parameter */
333 pos = luaL_optint(L, 3, PLAYLIST_INSERT);
334 queue = lua_toboolean(L, 4); /* default to false */
335 sync = lua_toboolean(L, 5); /* default to false */
336 result = rb->playlist_insert_track(NULL, filename, pos, queue, sync);
337 break;
338 case PLAYL_INSERTDIRECTORY:
339 dir = luaL_checkstring(L, 2); /* only required parameter */
340 pos = luaL_optint(L, 3, PLAYLIST_INSERT);
341 queue = lua_toboolean(L, 4); /* default to false */
342 recurse = lua_toboolean(L, 5); /* default to false */
343 result = rb->playlist_insert_directory(NULL, dir, pos, queue, recurse);
344 break;
345 }
318 346
347 rb->yield();
319 lua_pushinteger(L, result); 348 lua_pushinteger(L, result);
320 return 1; 349 return 1;
321} 350}
@@ -482,10 +511,6 @@ static const luaL_Reg rocklib[] =
482 RB_FUNC(clear_viewport), 511 RB_FUNC(clear_viewport),
483 RB_FUNC(current_path), 512 RB_FUNC(current_path),
484 RB_FUNC(gui_syncyesno_run), 513 RB_FUNC(gui_syncyesno_run),
485 RB_FUNC(playlist_sync),
486 RB_FUNC(playlist_remove_all_tracks),
487 RB_FUNC(playlist_insert_track),
488 RB_FUNC(playlist_insert_directory),
489 RB_FUNC(do_menu), 514 RB_FUNC(do_menu),
490 515
491 /* Backlight helper */ 516 /* Backlight helper */
@@ -513,6 +538,7 @@ static const luaL_Reg rocklib[] =
513 RB_FUNC(create_numbered_filename), 538 RB_FUNC(create_numbered_filename),
514 539
515 RB_FUNC(audio), 540 RB_FUNC(audio),
541 RB_FUNC(playlist),
516 542
517 {NULL, NULL} 543 {NULL, NULL}
518}; 544};
diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl
index e47a898d55..5114e7b6f7 100755
--- a/apps/plugins/lua/rocklib_aux.pl
+++ b/apps/plugins/lua/rocklib_aux.pl
@@ -76,6 +76,7 @@ my @forbidden_functions = ('^open$',
76 '^__.+$', 76 '^__.+$',
77 '^.+_(un)?cached$', 77 '^.+_(un)?cached$',
78 '^audio_.+$', 78 '^audio_.+$',
79 'playlist_.+$',
79 '^round_value_to_list32$'); 80 '^round_value_to_list32$');
80 81
81my $rocklib = sprintf("%s/rocklib.c", $ARGV[0]); 82my $rocklib = sprintf("%s/rocklib.c", $ARGV[0]);