core/playlists/system: Add collection playlist
Implements #7: Convert collection queue into a playlist Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
5d4de9c5b0
commit
6265b937c7
|
@ -56,6 +56,7 @@ static void __scan_path(struct scan_data *scan, const gchar *name)
|
|||
track = track_add(scan->sd_lib, path);
|
||||
if (track) {
|
||||
queue_add(&c_queue, track);
|
||||
playlist_add("Collection", track);
|
||||
playlist_add("Unplayed", track);
|
||||
}
|
||||
}
|
||||
|
@ -110,6 +111,7 @@ static bool __validate_library(void *data)
|
|||
if (collection_check_library(library) < 0)
|
||||
return true;
|
||||
queue_remove_all(&c_queue, track);
|
||||
playlist_remove("Collection", track);
|
||||
playlist_remove("Favorites", track);
|
||||
playlist_remove("Hidden", track);
|
||||
playlist_remove("Least Played", track);
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
|
||||
static bool __sys_pl_remove(enum sys_playlist_t, struct track *);
|
||||
|
||||
static struct file sys_file = FILE_INIT("playlist.db", 0, 0);
|
||||
static struct file sys_file = FILE_INIT("playlist.db", 0, 0);
|
||||
static struct file sys_collection = FILE_INIT("library.q", 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_COLLECTION] = DEFINE_PLAYLIST("Collection"),
|
||||
[SYS_PL_UNPLAYED] = DEFINE_PLAYLIST("Unplayed"),
|
||||
[SYS_PL_MOST_PLAYED] = DEFINE_PLAYLIST("Most Played"),
|
||||
[SYS_PL_LEAST_PLAYED] = DEFINE_PLAYLIST("Least Played"),
|
||||
|
@ -23,6 +25,8 @@ static enum sys_playlist_t __sys_pl_convert(const gchar *name)
|
|||
return SYS_PL_FAVORITES;
|
||||
else if (string_match(name, "Hidden") || string_match(name, "Banned"))
|
||||
return SYS_PL_HIDDEN;
|
||||
else if (string_match(name, "Collection"))
|
||||
return SYS_PL_COLLECTION;
|
||||
else if (string_match(name, "Unplayed"))
|
||||
return SYS_PL_UNPLAYED;
|
||||
else if (string_match(name, "Most Played"))
|
||||
|
@ -51,14 +55,23 @@ static void __sys_pl_save()
|
|||
file_close(&sys_file);
|
||||
}
|
||||
|
||||
static bool __sys_pl_load()
|
||||
static void __sys_pl_save_collection()
|
||||
{
|
||||
if (!file_open(&sys_collection, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
queue_save_flags(__sys_pl_queue(SYS_PL_COLLECTION), &sys_collection);
|
||||
file_close(&sys_collection);
|
||||
}
|
||||
|
||||
static void __sys_pl_load_playlists()
|
||||
{
|
||||
enum sys_playlist_t plist;
|
||||
unsigned int i, n;
|
||||
gchar *name;
|
||||
|
||||
if (!file_open(&sys_file, OPEN_READ))
|
||||
return true;
|
||||
return;
|
||||
|
||||
file_readf(&sys_file, "%u\n", &n);
|
||||
for (i = 0; i < n; i++) {
|
||||
|
@ -71,13 +84,33 @@ static bool __sys_pl_load()
|
|||
}
|
||||
|
||||
file_close(&sys_file);
|
||||
return;
|
||||
}
|
||||
|
||||
static void __sys_pl_load_collection()
|
||||
{
|
||||
if (!file_open(&sys_collection, OPEN_READ))
|
||||
return;
|
||||
|
||||
queue_load_flags(__sys_pl_queue(SYS_PL_COLLECTION), &sys_collection);
|
||||
queue_unset_flag(__sys_pl_queue(SYS_PL_COLLECTION), Q_SAVE_FLAGS);
|
||||
queue_unset_flag(__sys_pl_queue(SYS_PL_COLLECTION), Q_SAVE_SORT);
|
||||
file_close(&sys_collection);
|
||||
}
|
||||
|
||||
static bool __sys_pl_load()
|
||||
{
|
||||
__sys_pl_load_playlists();
|
||||
__sys_pl_load_collection();
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool __sys_pl_can_add(enum sys_playlist_t plist, struct track *track,
|
||||
unsigned int average)
|
||||
{
|
||||
if (track->tr_count == 0)
|
||||
if (plist == SYS_PL_COLLECTION)
|
||||
return true;
|
||||
else if (track->tr_count == 0)
|
||||
return plist == SYS_PL_UNPLAYED;
|
||||
else if (track->tr_count <= average)
|
||||
return plist == SYS_PL_LEAST_PLAYED;
|
||||
|
@ -101,6 +134,7 @@ static bool __sys_pl_add(enum sys_playlist_t plist, struct track *track,
|
|||
|
||||
switch (plist) {
|
||||
case SYS_PL_HIDDEN:
|
||||
__sys_pl_remove(SYS_PL_COLLECTION, track);
|
||||
__sys_pl_remove(SYS_PL_UNPLAYED, track);
|
||||
__sys_pl_remove(SYS_PL_MOST_PLAYED, track);
|
||||
__sys_pl_remove(SYS_PL_LEAST_PLAYED, track);
|
||||
|
@ -127,6 +161,7 @@ static bool __sys_pl_remove(enum sys_playlist_t plist, struct track *track)
|
|||
|
||||
switch (plist) {
|
||||
case SYS_PL_HIDDEN:
|
||||
__sys_pl_add(SYS_PL_COLLECTION, track, track_db_average_plays());
|
||||
__sys_pl_add(SYS_PL_UNPLAYED, track, track_db_average_plays());
|
||||
__sys_pl_add(SYS_PL_MOST_PLAYED, track, track_db_average_plays());
|
||||
__sys_pl_add(SYS_PL_LEAST_PLAYED, track, track_db_average_plays());
|
||||
|
@ -195,6 +230,9 @@ static void pl_system_set_flag(const gchar *name, enum queue_flags flag,
|
|||
queue_set_flag(__sys_pl_queue(plist), flag);
|
||||
else
|
||||
queue_unset_flag(__sys_pl_queue(plist), flag);
|
||||
|
||||
if (plist == SYS_PL_COLLECTION)
|
||||
__sys_pl_save_collection();
|
||||
}
|
||||
|
||||
static void pl_system_sort(const gchar *name, enum compare_t sort, bool reset)
|
||||
|
@ -202,6 +240,8 @@ static void pl_system_sort(const gchar *name, enum compare_t sort, bool reset)
|
|||
enum sys_playlist_t plist = __sys_pl_convert(name);
|
||||
|
||||
queue_sort(__sys_pl_queue(plist), sort, reset);
|
||||
if (plist == SYS_PL_COLLECTION)
|
||||
__sys_pl_save_collection();
|
||||
}
|
||||
|
||||
|
||||
|
@ -224,11 +264,12 @@ void pl_system_init(struct queue_ops *ops)
|
|||
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)
|
||||
if (i >= SYS_PL_COLLECTION)
|
||||
queue_set_flag(__sys_pl_queue(i), Q_ADD_FRONT);
|
||||
}
|
||||
|
||||
idle_schedule(IDLE_SYNC, __sys_pl_load, NULL);
|
||||
pl_system_update("Collection");
|
||||
pl_system_update("Unplayed");
|
||||
pl_system_update("Most Played");
|
||||
pl_system_update("Least Played");
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
enum sys_playlist_t {
|
||||
SYS_PL_FAVORITES, /* Songs that the user likes. */
|
||||
SYS_PL_HIDDEN, /* Songs that the user has hidden. */
|
||||
SYS_PL_COLLECTION, /* Songs that have not been hidden. */
|
||||
SYS_PL_UNPLAYED, /* Songs that have not been played yet. */
|
||||
SYS_PL_MOST_PLAYED, /* Songs with an above average play count. */
|
||||
SYS_PL_LEAST_PLAYED, /* Songs with a below average play count. */
|
||||
|
|
|
@ -112,6 +112,24 @@ static void test_hidden()
|
|||
__test_playlist_remove("Hidden", queue);
|
||||
}
|
||||
|
||||
static void test_collection()
|
||||
{
|
||||
struct queue *queue = pl_system.pl_get_queue("Collection");
|
||||
|
||||
pl_system_deinit();
|
||||
pl_system_init(NULL);
|
||||
|
||||
test_not_equal((void *)queue, NULL);
|
||||
test_equal(queue_has_flag(queue, Q_ADD_FRONT), (bool)true);
|
||||
|
||||
__test_playlist_random("Collection", queue);
|
||||
__test_playlist_add("Collection", queue);
|
||||
__test_playlist_hide_track("Collection", queue, 1, false, true);
|
||||
__test_playlist_reinit(queue, 1, false, true);
|
||||
__test_playlist_update("Collection", queue, 1, false, true);
|
||||
__test_playlist_unhide_track("Collection", queue, 2, true, true);
|
||||
}
|
||||
|
||||
static void test_unplayed()
|
||||
{
|
||||
struct queue *queue = pl_system.pl_get_queue("Unplayed");
|
||||
|
@ -223,6 +241,7 @@ DECLARE_UNIT_TESTS(
|
|||
UNIT_TEST("Invalid Playlist", test_invalid),
|
||||
UNIT_TEST("Favorites Playlist", test_favorites),
|
||||
UNIT_TEST("Hidden Playlist", test_hidden),
|
||||
UNIT_TEST("Collection Playlist", test_collection),
|
||||
UNIT_TEST("Unplayed Tracks Playlist", test_unplayed),
|
||||
UNIT_TEST("Most Played Tracks Playlist", test_most_played),
|
||||
UNIT_TEST("Least Played Tracks Playlist", test_least_played),
|
||||
|
|
Loading…
Reference in New Issue