core/playlists: Add struct playlist
Containing the playlist name and queue. I pass this to the gui through the queue_init() function. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
44a57ed863
commit
62123eb025
|
@ -5,10 +5,17 @@
|
|||
#include <core/playlists/system.h>
|
||||
#include <core/string.h>
|
||||
|
||||
static struct file sys_file = FILE_INIT("playlist.db", 0, 0);
|
||||
static struct queue sys_playlists[SYS_PL_NUM_PLAYLISTS];
|
||||
static bool __sys_pl_remove(enum sys_playlist_t, struct track *);
|
||||
|
||||
static struct file sys_file = FILE_INIT("playlist.db", 0, 0);
|
||||
static struct playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||
[SYS_PL_FAVORITES] = DEFINE_PLAYLIST("Favorites"),
|
||||
[SYS_PL_HIDDEN] = DEFINE_PLAYLIST("Hidden"),
|
||||
[SYS_PL_UNPLAYED] = DEFINE_PLAYLIST("Unplayed"),
|
||||
[SYS_PL_MOST_PLAYED] = DEFINE_PLAYLIST("Most Played"),
|
||||
[SYS_PL_LEAST_PLAYED] = DEFINE_PLAYLIST("Least Played"),
|
||||
};
|
||||
|
||||
|
||||
static enum sys_playlist_t __sys_pl_convert(const gchar *name)
|
||||
{
|
||||
|
@ -25,15 +32,20 @@ static enum sys_playlist_t __sys_pl_convert(const gchar *name)
|
|||
return SYS_PL_NUM_PLAYLISTS;
|
||||
}
|
||||
|
||||
static inline struct queue *__sys_pl_queue(enum sys_playlist_t plist)
|
||||
{
|
||||
return &sys_playlists[plist].pl_queue;
|
||||
}
|
||||
|
||||
static void __sys_pl_save()
|
||||
{
|
||||
if (!file_open(&sys_file, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
file_writef(&sys_file, "%u\n 1 %s\n", 2, "Favorites");
|
||||
queue_save_tracks(&sys_playlists[SYS_PL_FAVORITES], &sys_file);
|
||||
queue_save_tracks(__sys_pl_queue(SYS_PL_FAVORITES), &sys_file);
|
||||
file_writef(&sys_file, "\n1 %s\n", "Banned");
|
||||
queue_save_tracks(&sys_playlists[SYS_PL_HIDDEN], &sys_file);
|
||||
queue_save_tracks(__sys_pl_queue(SYS_PL_HIDDEN), &sys_file);
|
||||
file_writef(&sys_file, "\n");
|
||||
|
||||
file_close(&sys_file);
|
||||
|
@ -54,7 +66,7 @@ static bool __sys_pl_load()
|
|||
|
||||
plist = __sys_pl_convert(name);
|
||||
if (plist < SYS_PL_NUM_PLAYLISTS)
|
||||
queue_load_tracks(&sys_playlists[plist], &sys_file);
|
||||
queue_load_tracks(__sys_pl_queue(plist), &sys_file);
|
||||
g_free(name);
|
||||
}
|
||||
|
||||
|
@ -79,13 +91,13 @@ static bool __sys_pl_add(enum sys_playlist_t plist, struct track *track,
|
|||
if (plist != SYS_PL_FAVORITES && plist != SYS_PL_HIDDEN) {
|
||||
if (!__sys_pl_can_add(plist, track, average))
|
||||
return false;
|
||||
if (queue_has(&sys_playlists[SYS_PL_HIDDEN], track))
|
||||
if (queue_has(__sys_pl_queue(SYS_PL_HIDDEN), track))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (queue_has(&sys_playlists[plist], track))
|
||||
if (queue_has(__sys_pl_queue(plist), track))
|
||||
return false;
|
||||
queue_add(&sys_playlists[plist], track);
|
||||
queue_add(__sys_pl_queue(plist), track);
|
||||
|
||||
switch (plist) {
|
||||
case SYS_PL_HIDDEN:
|
||||
|
@ -110,7 +122,7 @@ static bool __sys_pl_add(enum sys_playlist_t plist, struct track *track,
|
|||
|
||||
static bool __sys_pl_remove(enum sys_playlist_t plist, struct track *track)
|
||||
{
|
||||
if (!queue_remove_all(&sys_playlists[plist], track))
|
||||
if (!queue_remove_all(__sys_pl_queue(plist), track))
|
||||
return false;
|
||||
|
||||
switch (plist) {
|
||||
|
@ -138,7 +150,7 @@ static bool __sys_pl_update(enum sys_playlist_t plist)
|
|||
__sys_pl_remove(plist, TRACK(dbe));
|
||||
}
|
||||
|
||||
queue_unset_flag(&sys_playlists[plist], Q_ADD_FRONT);
|
||||
queue_unset_flag(__sys_pl_queue(plist), Q_ADD_FRONT);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -148,7 +160,7 @@ static struct queue *pl_system_get_queue(const gchar *name)
|
|||
enum sys_playlist_t plist = __sys_pl_convert(name);
|
||||
if (plist == SYS_PL_NUM_PLAYLISTS)
|
||||
return NULL;
|
||||
return &sys_playlists[plist];
|
||||
return __sys_pl_queue(plist);
|
||||
}
|
||||
|
||||
static bool pl_system_add_track(const gchar *name, struct track *track)
|
||||
|
@ -189,12 +201,12 @@ void pl_system_init(struct queue_ops *ops)
|
|||
unsigned int i;
|
||||
|
||||
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
||||
queue_init(&sys_playlists[i], Q_ENABLED | Q_REPEAT, ops, NULL);
|
||||
queue_sort(&sys_playlists[i], COMPARE_ARTIST, true);
|
||||
queue_sort(&sys_playlists[i], COMPARE_YEAR, false);
|
||||
queue_sort(&sys_playlists[i], COMPARE_TRACK, false);
|
||||
queue_init(__sys_pl_queue(i), Q_ENABLED | Q_REPEAT, ops, &sys_playlists[i]);
|
||||
queue_sort(__sys_pl_queue(i), COMPARE_ARTIST, true);
|
||||
queue_sort(__sys_pl_queue(i), COMPARE_YEAR, false);
|
||||
queue_sort(__sys_pl_queue(i), COMPARE_TRACK, false);
|
||||
if (i >= SYS_PL_UNPLAYED)
|
||||
queue_set_flag(&sys_playlists[i], Q_ADD_FRONT);
|
||||
queue_set_flag(__sys_pl_queue(i), Q_ADD_FRONT);
|
||||
}
|
||||
|
||||
idle_schedule(IDLE_SYNC, __sys_pl_load, NULL);
|
||||
|
@ -208,5 +220,5 @@ void pl_system_deinit()
|
|||
unsigned int i;
|
||||
|
||||
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++)
|
||||
queue_deinit(&sys_playlists[i]);
|
||||
queue_deinit(__sys_pl_queue(i));
|
||||
}
|
||||
|
|
|
@ -9,6 +9,15 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
|
||||
struct playlist {
|
||||
const gchar *pl_name; /* This playlist's name. */
|
||||
struct queue pl_queue; /* This playlist's queue of tracks. */
|
||||
};
|
||||
|
||||
|
||||
#define DEFINE_PLAYLIST(name) { .pl_name = name, }
|
||||
|
||||
|
||||
struct playlist_type {
|
||||
/* Called to get the queue for the playlist. */
|
||||
struct queue *(*pl_get_queue)(const gchar *);
|
||||
|
|
Loading…
Reference in New Issue