core/playlists/artist: Add tracks to the artist playlists

I use a single idle task to scan the track database and add to the
appropriate playlist.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-15 10:32:58 -04:00 committed by Anna Schumaker
parent 12ae7cfee6
commit 24448aefec
2 changed files with 26 additions and 1 deletions

View File

@ -26,6 +26,19 @@ static void __artist_pl_free(struct playlist *playlist)
}
}
static bool __artist_pl_load(void *data)
{
struct playlist *playlist;
struct db_entry *dbe, *next;
db_for_each(dbe, next, track_db_get()) {
playlist = TRACK(dbe)->tr_artist->ar_playlist;
queue_add(&playlist->pl_queue, TRACK(dbe));
}
return true;
}
struct playlist_type pl_artist;
@ -47,6 +60,7 @@ void pl_artist_init(struct queue_ops *ops)
{
artist_ops = ops;
idle_schedule(IDLE_SYNC, __artist_pl_init, NULL);
idle_schedule(IDLE_SYNC, __artist_pl_load, NULL);
}
void pl_artist_deinit()

View File

@ -5,25 +5,36 @@
#include <core/idle.h>
#include <core/playlists/artist.h>
#include <core/tags/artist.h>
#include <core/tags/library.h>
#include <core/tags/tags.h>
#include <tests/test.h>
void test_artist()
{
struct artist *artist;
struct playlist *playlist;
struct library *library;
struct artist *artist;
idle_init_sync();
filter_init();
tags_init();
while (idle_run_task()) {};
/* Add tracks to the collection. */
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");
artist = artist_find("Koji Kondo");
test_equal(artist->ar_playlist, NULL);
pl_artist_init(NULL);
while (idle_run_task()) {};
playlist = (struct playlist *)artist->ar_playlist;
test_not_equal(artist->ar_playlist, NULL);
test_equal(queue_size(&playlist->pl_queue), 2);
pl_artist_deinit();
test_equal(artist->ar_playlist, NULL);