summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-12-05 23:06:22 -0500
committerWilliam Wilgus <wilgus.william@gmail.com>2021-12-05 23:10:19 -0500
commit221e8752cce3509660abe8848f731062ae2ceb81 (patch)
treebec9c6b9f23edee7a7eee99c3f860a1da25541c3
parentf02cd18ad027cdb4992a19a16cfbd336ffb63124 (diff)
downloadrockbox-221e8752cce3509660abe8848f731062ae2ceb81.tar.gz
rockbox-221e8752cce3509660abe8848f731062ae2ceb81.zip
plugin.h & lua add playlist_insert_playlist
having issues running lua and loading a playlist Change-Id: I72d32d77e6567ceed7e8e5fd492eebf0ee44561a
-rw-r--r--apps/plugin.c1
-rw-r--r--apps/plugin.h3
-rw-r--r--apps/plugins/lua/rocklib.c11
-rw-r--r--apps/plugins/lua_scripts/random_playlist.lua72
4 files changed, 70 insertions, 17 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 0225491d85..89905b1435 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -803,6 +803,7 @@ static const struct plugin_api rockbox_api = {
803 /* new stuff at the end, sort into place next time 803 /* new stuff at the end, sort into place next time
804 the API gets incompatible */ 804 the API gets incompatible */
805 warn_on_pl_erase, 805 warn_on_pl_erase,
806 playlist_insert_playlist,
806}; 807};
807 808
808static int plugin_buffer_handle; 809static int plugin_buffer_handle;
diff --git a/apps/plugin.h b/apps/plugin.h
index 6ad495b5a6..f4bb91988a 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -929,7 +929,8 @@ struct plugin_api {
929 /* new stuff at the end, sort into place next time 929 /* new stuff at the end, sort into place next time
930 the API gets incompatible */ 930 the API gets incompatible */
931 bool (*warn_on_pl_erase)(void); 931 bool (*warn_on_pl_erase)(void);
932 932 int (*playlist_insert_playlist)(struct playlist_info* playlist,
933 const char *filename, int position, bool queue);
933}; 934};
934 935
935/* plugin header */ 936/* plugin header */
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 2672d446fc..6131a479db 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -320,11 +320,12 @@ RB_WRAP(playlist)
320 enum e_playlist {PLAYL_AMOUNT = 0, PLAYL_ADD, PLAYL_CREATE, 320 enum e_playlist {PLAYL_AMOUNT = 0, PLAYL_ADD, PLAYL_CREATE,
321 PLAYL_START, PLAYL_RESUMETRACK, PLAYL_RESUME, 321 PLAYL_START, PLAYL_RESUMETRACK, PLAYL_RESUME,
322 PLAYL_SHUFFLE, PLAYL_SYNC, PLAYL_REMOVEALLTRACKS, 322 PLAYL_SHUFFLE, PLAYL_SYNC, PLAYL_REMOVEALLTRACKS,
323 PLAYL_INSERTTRACK, PLAYL_INSERTDIRECTORY, PLAYL_ECOUNT}; 323 PLAYL_INSERTTRACK, PLAYL_INSERTDIRECTORY, PLAYL_INSERTPLAYL,
324 PLAYL_ECOUNT};
324 325
325 const char *playlist_option[] = {"amount", "add", "create", "start", "resume_track", 326 const char *playlist_option[] = {"amount", "add", "create", "start", "resume_track",
326 "resume", "shuffle", "sync", "remove_all_tracks", 327 "resume", "shuffle", "sync", "remove_all_tracks",
327 "insert_track", "insert_directory", NULL}; 328 "insert_track", "insert_directory", "insert_playlist", NULL};
328 329
329 const char *filename, *dir; 330 const char *filename, *dir;
330 int result = 0; 331 int result = 0;
@@ -388,6 +389,12 @@ RB_WRAP(playlist)
388 recurse = lua_toboolean(L, 5); /* default to false */ 389 recurse = lua_toboolean(L, 5); /* default to false */
389 result = rb->playlist_insert_directory(NULL, dir, pos, queue, recurse); 390 result = rb->playlist_insert_directory(NULL, dir, pos, queue, recurse);
390 break; 391 break;
392 case PLAYL_INSERTPLAYL:
393 filename = luaL_checkstring(L, 2); /* only required parameter */
394 pos = luaL_optint(L, 3, 0);
395 queue = lua_toboolean(L, 4); /* default to false */
396 result = rb->playlist_insert_playlist(NULL, filename, pos, queue);
397 break;
391 } 398 }
392 399
393 yield(); 400 yield();
diff --git a/apps/plugins/lua_scripts/random_playlist.lua b/apps/plugins/lua_scripts/random_playlist.lua
index c87b005a49..9d300025ac 100644
--- a/apps/plugins/lua_scripts/random_playlist.lua
+++ b/apps/plugins/lua_scripts/random_playlist.lua
@@ -29,6 +29,9 @@ local playlistpath = "/Playlists"
29local max_tracks = 500; -- size of playlist to create 29local max_tracks = 500; -- size of playlist to create
30local min_repeat = 500; -- this many songs before a repeat 30local min_repeat = 500; -- this many songs before a repeat
31local play_on_success = true; 31local play_on_success = true;
32--program vars
33local playlist_handle
34local t_playlistbuf -- table for playlist write buffer
32 35
33-- Random integer function 36-- Random integer function
34local random = math.random; -- ref random(min, max) 37local random = math.random; -- ref random(min, max)
@@ -48,7 +51,6 @@ rb.contexts = nil
48local sINITDATABASE = "Initialize Database" 51local sINITDATABASE = "Initialize Database"
49local sHEADERTEXT = "Random Playlist" 52local sHEADERTEXT = "Random Playlist"
50local sPLAYLISTERROR = "Playlist Error!" 53local sPLAYLISTERROR = "Playlist Error!"
51local sREMOVEPLAYLIST = "Removing Dynamic Playlist"
52local sSEARCHINGFILES = "Searching for Files.." 54local sSEARCHINGFILES = "Searching for Files.."
53local sERROROPENFMT = "Error Opening %s" 55local sERROROPENFMT = "Error Opening %s"
54local sINVALIDDBFMT = "Invalid Database %s" 56local sINVALIDDBFMT = "Invalid Database %s"
@@ -174,13 +176,55 @@ local function _setup_random_playlist(tag_entries, play, min_repeat, trackcount)
174 return play, min_repeat, trackcount; 176 return play, min_repeat, trackcount;
175end 177end
176 178
179--deletes existing file and creates a new playlist
180local function playlist_create(filename)
181 local filehandle = io.open(filename, "w+") --overwrite
182 if not filehandle then
183 rb.splash(rb.HZ, "Error opening " .. filename)
184 return false
185 end
186 t_playlistbuf = {}
187 filehandle:write("\239\187\191") -- Write BOM --"\xEF\xBB\xBF"
188 playlist_handle = filehandle
189 return true
190 --os.remove( playlistpath .. "/" .. playlist)
191 --rb.playlist("remove_all_tracks")
192 --rb.playlist("create", playlistpath .. "/", playlist)
193end
194
195-- writes track path to a buffer must be flushed
196local function playlist_write(trackpath)
197 t_playlistbuf[#t_playlistbuf + 1] = trackpath
198 t_playlistbuf[#t_playlistbuf + 1] = "\n"
199 --[[if rb.playlist("insert_track", str) < 0 then
200 rb.splash(rb.HZ, sPLAYLISTERROR)
201 break; -- ERROR, PLAYLIST FULL?
202 end]]
203end
204
205-- flushes playlist buffer to file
206local function playlist_flush()
207 playlist_handle:write(table.concat(t_playlistbuf))
208 t_playlistbuf = {}
209 --[[if rb.playlist("insert_track", str) < 0 then
210 rb.splash(rb.HZ, sPLAYLISTERROR)
211 break; -- ERROR, PLAYLIST FULL?
212 end]]
213end
214
215-- closes playlist file descriptor
216local function playlist_finalize()
217 playlist_handle:close()
218end
219
177--[[ Given the filenameDB file [database] 220--[[ Given the filenameDB file [database]
178 creates a random dynamic playlist with a default savename of [playlist] 221 creates a random dynamic playlist with a default savename of [playlist]
179 containing [trackcount] tracks, played on completion if [play] is true]] 222 containing [trackcount] tracks, played on completion if [play] is true]]
180function create_random_playlist(database, playlist, trackcount, play) 223local function create_random_playlist(database, playlist, trackcount, play)
181 if not database or not playlist or not trackcount then return end 224 if not database or not playlist or not trackcount then return end
182 if not play then play = false end 225 if not play then play = false end
183 226
227 local playlist_handle
184 local file = io.open('/' .. database or "", "r") --read 228 local file = io.open('/' .. database or "", "r") --read
185 if not file then rb.splash(100, string.format(sERROROPENFMT, database)) return end 229 if not file then rb.splash(100, string.format(sERROROPENFMT, database)) return end
186 230
@@ -214,6 +258,7 @@ function create_random_playlist(database, playlist, trackcount, play)
214 end 258 end
215 259
216 local tag_entries = bytesLE_n(tagcache_entries) 260 local tag_entries = bytesLE_n(tagcache_entries)
261 if tag_entries > 50000 then play = false end
217 262
218 play, min_repeat, trackcount = _setup_random_playlist( 263 play, min_repeat, trackcount = _setup_random_playlist(
219 tag_entries, play, min_repeat, trackcount); 264 tag_entries, play, min_repeat, trackcount);
@@ -250,6 +295,7 @@ function create_random_playlist(database, playlist, trackcount, play)
250 if y >= max_h then 295 if y >= max_h then
251 do_progress_header() 296 do_progress_header()
252 rb.lcd_clear_display() 297 rb.lcd_clear_display()
298 playlist_flush(playlist_handle)
253 rb.yield() 299 rb.yield()
254 y = h 300 y = h
255 end 301 end
@@ -319,14 +365,11 @@ function create_random_playlist(database, playlist, trackcount, play)
319 tracks = tracks + 1 365 tracks = tracks + 1
320 show_progress() 366 show_progress()
321 push_lru(idxp) -- add to repeat list 367 push_lru(idxp) -- add to repeat list
322 if rb.playlist("insert_track", str) < 0 then 368 playlist_write(str)
323 rb.splash(rb.HZ, sPLAYLISTERROR)
324 break; -- ERROR, PLAYLIST FULL?
325 end
326
327 end 369 end
328 370
329 if tracks >= trackcount then 371 if tracks >= trackcount then
372 playlist_flush()
330 do_progress_header() 373 do_progress_header()
331 break 374 break
332 end 375 end
@@ -400,11 +443,7 @@ function create_random_playlist(database, playlist, trackcount, play)
400 anchor_index = nil 443 anchor_index = nil
401 end 444 end
402 445
403 rb.splash(10, sREMOVEPLAYLIST) 446 if not playlist_create(playlistpath .. "/" .. playlist) then return end
404 rb.audio("stop")
405 os.remove( playlistpath .. "/" .. playlist)
406 --rb.playlist("remove_all_tracks")
407 rb.playlist("create", playlistpath .. "/", playlist)
408--[[ --profiling 447--[[ --profiling
409 local starttime = rb.current_tick(); 448 local starttime = rb.current_tick();
410 get_tracks_random() 449 get_tracks_random()
@@ -414,15 +453,20 @@ function create_random_playlist(database, playlist, trackcount, play)
414 if (false) then 453 if (false) then
415--]] 454--]]
416 get_tracks_random() 455 get_tracks_random()
456 playlist_finalize(playlist_handle)
417 end 457 end
418 458
419 file:close() 459 file:close()
420 collectgarbage("collect") 460 collectgarbage("collect")
421 if trackcount and rb.playlist("amount") >= trackcount and play == true then 461 if trackcount and play == true then
462 rb.audio("stop")
463 rb.yield()
464 rb.playlist("create", playlistpath .. "/", "dynamic_playlist.m3u8")
465 rb.playlist("insert_playlist", playlistpath .. "/" .. playlist)
422 rb.playlist("start", 0, 0, 0) 466 rb.playlist("start", 0, 0, 0)
423 end 467 end
424 468
425end -- create_playlist 469end -- playlist_create
426 470
427local function main() 471local function main()
428 if not rb.file_exists(rb.ROCKBOX_DIR .. "/database_4.tcd") then 472 if not rb.file_exists(rb.ROCKBOX_DIR .. "/database_4.tcd") then