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;
|
struct playlist_type pl_library;
|
||||||
|
|
||||||
|
@ -38,6 +54,8 @@ static bool __lib_pl_init(void *data)
|
||||||
db_for_each(dbe, next, library_db_get()) {
|
db_for_each(dbe, next, library_db_get()) {
|
||||||
playlist = __lib_pl_alloc(LIBRARY(dbe)->li_path);
|
playlist = __lib_pl_alloc(LIBRARY(dbe)->li_path);
|
||||||
LIBRARY(dbe)->li_playlist = playlist;
|
LIBRARY(dbe)->li_playlist = playlist;
|
||||||
|
|
||||||
|
idle_schedule(IDLE_SYNC, __lib_pl_load, playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
void test_library()
|
void test_library()
|
||||||
{
|
{
|
||||||
struct library *library;
|
struct playlist *playlist;
|
||||||
|
struct library *library;
|
||||||
|
|
||||||
idle_init_sync();
|
idle_init_sync();
|
||||||
filter_init();
|
filter_init();
|
||||||
|
@ -18,11 +19,16 @@ void test_library()
|
||||||
while (idle_run_task()) {};
|
while (idle_run_task()) {};
|
||||||
|
|
||||||
library = library_find("tests/Music");
|
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);
|
test_equal(library->li_playlist, NULL);
|
||||||
|
|
||||||
pl_library_init(NULL);
|
pl_library_init(NULL);
|
||||||
while (idle_run_task()) {};
|
while (idle_run_task()) {};
|
||||||
|
playlist = (struct playlist *)library->li_playlist;
|
||||||
|
|
||||||
test_not_equal(library->li_playlist, NULL);
|
test_not_equal(library->li_playlist, NULL);
|
||||||
|
test_equal(queue_size(&playlist->pl_queue), 2);
|
||||||
|
|
||||||
pl_library_deinit();
|
pl_library_deinit();
|
||||||
test_equal(library->li_playlist, NULL);
|
test_equal(library->li_playlist, NULL);
|
||||||
|
|
Loading…
Reference in New Issue