diff options
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r-- | apps/plugins/lua/rocklib.c | 128 |
1 files changed, 77 insertions, 51 deletions
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 | ||
270 | RB_WRAP(playlist_sync) | 270 | RB_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}; | |
277 | RB_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; | |
285 | RB_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: | |
305 | RB_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 | }; |