summaryrefslogtreecommitdiff
path: root/apps/plugins/lua
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-10-24 10:49:52 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2018-10-24 12:37:29 -0400
commitb670fcd50d42085a2db978bbcf2ccfd889d740ef (patch)
tree926ae29bf659c7ad93b274d6f7e4989fa3f32350 /apps/plugins/lua
parent20b98f6fd0e5916bffe9561ebd324acdfbabf61a (diff)
downloadrockbox-b670fcd50d42085a2db978bbcf2ccfd889d740ef.tar.gz
rockbox-b670fcd50d42085a2db978bbcf2ccfd889d740ef.zip
lua add audio_play consolidate audio_ functions
audio_play was removed from the rocklib I assume due to inconsistent behavior I've readded it with a check for audio paused which instead uses rewind/ff and then resumes audio the way to call the audio functions has changed as well rb.audio("option", var) so rb.audio_play(0, 0) becomes rb.audio("play", 0, 0) audio_audio_flush_and_reload_tracks becomes rb.audio("flushandreloadtracks") all functions except audio("getfilepos") return the previous (or still current) status added audio.lua to the includes for conversion to old functions if your script is broken by this change you simply add `require("audio")` to the top for the old functionality Change-Id: I364adf0c85d9c12b98cde29c26fbe5ee05b9d331
Diffstat (limited to 'apps/plugins/lua')
-rw-r--r--apps/plugins/lua/include_lua/audio.lua36
-rw-r--r--apps/plugins/lua/lua.make2
-rw-r--r--apps/plugins/lua/rocklib.c65
-rwxr-xr-xapps/plugins/lua/rocklib_aux.pl2
4 files changed, 103 insertions, 2 deletions
diff --git a/apps/plugins/lua/include_lua/audio.lua b/apps/plugins/lua/include_lua/audio.lua
new file mode 100644
index 0000000000..51e5fbe228
--- /dev/null
+++ b/apps/plugins/lua/include_lua/audio.lua
@@ -0,0 +1,36 @@
1--[[ Lua RB Audio Operations
2/***************************************************************************
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
10 *
11 * Copyright (C) 2017 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 audio_ functions ]]
25if not rb.audio then rb.splash(rb.HZ, "No Support!") return nil end
26
27rb.audio_status = function() return rb.audio("status") end
28rb.audio_play = function (elapsed, offset) rb.audio("play", elapsed, offset) end
29rb.audio_stop = function() rb.audio("stop") end
30rb.audio_pause = function() rb.audio("pause") end
31rb.audio_resume = function() rb.audio("resume") end
32rb.audio_next = function() rb.audio("next") end
33rb.audio_prev = function() rb.audio("prev") end
34rb.audio_ff_rewind = function (newtime) rb.audio("ffrewind", newtime) end
35rb.audio_flush_and_reload_tracks = function() rb.audio("flushandreloadtracks") end
36rb.audio_get_file_pos = function() return rb.audio("getfilepos") end
diff --git a/apps/plugins/lua/lua.make b/apps/plugins/lua/lua.make
index 58b3b69831..5931b655e8 100644
--- a/apps/plugins/lua/lua.make
+++ b/apps/plugins/lua/lua.make
@@ -16,7 +16,7 @@ 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)/,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)
20 20
21ifndef APP_TYPE 21ifndef APP_TYPE
22ifneq (,$(strip $(foreach tgt,RECORDER ONDIO,$(findstring $(tgt),$(TARGET))))) 22ifneq (,$(strip $(foreach tgt,RECORDER ONDIO,$(findstring $(tgt),$(TARGET)))))
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 3f85da97a7..871336505c 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -320,6 +320,69 @@ RB_WRAP(playlist_insert_directory)
320 return 1; 320 return 1;
321} 321}
322 322
323RB_WRAP(audio)
324{
325 enum e_audio {AUDIO_STATUS = 0, AUDIO_PLAY, AUDIO_STOP, AUDIO_PAUSE,
326 AUDIO_RESUME, AUDIO_NEXT, AUDIO_PREV, AUDIO_FFREWIND,
327 AUDIO_FLUSHANDRELOADTRACKS, AUDIO_GETPOS, AUDIO_ECOUNT};
328 const char *audio_option[] = {"status", "play", "stop", "pause",
329 "resume", "next", "prev", "ffrewind",
330 "flushandreloadtracks", "getfilepos", NULL};
331 long elapsed, offset, newtime;
332 int status = rb->audio_status();
333
334 int option = luaL_checkoption (L, 1, NULL, audio_option);
335 switch(option)
336 {
337 default:
338 case AUDIO_STATUS:
339 break;
340 case AUDIO_PLAY:
341 elapsed = luaL_checkint(L, 2);
342 offset = luaL_checkint(L, 3);
343
344 if (status == (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE))
345 {
346 /* not perfect but provides a decent compromise */
347 rb->audio_ff_rewind(elapsed + offset);
348 rb->audio_resume();
349 }
350 else if (status != AUDIO_STATUS_PLAY)
351 rb->audio_play((unsigned long) elapsed, (unsigned long) offset);
352
353 break;
354 case AUDIO_STOP:
355 rb->audio_stop();
356 break;
357 case AUDIO_PAUSE:
358 rb->audio_pause();
359 break;
360 case AUDIO_RESUME:
361 rb->audio_resume();
362 break;
363 case AUDIO_NEXT:
364 rb->audio_next();
365 break;
366 case AUDIO_PREV:
367 rb->audio_prev();
368 break;
369 case AUDIO_FFREWIND:
370 newtime = (long) luaL_checkint(L, 2);
371 rb->audio_ff_rewind(newtime);
372 break;
373 case AUDIO_FLUSHANDRELOADTRACKS:
374 rb->audio_flush_and_reload_tracks();
375 break;
376 case AUDIO_GETPOS:
377 lua_pushinteger(L, rb->audio_get_file_pos());
378 return 1;
379 }
380
381 rb->yield();
382 lua_pushinteger(L, status); /* return previous (or current) audio status */
383 return 1;
384}
385
323SIMPLE_VOID_WRAPPER(backlight_force_on); 386SIMPLE_VOID_WRAPPER(backlight_force_on);
324SIMPLE_VOID_WRAPPER(backlight_use_settings); 387SIMPLE_VOID_WRAPPER(backlight_use_settings);
325 388
@@ -449,6 +512,8 @@ static const luaL_Reg rocklib[] =
449 RB_FUNC(strip_extension), 512 RB_FUNC(strip_extension),
450 RB_FUNC(create_numbered_filename), 513 RB_FUNC(create_numbered_filename),
451 514
515 RB_FUNC(audio),
516
452 {NULL, NULL} 517 {NULL, NULL}
453}; 518};
454#undef RB_FUNC 519#undef RB_FUNC
diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl
index 085a191ee3..e47a898d55 100755
--- a/apps/plugins/lua/rocklib_aux.pl
+++ b/apps/plugins/lua/rocklib_aux.pl
@@ -75,7 +75,7 @@ my @forbidden_functions = ('^open$',
75 '^lcd_(mono_)?+bitmap', 75 '^lcd_(mono_)?+bitmap',
76 '^__.+$', 76 '^__.+$',
77 '^.+_(un)?cached$', 77 '^.+_(un)?cached$',
78 '^audio_play$', 78 '^audio_.+$',
79 '^round_value_to_list32$'); 79 '^round_value_to_list32$');
80 80
81my $rocklib = sprintf("%s/rocklib.c", $ARGV[0]); 81my $rocklib = sprintf("%s/rocklib.c", $ARGV[0]);