core/playlists/generic: Add a playlist_generic_init() function
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
1a29458d7c
commit
dddb098354
|
@ -13,7 +13,7 @@ static struct playlist *__artist_pl_alloc(gchar *name)
|
||||||
|
|
||||||
playlist->pl_name = name;
|
playlist->pl_name = name;
|
||||||
playlist->pl_type = PL_ARTIST;
|
playlist->pl_type = PL_ARTIST;
|
||||||
queue_init(&playlist->pl_queue, Q_ENABLED | Q_REPEAT, artist_ops, playlist);
|
playlist_generic_init(playlist, Q_REPEAT, artist_ops);
|
||||||
|
|
||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,15 @@ void playlist_noop_sort(struct playlist *playlist,
|
||||||
/*
|
/*
|
||||||
* Generic playlist operations.
|
* Generic playlist operations.
|
||||||
*/
|
*/
|
||||||
|
void playlist_generic_init(struct playlist *playlist, unsigned int flags,
|
||||||
|
struct queue_ops *ops)
|
||||||
|
{
|
||||||
|
queue_init(&playlist->pl_queue, flags | Q_ENABLED, ops, playlist);
|
||||||
|
queue_sort(&playlist->pl_queue, COMPARE_ARTIST, true);
|
||||||
|
queue_sort(&playlist->pl_queue, COMPARE_YEAR, false);
|
||||||
|
queue_sort(&playlist->pl_queue, COMPARE_TRACK, false);
|
||||||
|
}
|
||||||
|
|
||||||
bool playlist_generic_add_track(struct playlist *playlist, struct track *track)
|
bool playlist_generic_add_track(struct playlist *playlist, struct track *track)
|
||||||
{
|
{
|
||||||
if (queue_has(&playlist->pl_queue, track))
|
if (queue_has(&playlist->pl_queue, track))
|
||||||
|
|
|
@ -22,10 +22,7 @@ static struct playlist *__lib_pl_alloc(const gchar *path)
|
||||||
|
|
||||||
playlist->pl_name = path;
|
playlist->pl_name = path;
|
||||||
playlist->pl_type = PL_LIBRARY;
|
playlist->pl_type = PL_LIBRARY;
|
||||||
queue_init(&playlist->pl_queue, Q_ENABLED | Q_REPEAT, lib_ops, playlist);
|
playlist_generic_init(playlist, Q_REPEAT, lib_ops);
|
||||||
queue_sort(&playlist->pl_queue, COMPARE_ARTIST, true);
|
|
||||||
queue_sort(&playlist->pl_queue, COMPARE_YEAR, false);
|
|
||||||
queue_sort(&playlist->pl_queue, COMPARE_TRACK, false);
|
|
||||||
|
|
||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,12 @@ static struct file sys_collection = FILE_INIT("library.q", 0, 0);
|
||||||
/*
|
/*
|
||||||
* Generic system playlist operations.
|
* Generic system playlist operations.
|
||||||
*/
|
*/
|
||||||
|
static void sys_pl_generic_init(struct playlist *playlist, unsigned int flags,
|
||||||
|
struct queue_ops *ops)
|
||||||
|
{
|
||||||
|
playlist_generic_init(playlist, Q_REPEAT | Q_ADD_FRONT, ops);
|
||||||
|
}
|
||||||
|
|
||||||
static bool sys_pl_generic_add(struct playlist *playlist, struct track *track)
|
static bool sys_pl_generic_add(struct playlist *playlist, struct track *track)
|
||||||
{
|
{
|
||||||
if (queue_has(__sys_pl_queue(SYS_PL_HIDDEN), track))
|
if (queue_has(__sys_pl_queue(SYS_PL_HIDDEN), track))
|
||||||
|
@ -98,6 +104,14 @@ static void sys_pl_collection_sort(struct playlist *playlist,
|
||||||
/*
|
/*
|
||||||
* History playlist operations.
|
* History playlist operations.
|
||||||
*/
|
*/
|
||||||
|
static void sys_pl_history_init(struct playlist *playlist,
|
||||||
|
unsigned int flags, struct queue_ops *ops)
|
||||||
|
{
|
||||||
|
queue_init(&playlist->pl_queue,
|
||||||
|
Q_ENABLED | Q_REPEAT | Q_ADD_FRONT | Q_NO_SORT,
|
||||||
|
ops, playlist);
|
||||||
|
}
|
||||||
|
|
||||||
static bool sys_pl_history_add(struct playlist *playlist, struct track *track)
|
static bool sys_pl_history_add(struct playlist *playlist, struct track *track)
|
||||||
{
|
{
|
||||||
queue_add(&playlist->pl_queue, track);
|
queue_add(&playlist->pl_queue, track);
|
||||||
|
@ -144,6 +158,7 @@ static bool sys_pl_least_played_add(struct playlist *playlist, struct track *tra
|
||||||
static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
[SYS_PL_FAVORITES] = {
|
[SYS_PL_FAVORITES] = {
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"),
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"),
|
||||||
|
.spl_init = playlist_generic_init,
|
||||||
.spl_add = sys_pl_favorites_add,
|
.spl_add = sys_pl_favorites_add,
|
||||||
.spl_remove = sys_pl_favorites_remove,
|
.spl_remove = sys_pl_favorites_remove,
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
@ -151,6 +166,7 @@ static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
},
|
},
|
||||||
[SYS_PL_HIDDEN] = {
|
[SYS_PL_HIDDEN] = {
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"),
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"),
|
||||||
|
.spl_init = playlist_generic_init,
|
||||||
.spl_add = sys_pl_hidden_add,
|
.spl_add = sys_pl_hidden_add,
|
||||||
.spl_remove = sys_pl_hidden_remove,
|
.spl_remove = sys_pl_hidden_remove,
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
@ -158,6 +174,7 @@ static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
},
|
},
|
||||||
[SYS_PL_COLLECTION] = {
|
[SYS_PL_COLLECTION] = {
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"),
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"),
|
||||||
|
.spl_init = sys_pl_generic_init,
|
||||||
.spl_add = sys_pl_collection_add,
|
.spl_add = sys_pl_collection_add,
|
||||||
.spl_remove = playlist_generic_remove_track,
|
.spl_remove = playlist_generic_remove_track,
|
||||||
.spl_set_flag = sys_pl_collection_set_flag,
|
.spl_set_flag = sys_pl_collection_set_flag,
|
||||||
|
@ -165,6 +182,7 @@ static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
},
|
},
|
||||||
[SYS_PL_HISTORY] = {
|
[SYS_PL_HISTORY] = {
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History"),
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History"),
|
||||||
|
.spl_init = sys_pl_history_init,
|
||||||
.spl_add = sys_pl_history_add,
|
.spl_add = sys_pl_history_add,
|
||||||
.spl_remove = playlist_generic_remove_track,
|
.spl_remove = playlist_generic_remove_track,
|
||||||
.spl_set_flag = playlist_noop_set_flag,
|
.spl_set_flag = playlist_noop_set_flag,
|
||||||
|
@ -172,6 +190,7 @@ static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
},
|
},
|
||||||
[SYS_PL_UNPLAYED] = {
|
[SYS_PL_UNPLAYED] = {
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"),
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"),
|
||||||
|
.spl_init = sys_pl_generic_init,
|
||||||
.spl_add = sys_pl_unplayed_add,
|
.spl_add = sys_pl_unplayed_add,
|
||||||
.spl_remove = playlist_generic_remove_track,
|
.spl_remove = playlist_generic_remove_track,
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
@ -179,6 +198,7 @@ static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
},
|
},
|
||||||
[SYS_PL_MOST_PLAYED] = {
|
[SYS_PL_MOST_PLAYED] = {
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"),
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"),
|
||||||
|
.spl_init = sys_pl_generic_init,
|
||||||
.spl_add = sys_pl_most_played_add,
|
.spl_add = sys_pl_most_played_add,
|
||||||
.spl_remove = playlist_generic_remove_track,
|
.spl_remove = playlist_generic_remove_track,
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
@ -186,6 +206,7 @@ static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
},
|
},
|
||||||
[SYS_PL_LEAST_PLAYED] = {
|
[SYS_PL_LEAST_PLAYED] = {
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"),
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"),
|
||||||
|
.spl_init = sys_pl_generic_init,
|
||||||
.spl_add = sys_pl_least_played_add,
|
.spl_add = sys_pl_least_played_add,
|
||||||
.spl_remove = playlist_generic_remove_track,
|
.spl_remove = playlist_generic_remove_track,
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
@ -381,18 +402,12 @@ struct playlist_type pl_system = {
|
||||||
|
|
||||||
void pl_system_init(struct queue_ops *ops)
|
void pl_system_init(struct queue_ops *ops)
|
||||||
{
|
{
|
||||||
|
struct sys_playlist *sys_pl;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
||||||
queue_init(__sys_pl_queue(i), Q_ENABLED | Q_REPEAT, ops, &sys_playlists[i]);
|
sys_pl = &sys_playlists[i];
|
||||||
if (i != SYS_PL_HISTORY) {
|
sys_pl->spl_init(&sys_pl->spl_playlist, 0, ops);
|
||||||
queue_sort(__sys_pl_queue(i), COMPARE_ARTIST, true);
|
|
||||||
queue_sort(__sys_pl_queue(i), COMPARE_YEAR, false);
|
|
||||||
queue_sort(__sys_pl_queue(i), COMPARE_TRACK, false);
|
|
||||||
} else
|
|
||||||
queue_set_flag(__sys_pl_queue(i), Q_NO_SORT);
|
|
||||||
if (i >= SYS_PL_COLLECTION)
|
|
||||||
queue_set_flag(__sys_pl_queue(i), Q_ADD_FRONT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idle_schedule(IDLE_SYNC, __sys_pl_load, NULL);
|
idle_schedule(IDLE_SYNC, __sys_pl_load, NULL);
|
||||||
|
|
|
@ -20,6 +20,7 @@ enum sys_playlist_t {
|
||||||
struct sys_playlist {
|
struct sys_playlist {
|
||||||
struct playlist spl_playlist;
|
struct playlist spl_playlist;
|
||||||
|
|
||||||
|
void (*spl_init)(struct playlist *, unsigned int, struct queue_ops *);
|
||||||
bool (*spl_add)(struct playlist *, struct track *);
|
bool (*spl_add)(struct playlist *, struct track *);
|
||||||
bool (*spl_remove)(struct playlist *, struct track *);
|
bool (*spl_remove)(struct playlist *, struct track *);
|
||||||
void (*spl_set_flag)(struct playlist *, enum queue_flags, bool);
|
void (*spl_set_flag)(struct playlist *, enum queue_flags, bool);
|
||||||
|
|
|
@ -61,6 +61,9 @@ void playlist_noop_set_flag(struct playlist *, enum queue_flags, bool);
|
||||||
void playlist_noop_sort(struct playlist *, enum compare_t, bool);
|
void playlist_noop_sort(struct playlist *, enum compare_t, bool);
|
||||||
|
|
||||||
|
|
||||||
|
/* Generic playlist init function. */
|
||||||
|
void playlist_generic_init(struct playlist *, unsigned int, struct queue_ops *);
|
||||||
|
|
||||||
/* Generic playlist add track operation. */
|
/* Generic playlist add track operation. */
|
||||||
bool playlist_generic_add_track(struct playlist *, struct track *);
|
bool playlist_generic_add_track(struct playlist *, struct track *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue