/* * Copyright 2016 (c) Anna Schumaker. */ #ifndef OCARINA_CORE_PLAYLISTS_TYPE_H #define OCARINA_CORE_PLAYLISTS_TYPE_H #include #include #include #include struct playlist; enum playlist_type_t { PL_SYSTEM, PL_ARTIST, PL_LIBRARY, PL_USER, PL_MAX_TYPE, }; struct playlist_ops { /* Called to add a track to a playlist. */ bool (*pl_add)(struct playlist *, struct track *); /* 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_flag)(struct playlist *, enum queue_flags, bool); }; struct playlist { enum playlist_type_t pl_type; /* This playlist's type. */ gchar *pl_name; /* This playlist's name. */ void *pl_private; /* This playlist's private data. */ struct queue pl_queue; /* This playlist's queue of tracks. */ const struct playlist_ops *pl_ops; /* This playlist's supported operations. */ }; #define DEFINE_PLAYLIST(type, name, ops) { \ .pl_type = type, \ .pl_name = name, \ .pl_ops = ops, \ } struct playlist_type { /* Called to save all playlists of the given type. */ void (*pl_save)(void); /* Called to get the playlist. */ struct playlist *(*pl_get_playlist)(const gchar *); /* Called to convert a playlist name to an integer id. */ unsigned int (*pl_get_id)(const gchar *); /* Called to convert a playlist id to a name. */ gchar *(*pl_get_name)(unsigned int); /* Called to check if a playlist can be selected. */ bool (*pl_can_select)(const gchar *); /* Called to create a new playlist. */ struct playlist *(*pl_new)(const gchar *); /* Called to update a playlist. */ void (*pl_update)(const gchar *); /* Called to sort a playlist. */ void (*pl_sort)(const gchar *, enum compare_t, bool); /* Called to pick the next track from a playlist. */ struct track *(*pl_next)(const gchar *); }; /* Noop playlist can-select operation. */ bool playlist_noop_can_select(struct playlist *); /* Noop playlist sorting operation. */ 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 can-select function. */ bool playlist_generic_can_select(struct playlist *); /* Generic playlist clear operation. */ void playlist_generic_clear(struct playlist *); /* Generic playlist add track operations. */ bool playlist_generic_add_track(struct playlist *, struct track *); bool playlist_generic_add_track_front(struct playlist *, struct track *); /* Generic playlist remove track operation. */ bool playlist_generic_remove_track(struct playlist *, struct track *); /* Generic playlist update operation. */ void playlist_generic_update(struct playlist *, bool (*)(struct playlist *, struct track *)); /* Generic playlist set_flag operation. */ void playlist_generic_set_flag(struct playlist *, enum queue_flags, bool); /* Generic playlist sorting operation. */ void playlist_generic_sort(struct playlist *, enum compare_t, bool); /* Generic playlist next track operation. */ struct track *playlist_generic_next(struct playlist *); #endif /* OCARINA_CORE_PLAYLISTS_TYPE_H */