summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-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 0000000..51e5fbe
--- /dev/null
+++ b/apps/plugins/lua/include_lua/audio.lua
@@ -0,0 +1,36 @@
+--[[ Lua RB Audio Operations
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2017 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 audio_ functions ]]
+if not rb.audio then rb.splash(rb.HZ, "No Support!") return nil end
+
+rb.audio_status = function() return rb.audio("status") end
+rb.audio_play = function (elapsed, offset) rb.audio("play", elapsed, offset) end
+rb.audio_stop = function() rb.audio("stop") end
+rb.audio_pause = function() rb.audio("pause") end
+rb.audio_resume = function() rb.audio("resume") end
+rb.audio_next = function() rb.audio("next") end
+rb.audio_prev = function() rb.audio("prev") end
+rb.audio_ff_rewind = function (newtime) rb.audio("ffrewind", newtime) end
+rb.audio_flush_and_reload_tracks = function() rb.audio("flushandreloadtracks") end
+rb.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 58b3b69..5931b65 100644
--- a/apps/plugins/lua/lua.make
+++ b/apps/plugins/lua/lua.make
@@ -16,7 +16,7 @@ LUA_OBJ := $(call c2obj, $(LUA_SRC))
OTHER_SRC += $(LUA_SRC)
LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua
-LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,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)
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 3f85da9..8713365 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -320,6 +320,69 @@ RB_WRAP(playlist_insert_directory)
return 1;
}
+RB_WRAP(audio)
+{
+ enum e_audio {AUDIO_STATUS = 0, AUDIO_PLAY, AUDIO_STOP, AUDIO_PAUSE,
+ AUDIO_RESUME, AUDIO_NEXT, AUDIO_PREV, AUDIO_FFREWIND,
+ AUDIO_FLUSHANDRELOADTRACKS, AUDIO_GETPOS, AUDIO_ECOUNT};
+ const char *audio_option[] = {"status", "play", "stop", "pause",
+ "resume", "next", "prev", "ffrewind",
+ "flushandreloadtracks", "getfilepos", NULL};
+ long elapsed, offset, newtime;
+ int status = rb->audio_status();
+
+ int option = luaL_checkoption (L, 1, NULL, audio_option);
+ switch(option)
+ {
+ default:
+ case AUDIO_STATUS:
+ break;
+ case AUDIO_PLAY:
+ elapsed = luaL_checkint(L, 2);
+ offset = luaL_checkint(L, 3);
+
+ if (status == (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE))
+ {
+ /* not perfect but provides a decent compromise */
+ rb->audio_ff_rewind(elapsed + offset);
+ rb->audio_resume();
+ }
+ else if (status != AUDIO_STATUS_PLAY)
+ rb->audio_play((unsigned long) elapsed, (unsigned long) offset);
+
+ break;
+ case AUDIO_STOP:
+ rb->audio_stop();
+ break;
+ case AUDIO_PAUSE:
+ rb->audio_pause();
+ break;
+ case AUDIO_RESUME:
+ rb->audio_resume();
+ break;
+ case AUDIO_NEXT:
+ rb->audio_next();
+ break;
+ case AUDIO_PREV:
+ rb->audio_prev();
+ break;
+ case AUDIO_FFREWIND:
+ newtime = (long) luaL_checkint(L, 2);
+ rb->audio_ff_rewind(newtime);
+ break;
+ case AUDIO_FLUSHANDRELOADTRACKS:
+ rb->audio_flush_and_reload_tracks();
+ break;
+ case AUDIO_GETPOS:
+ lua_pushinteger(L, rb->audio_get_file_pos());
+ return 1;
+ }
+
+ rb->yield();
+ lua_pushinteger(L, status); /* return previous (or current) audio status */
+ return 1;
+}
+
SIMPLE_VOID_WRAPPER(backlight_force_on);
SIMPLE_VOID_WRAPPER(backlight_use_settings);
@@ -449,6 +512,8 @@ static const luaL_Reg rocklib[] =
RB_FUNC(strip_extension),
RB_FUNC(create_numbered_filename),
+ RB_FUNC(audio),
+
{NULL, NULL}
};
#undef RB_FUNC
diff --git a/apps/plugins/lua/rocklib_aux.pl b/apps/plugins/lua/rocklib_aux.pl
index 085a191..e47a898 100755
--- a/apps/plugins/lua/rocklib_aux.pl
+++ b/apps/plugins/lua/rocklib_aux.pl
@@ -75,7 +75,7 @@ my @forbidden_functions = ('^open$',
'^lcd_(mono_)?+bitmap',
'^__.+$',
'^.+_(un)?cached$',
- '^audio_play$',
+ '^audio_.+$',
'^round_value_to_list32$');
my $rocklib = sprintf("%s/rocklib.c", $ARGV[0]);