78 lines
1.5 KiB
C
78 lines
1.5 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/idle.h>
|
|
#include <core/playlists/artist.h>
|
|
|
|
static struct queue_ops *artist_ops = NULL;
|
|
|
|
|
|
static struct playlist *__artist_pl_alloc(gchar *name)
|
|
{
|
|
struct playlist *playlist = g_malloc(sizeof(struct playlist));
|
|
|
|
playlist->pl_name = name;
|
|
playlist->pl_type = PL_ARTIST;
|
|
queue_init(&playlist->pl_queue, Q_ENABLED | Q_REPEAT, artist_ops, playlist);
|
|
|
|
return playlist;
|
|
}
|
|
|
|
static void __artist_pl_free(struct playlist *playlist)
|
|
{
|
|
if (playlist) {
|
|
queue_deinit(&playlist->pl_queue);
|
|
g_free(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;
|
|
|
|
|
|
static bool __artist_pl_init(void *data)
|
|
{
|
|
struct db_entry *dbe, *next;
|
|
struct playlist *playlist;
|
|
|
|
db_for_each(dbe, next, artist_db_get()) {
|
|
playlist = __artist_pl_alloc(ARTIST(dbe)->ar_name);
|
|
ARTIST(dbe)->ar_playlist = playlist;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
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()
|
|
{
|
|
struct db_entry *dbe, *next;
|
|
struct playlist *playlist;
|
|
|
|
db_for_each(dbe, next, artist_db_get()) {
|
|
playlist = ARTIST(dbe)->ar_playlist;
|
|
ARTIST(dbe)->ar_playlist = NULL;
|
|
|
|
__artist_pl_free(playlist);
|
|
}
|
|
}
|