From ae604ab4a8b0406bb955f16a47eabaca761aeaff Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 13 Sep 2016 13:57:50 -0400 Subject: [PATCH] core/playlists/system: Remove sys_playlist struct It isn't needed now that playlist differences are handled in the upper layer. This also lets me create a shared set of operations for dynamic playlists. Signed-off-by: Anna Schumaker --- core/playlists/system.c | 122 +++++++------------------------- include/core/playlists/system.h | 4 -- 2 files changed, 26 insertions(+), 100 deletions(-) diff --git a/core/playlists/system.c b/core/playlists/system.c index b2c09afa..a744b567 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -85,11 +85,6 @@ static struct playlist_ops favorites_ops = { .pl_sort = playlist_generic_sort, }; -static struct sys_playlist sys_favorites = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Favorites", - SYS_PL_FAVORITES, &favorites_ops), -}; - /* * Hidden tracks playlist operations. @@ -141,11 +136,6 @@ static struct playlist_ops hidden_ops = { .pl_sort = playlist_generic_sort, }; -static struct sys_playlist sys_hidden = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Hidden", - SYS_PL_HIDDEN, &hidden_ops), -}; - /* * Queued tracks playlist operations. @@ -192,11 +182,6 @@ static struct playlist_ops queued_ops = { .pl_sort = playlist_generic_sort, }; -static struct sys_playlist sys_queued = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Queued Tracks", - SYS_PL_QUEUED, &queued_ops), -}; - /* * Collection playlist operations. @@ -222,11 +207,6 @@ static struct playlist_ops collection_ops = { .pl_sort = playlist_generic_sort, }; -static struct sys_playlist sys_collection = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Collection", - SYS_PL_COLLECTION, &collection_ops), -}; - /* * History playlist operations. @@ -243,83 +223,32 @@ static struct playlist_ops history_ops = { .pl_next = playlist_generic_next, }; -static struct sys_playlist sys_history = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "History", - SYS_PL_HISTORY, &history_ops), -}; - /* - * Unplayed tracks playlist operations. + * Unplayed, Most Played, and Least Played tracks playlist operations. */ -static struct playlist_ops unplayed_ops = { +static struct playlist_ops dynamic_ops = { .pl_can_select = playlist_generic_can_select, .pl_next = playlist_generic_next, .pl_set_flag = playlist_generic_set_flag, .pl_sort = playlist_generic_sort, }; -static struct sys_playlist sys_unplayed = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Unplayed", - SYS_PL_UNPLAYED, &unplayed_ops), + +#define SYS_PLAYLIST(id, name, ops) \ + [id] = DEFINE_PLAYLIST(PL_SYSTEM, name, id, ops) + +static struct playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = { + SYS_PLAYLIST(SYS_PL_FAVORITES, "Favorites", &favorites_ops), + SYS_PLAYLIST(SYS_PL_HIDDEN, "Hidden", &hidden_ops), + SYS_PLAYLIST(SYS_PL_QUEUED, "Queued Tracks", &queued_ops), + SYS_PLAYLIST(SYS_PL_COLLECTION, "Collection", &collection_ops), + SYS_PLAYLIST(SYS_PL_HISTORY, "History", &history_ops), + SYS_PLAYLIST(SYS_PL_UNPLAYED, "Unplayed", &dynamic_ops), + SYS_PLAYLIST(SYS_PL_MOST_PLAYED, "Most Played", &dynamic_ops), + SYS_PLAYLIST(SYS_PL_LEAST_PLAYED, "Least Played", &dynamic_ops), }; - -/* - * Most played tracks playlist operations. - */ -static struct playlist_ops most_played_ops = { - .pl_can_select = playlist_generic_can_select, - .pl_next = playlist_generic_next, - .pl_set_flag = playlist_generic_set_flag, - .pl_sort = playlist_generic_sort, -}; - -static struct sys_playlist sys_most_played = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Most Played", - SYS_PL_MOST_PLAYED, &most_played_ops), -}; - - -/* - * Least played tracks playlist operations. - */ -static struct playlist_ops least_played_ops = { - .pl_can_select = playlist_generic_can_select, - .pl_next = playlist_generic_next, - .pl_set_flag = playlist_generic_set_flag, - .pl_sort = playlist_generic_sort, -}; - -static struct sys_playlist sys_least_played = { - .spl_playlist = DEFINE_PLAYLIST(PL_SYSTEM, "Least Played", - SYS_PL_LEAST_PLAYED, &least_played_ops), -}; - - -static struct sys_playlist *sys_playlists[SYS_PL_NUM_PLAYLISTS] = { - [SYS_PL_FAVORITES] = &sys_favorites, - [SYS_PL_HIDDEN] = &sys_hidden, - [SYS_PL_QUEUED] = &sys_queued, - [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) -{ - unsigned int i; - - for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) { - if (string_match(name, sys_playlists[i]->spl_playlist.pl_name)) - return sys_playlists[i]; - } - return NULL; -} - static bool __sys_pl_update_save() { pl_system_save(); @@ -419,13 +348,19 @@ static void pl_system_save(void) static struct playlist *pl_system_lookup(const gchar *name) { - struct sys_playlist *sys_pl = __sys_pl_lookup(name); - return sys_pl ? &sys_pl->spl_playlist : NULL; + unsigned int i; + + for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) { + if (string_match(name, pl_system_get(i)->pl_name)) + return pl_system_get(i); + } + + return NULL; } static struct playlist *pl_system_get(unsigned int id) { - return (id < SYS_PL_NUM_PLAYLISTS) ? &sys_playlists[id]->spl_playlist : NULL; + return (id < SYS_PL_NUM_PLAYLISTS) ? &sys_playlists[id] : NULL; } static void pl_system_played(struct track *track) @@ -490,11 +425,6 @@ void pl_system_new_track(struct track *track) void pl_system_delete_track(struct track *track) { - struct sys_playlist *sys_pl; - unsigned int i; - - for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) { - sys_pl = sys_playlists[i]; - playlist_generic_remove_track(&sys_pl->spl_playlist, track); - } + for (unsigned int i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) + playlist_generic_remove_track(pl_system_get(i), track); } diff --git a/include/core/playlists/system.h b/include/core/playlists/system.h index ed396199..6b442e51 100644 --- a/include/core/playlists/system.h +++ b/include/core/playlists/system.h @@ -18,10 +18,6 @@ enum sys_playlist_t { SYS_PL_NUM_PLAYLISTS, /* Number of system playlists. */ }; -struct sys_playlist { - struct playlist spl_playlist; -}; - /* System playlist type. */ extern struct playlist_type pl_system;