ocarina/include/core/playlists/type.h
Anna Schumaker b17585237a core/playlist: Add a playlist_played() function
This is used to notify when tracks have been played so dynamic playlists
can be updated, and so the model can display the correct playcount.

The old system playlist tests are mostly unnecessary at this point, so I
remove them as part of this patch.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2017-04-28 09:40:02 -04:00

116 lines
3.2 KiB
C

/*
* Copyright 2016 (c) Anna Schumaker.
*/
#ifndef OCARINA_CORE_PLAYLISTS_TYPE_H
#define OCARINA_CORE_PLAYLISTS_TYPE_H
#include <core/queue.h>
#include <core/tags/track.h>
#include <glib.h>
#include <stdbool.h>
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 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 pick the next track from a playlist. */
struct track *(*pl_next)(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);
/* Called to sort the playlist. */
void (*pl_sort)(struct playlist *, enum compare_t, bool);
};
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. */
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, 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 update a playlist. */
void (*pl_update)(const gchar *);
};
/* 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 */