core/playlists/system: Define each playlist near it's associated functions
I think this is a bit cleaner, and helps to keep similar things together. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
532d55ba4f
commit
f4b12c5a83
|
@ -10,8 +10,9 @@ static bool pl_system_remove_track(const gchar *, struct track *);
|
||||||
static inline struct queue *__sys_pl_queue(enum sys_playlist_t);
|
static inline struct queue *__sys_pl_queue(enum sys_playlist_t);
|
||||||
static void __sys_pl_save();
|
static void __sys_pl_save();
|
||||||
|
|
||||||
static struct file sys_file = FILE_INIT("playlist.db", 0, 0);
|
static struct file sys_file = FILE_INIT("playlist.db", 0, 0);
|
||||||
static struct file sys_collection = FILE_INIT("library.q", 0, 0);
|
static struct file sys_collection_f = FILE_INIT("library.q", 0, 0);
|
||||||
|
static struct sys_playlist *sys_playlists[SYS_PL_NUM_PLAYLISTS];
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -48,6 +49,15 @@ static bool sys_pl_favorites_remove(struct playlist *playlist, struct track *tra
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sys_playlist sys_favorites = {
|
||||||
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"),
|
||||||
|
.spl_init = playlist_generic_init,
|
||||||
|
.spl_add = sys_pl_favorites_add,
|
||||||
|
.spl_remove = sys_pl_favorites_remove,
|
||||||
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
.spl_sort = playlist_generic_sort,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hidden tracks playlist operations.
|
* Hidden tracks playlist operations.
|
||||||
|
@ -74,25 +84,34 @@ static bool sys_pl_hidden_remove(struct playlist *playlist, struct track *track)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sys_playlist sys_hidden = {
|
||||||
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"),
|
||||||
|
.spl_init = playlist_generic_init,
|
||||||
|
.spl_add = sys_pl_hidden_add,
|
||||||
|
.spl_remove = sys_pl_hidden_remove,
|
||||||
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
.spl_sort = playlist_generic_sort,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Collection playlist operations.
|
* Collection playlist operations.
|
||||||
*/
|
*/
|
||||||
static void sys_pl_collection_save(struct playlist *playlist)
|
static void sys_pl_collection_save(struct playlist *playlist)
|
||||||
{
|
{
|
||||||
if (file_open(&sys_collection, OPEN_WRITE)) {
|
if (file_open(&sys_collection_f, OPEN_WRITE)) {
|
||||||
queue_save_flags(&playlist->pl_queue, &sys_collection);
|
queue_save_flags(&playlist->pl_queue, &sys_collection_f);
|
||||||
file_close(&sys_collection);
|
file_close(&sys_collection_f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sys_pl_collection_load(struct playlist *playlist)
|
static void sys_pl_collection_load(struct playlist *playlist)
|
||||||
{
|
{
|
||||||
if (file_open(&sys_collection, OPEN_READ)) {
|
if (file_open(&sys_collection_f, OPEN_READ)) {
|
||||||
queue_load_flags(&playlist->pl_queue, &sys_collection);
|
queue_load_flags(&playlist->pl_queue, &sys_collection_f);
|
||||||
queue_unset_flag(&playlist->pl_queue, Q_SAVE_FLAGS);
|
queue_unset_flag(&playlist->pl_queue, Q_SAVE_FLAGS);
|
||||||
queue_unset_flag(&playlist->pl_queue, Q_SAVE_SORT);
|
queue_unset_flag(&playlist->pl_queue, Q_SAVE_SORT);
|
||||||
file_close(&sys_collection);
|
file_close(&sys_collection_f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +144,16 @@ static void sys_pl_collection_sort(struct playlist *playlist,
|
||||||
sys_pl_collection_save(playlist);
|
sys_pl_collection_save(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sys_playlist sys_collection = {
|
||||||
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"),
|
||||||
|
.spl_init = sys_pl_generic_init,
|
||||||
|
.spl_add = sys_pl_collection_add,
|
||||||
|
.spl_remove = playlist_generic_remove_track,
|
||||||
|
.spl_update = sys_pl_collection_update,
|
||||||
|
.spl_set_flag = sys_pl_collection_set_flag,
|
||||||
|
.spl_sort = sys_pl_collection_sort,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* History playlist operations.
|
* History playlist operations.
|
||||||
|
@ -144,6 +173,15 @@ static bool sys_pl_history_add(struct playlist *playlist, struct track *track)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sys_playlist sys_history = {
|
||||||
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History"),
|
||||||
|
.spl_init = sys_pl_history_init,
|
||||||
|
.spl_add = sys_pl_history_add,
|
||||||
|
.spl_remove = playlist_generic_remove_track,
|
||||||
|
.spl_set_flag = playlist_noop_set_flag,
|
||||||
|
.spl_sort = playlist_noop_sort,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unplayed tracks playlist operations.
|
* Unplayed tracks playlist operations.
|
||||||
|
@ -163,6 +201,16 @@ static bool sys_pl_unplayed_update(struct playlist *playlist,
|
||||||
return sys_pl_generic_add(playlist, track) || true;
|
return sys_pl_generic_add(playlist, track) || true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sys_playlist sys_unplayed = {
|
||||||
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"),
|
||||||
|
.spl_init = sys_pl_generic_init,
|
||||||
|
.spl_add = sys_pl_unplayed_add,
|
||||||
|
.spl_remove = playlist_generic_remove_track,
|
||||||
|
.spl_update = sys_pl_unplayed_update,
|
||||||
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
.spl_sort = playlist_generic_sort,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Most played tracks playlist operations.
|
* Most played tracks playlist operations.
|
||||||
|
@ -184,6 +232,16 @@ static bool sys_pl_most_played_update(struct playlist *playlist,
|
||||||
return sys_pl_generic_add(playlist, track) || true;
|
return sys_pl_generic_add(playlist, track) || true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sys_playlist sys_most_played = {
|
||||||
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"),
|
||||||
|
.spl_init = sys_pl_generic_init,
|
||||||
|
.spl_add = sys_pl_most_played_add,
|
||||||
|
.spl_remove = playlist_generic_remove_track,
|
||||||
|
.spl_update = sys_pl_most_played_update,
|
||||||
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
|
.spl_sort = playlist_generic_sort,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Least played tracks playlist operations.
|
* Least played tracks playlist operations.
|
||||||
|
@ -205,99 +263,50 @@ static bool sys_pl_least_played_update(struct playlist *playlist,
|
||||||
return sys_pl_generic_add(playlist, track) || true;
|
return sys_pl_generic_add(playlist, track) || true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct sys_playlist sys_least_played = {
|
||||||
static struct sys_playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"),
|
||||||
[SYS_PL_FAVORITES] = {
|
.spl_init = sys_pl_generic_init,
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites"),
|
.spl_add = sys_pl_least_played_add,
|
||||||
.spl_init = playlist_generic_init,
|
.spl_remove = playlist_generic_remove_track,
|
||||||
.spl_add = sys_pl_favorites_add,
|
.spl_update = sys_pl_least_played_update,
|
||||||
.spl_remove = sys_pl_favorites_remove,
|
.spl_set_flag = playlist_generic_set_flag,
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
.spl_sort = playlist_generic_sort,
|
||||||
.spl_sort = playlist_generic_sort,
|
|
||||||
},
|
|
||||||
[SYS_PL_HIDDEN] = {
|
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden"),
|
|
||||||
.spl_init = playlist_generic_init,
|
|
||||||
.spl_add = sys_pl_hidden_add,
|
|
||||||
.spl_remove = sys_pl_hidden_remove,
|
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
|
||||||
.spl_sort = playlist_generic_sort,
|
|
||||||
},
|
|
||||||
[SYS_PL_COLLECTION] = {
|
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection"),
|
|
||||||
.spl_init = sys_pl_generic_init,
|
|
||||||
.spl_add = sys_pl_collection_add,
|
|
||||||
.spl_remove = playlist_generic_remove_track,
|
|
||||||
.spl_update = sys_pl_collection_update,
|
|
||||||
.spl_set_flag = sys_pl_collection_set_flag,
|
|
||||||
.spl_sort = sys_pl_collection_sort,
|
|
||||||
},
|
|
||||||
[SYS_PL_HISTORY] = {
|
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History"),
|
|
||||||
.spl_init = sys_pl_history_init,
|
|
||||||
.spl_add = sys_pl_history_add,
|
|
||||||
.spl_remove = playlist_generic_remove_track,
|
|
||||||
.spl_set_flag = playlist_noop_set_flag,
|
|
||||||
.spl_sort = playlist_noop_sort,
|
|
||||||
},
|
|
||||||
[SYS_PL_UNPLAYED] = {
|
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed"),
|
|
||||||
.spl_init = sys_pl_generic_init,
|
|
||||||
.spl_add = sys_pl_unplayed_add,
|
|
||||||
.spl_remove = playlist_generic_remove_track,
|
|
||||||
.spl_update = sys_pl_unplayed_update,
|
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
|
||||||
.spl_sort = playlist_generic_sort,
|
|
||||||
},
|
|
||||||
[SYS_PL_MOST_PLAYED] = {
|
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played"),
|
|
||||||
.spl_init = sys_pl_generic_init,
|
|
||||||
.spl_add = sys_pl_most_played_add,
|
|
||||||
.spl_remove = playlist_generic_remove_track,
|
|
||||||
.spl_update = sys_pl_most_played_update,
|
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
|
||||||
.spl_sort = playlist_generic_sort,
|
|
||||||
},
|
|
||||||
[SYS_PL_LEAST_PLAYED] = {
|
|
||||||
.spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played"),
|
|
||||||
.spl_init = sys_pl_generic_init,
|
|
||||||
.spl_add = sys_pl_least_played_add,
|
|
||||||
.spl_remove = playlist_generic_remove_track,
|
|
||||||
.spl_update = sys_pl_least_played_update,
|
|
||||||
.spl_set_flag = playlist_generic_set_flag,
|
|
||||||
.spl_sort = playlist_generic_sort,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static enum sys_playlist_t __sys_pl_convert(const gchar *name)
|
static struct sys_playlist *sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
|
[SYS_PL_FAVORITES] = &sys_favorites,
|
||||||
|
[SYS_PL_HIDDEN] = &sys_hidden,
|
||||||
|
[SYS_PL_COLLECTION] = &sys_collection,
|
||||||
|
[SYS_PL_HISTORY] = &sys_history,
|
||||||
|
[SYS_PL_UNPLAYED] = &sys_unplayed,
|
||||||
|
[SYS_PL_MOST_PLAYED] = &sys_most_played,
|
||||||
|
[SYS_PL_LEAST_PLAYED] = &sys_least_played,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static struct sys_playlist * __sys_pl_lookup(const gchar *name)
|
||||||
{
|
{
|
||||||
if (string_match(name, "Favorites"))
|
if (string_match(name, "Favorites"))
|
||||||
return SYS_PL_FAVORITES;
|
return &sys_favorites;
|
||||||
else if (string_match(name, "Hidden") || string_match(name, "Banned"))
|
else if (string_match(name, "Hidden") || string_match(name, "Banned"))
|
||||||
return SYS_PL_HIDDEN;
|
return &sys_hidden;
|
||||||
else if (string_match(name, "Collection"))
|
else if (string_match(name, "Collection"))
|
||||||
return SYS_PL_COLLECTION;
|
return &sys_collection;
|
||||||
else if (string_match(name, "History"))
|
else if (string_match(name, "History"))
|
||||||
return SYS_PL_HISTORY;
|
return &sys_history;
|
||||||
else if (string_match(name, "Unplayed"))
|
else if (string_match(name, "Unplayed"))
|
||||||
return SYS_PL_UNPLAYED;
|
return &sys_unplayed;
|
||||||
else if (string_match(name, "Most Played"))
|
else if (string_match(name, "Most Played"))
|
||||||
return SYS_PL_MOST_PLAYED;
|
return &sys_most_played;
|
||||||
else if (string_match(name, "Least Played"))
|
else if (string_match(name, "Least Played"))
|
||||||
return SYS_PL_LEAST_PLAYED;
|
return &sys_least_played;
|
||||||
return SYS_PL_NUM_PLAYLISTS;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct queue *__sys_pl_queue(enum sys_playlist_t plist)
|
static inline struct queue *__sys_pl_queue(enum sys_playlist_t plist)
|
||||||
{
|
{
|
||||||
return &sys_playlists[plist].spl_playlist.pl_queue;
|
return &sys_playlists[plist]->spl_playlist.pl_queue;
|
||||||
}
|
|
||||||
|
|
||||||
static struct sys_playlist *__sys_pl_lookup(const gchar *name)
|
|
||||||
{
|
|
||||||
enum sys_playlist_t plist = __sys_pl_convert(name);
|
|
||||||
return (plist < SYS_PL_NUM_PLAYLISTS) ? &sys_playlists[plist] : NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __sys_pl_save()
|
static void __sys_pl_save()
|
||||||
|
@ -316,7 +325,7 @@ static void __sys_pl_save()
|
||||||
|
|
||||||
static void __sys_pl_load_playlists()
|
static void __sys_pl_load_playlists()
|
||||||
{
|
{
|
||||||
enum sys_playlist_t plist;
|
struct sys_playlist *plist;
|
||||||
unsigned int i, n;
|
unsigned int i, n;
|
||||||
gchar *name;
|
gchar *name;
|
||||||
|
|
||||||
|
@ -327,9 +336,9 @@ static void __sys_pl_load_playlists()
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
file_readf(&sys_file, "%*u %m[^\n]\n", &name);
|
file_readf(&sys_file, "%*u %m[^\n]\n", &name);
|
||||||
|
|
||||||
plist = __sys_pl_convert(name);
|
plist = __sys_pl_lookup(name);
|
||||||
if (plist < SYS_PL_NUM_PLAYLISTS)
|
if (plist)
|
||||||
queue_load_tracks(__sys_pl_queue(plist), &sys_file);
|
queue_load_tracks(&plist->spl_playlist.pl_queue, &sys_file);
|
||||||
g_free(name);
|
g_free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,7 +418,7 @@ void pl_system_init(struct queue_ops *ops)
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
||||||
sys_pl = &sys_playlists[i];
|
sys_pl = sys_playlists[i];
|
||||||
sys_pl->spl_init(&sys_pl->spl_playlist, 0, ops);
|
sys_pl->spl_init(&sys_pl->spl_playlist, 0, ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +449,7 @@ void pl_system_delete_track(struct track *track)
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
||||||
sys_pl = &sys_playlists[i];
|
sys_pl = sys_playlists[i];
|
||||||
sys_pl->spl_remove(&sys_pl->spl_playlist, track);
|
sys_pl->spl_remove(&sys_pl->spl_playlist, track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue