summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rocklib.c
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/rocklib.c
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/rocklib.c')
-rw-r--r--apps/plugins/lua/rocklib.c65
1 files changed, 65 insertions, 0 deletions
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