From 4d5569ef7ad7ac896ca670a90981e61293b7182c Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 9 May 2016 08:04:59 -0400 Subject: [PATCH] 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 --- core/playlists/library.c | 18 ++++++++++++++++++ tests/core/playlists/library.c | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/playlists/library.c b/core/playlists/library.c index 45000279..969a118d 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -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; diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index 8af679ed..026258ff 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -10,7 +10,8 @@ void test_library() { - struct library *library; + struct playlist *playlist; + struct library *library; idle_init_sync(); filter_init(); @@ -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);