/* * Copyright 2016 (c) Anna Schumaker. */ #ifndef OCARINA_CORE_PLAYLISTS_PLAYLIST_H #define OCARINA_CORE_PLAYLISTS_PLAYLIST_H #include #include typedef GList * playlist_iter; struct playlist; enum playlist_type_t { PL_SYSTEM, PL_ARTIST, PL_LIBRARY, PL_USER, PL_MAX_TYPE, }; #define PL_RANDOM (1 << 1) struct playlist_ops { /* Called to add a track to a playlist. */ bool (*pl_add)(struct playlist *, struct track *); /* Called to check if a playlist can be selected. */ bool (*pl_can_select)(struct playlist *); /* Called to delete a playlist. */ bool (*pl_delete)(struct playlist *); /* Called to remove a track from the playlist. */ bool (*pl_remove)(struct playlist *, struct track *); /* Called to set a playlist flag. */ void (*pl_set_random)(struct playlist *, bool); /* Called to sort the playlist. */ void (*pl_sort)(struct playlist *, enum compare_t); /* Called to rearrange the playlist. */ bool (*pl_rearrange)(struct playlist *, unsigned int, unsigned int); }; struct playlist { enum playlist_type_t pl_type; /* This playlist's type. */ gchar *pl_name; /* This playlist's name. */ unsigned int pl_id; /* This playlist's identifier. */ GQueue pl_tracks; /* This playlist's queue of tracks. */ unsigned int pl_length; /* This playlist's length, in seconds. */ bool pl_random; /* This playlist's random setting. */ playlist_iter pl_current; /* This playlist's current track. */ GSList *pl_sort; /* This playlist's sort order. */ gchar **pl_search; /* This playlist's search text. */ const struct playlist_ops *pl_ops; /* This playlist's supported operations. */ }; #define DEFINE_PLAYLIST(type, name, id, ops) { \ .pl_type = type, \ .pl_name = name, \ .pl_id = id, \ .pl_ops = ops, \ } struct playlist_type { /* Called to save all playlists of the given type. */ void (*pl_save)(void); /* Called to look up playlists. */ struct playlist *(*pl_lookup)(const gchar *); struct playlist *(*pl_get)(unsigned int); /* Called to create a new playlist. */ struct playlist *(*pl_new)(const gchar *); /* Called to notify that a track has been played. */ void (*pl_played)(struct track *); /* Called to notify that a track has been selected. */ void (*pl_selected)(struct track *); }; /* Called to check if the playlist contains a specific track. */ static inline bool playlist_has(struct playlist *playlist, struct track *track) { return playlist ? g_queue_find(&playlist->pl_tracks, track) != NULL : false; } /* Called to find the size of a playlist. */ static inline unsigned int playlist_size(struct playlist *playlist) { return playlist ? g_queue_get_length(&playlist->pl_tracks) : 0; } /* Called to clear the sort order of the playlist. */ static inline void playlist_clear_sort(struct playlist *playlist) { if (playlist) { g_slist_free(playlist->pl_sort); playlist->pl_sort = NULL; } } #endif /* OCARINA_CORE_PLAYLISTS_PLAYLIST_H */