core/playlists/library: Add tracks to library playlists
This needs to happen in an idle task since the track database is loaded when idle. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
261f6d91d7
commit
4d5569ef7a
|
@ -26,6 +26,22 @@ static void __lib_pl_free(struct playlist *playlist)
|
|||
}
|
||||
}
|
||||
|
||||
static bool __lib_pl_load(void *data)
|
||||
{
|
||||
struct playlist *playlist = (struct playlist *)data;
|
||||
struct library *library = library_lookup(playlist->pl_name);
|
||||
struct db_entry *dbe, *next;
|
||||
|
||||
queue_set_flag(&playlist->pl_queue, Q_ADD_FRONT);
|
||||
db_for_each(dbe, next, track_db_get()) {
|
||||
if (TRACK(dbe)->tr_library == library)
|
||||
queue_add(&playlist->pl_queue, TRACK(dbe));
|
||||
}
|
||||
queue_unset_flag(&playlist->pl_queue, Q_ADD_FRONT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
struct playlist_type pl_library;
|
||||
|
||||
|
@ -38,6 +54,8 @@ static bool __lib_pl_init(void *data)
|
|||
db_for_each(dbe, next, library_db_get()) {
|
||||
playlist = __lib_pl_alloc(LIBRARY(dbe)->li_path);
|
||||
LIBRARY(dbe)->li_playlist = playlist;
|
||||
|
||||
idle_schedule(IDLE_SYNC, __lib_pl_load, playlist);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
void test_library()
|
||||
{
|
||||
struct playlist *playlist;
|
||||
struct library *library;
|
||||
|
||||
idle_init_sync();
|
||||
|
@ -18,11 +19,16 @@ void test_library()
|
|||
while (idle_run_task()) {};
|
||||
|
||||
library = library_find("tests/Music");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/02 - Kokiri Forest.ogg");
|
||||
test_equal(library->li_playlist, NULL);
|
||||
|
||||
pl_library_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
playlist = (struct playlist *)library->li_playlist;
|
||||
|
||||
test_not_equal(library->li_playlist, NULL);
|
||||
test_equal(queue_size(&playlist->pl_queue), 2);
|
||||
|
||||
pl_library_deinit();
|
||||
test_equal(library->li_playlist, NULL);
|
||||
|
|
Loading…
Reference in New Issue