core/playlists/system: Add history playlist
Implements #8: Convert history queue into a playlist Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
6265b937c7
commit
efae58c356
|
@ -66,8 +66,10 @@ static struct track *__audio_load_basic(struct track *track, GstState state)
|
||||||
|
|
||||||
static struct track *__audio_load(struct track *track, GstState state)
|
static struct track *__audio_load(struct track *track, GstState state)
|
||||||
{
|
{
|
||||||
if (__audio_load_basic(track, state))
|
if (__audio_load_basic(track, state)) {
|
||||||
history_add(track);
|
history_add(track);
|
||||||
|
playlist_add("History", track);
|
||||||
|
}
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ static struct playlist sys_playlists[SYS_PL_NUM_PLAYLISTS] = {
|
||||||
[SYS_PL_FAVORITES] = DEFINE_PLAYLIST("Favorites"),
|
[SYS_PL_FAVORITES] = DEFINE_PLAYLIST("Favorites"),
|
||||||
[SYS_PL_HIDDEN] = DEFINE_PLAYLIST("Hidden"),
|
[SYS_PL_HIDDEN] = DEFINE_PLAYLIST("Hidden"),
|
||||||
[SYS_PL_COLLECTION] = DEFINE_PLAYLIST("Collection"),
|
[SYS_PL_COLLECTION] = DEFINE_PLAYLIST("Collection"),
|
||||||
|
[SYS_PL_HISTORY] = DEFINE_PLAYLIST("History"),
|
||||||
[SYS_PL_UNPLAYED] = DEFINE_PLAYLIST("Unplayed"),
|
[SYS_PL_UNPLAYED] = DEFINE_PLAYLIST("Unplayed"),
|
||||||
[SYS_PL_MOST_PLAYED] = DEFINE_PLAYLIST("Most Played"),
|
[SYS_PL_MOST_PLAYED] = DEFINE_PLAYLIST("Most Played"),
|
||||||
[SYS_PL_LEAST_PLAYED] = DEFINE_PLAYLIST("Least Played"),
|
[SYS_PL_LEAST_PLAYED] = DEFINE_PLAYLIST("Least Played"),
|
||||||
|
@ -27,6 +28,8 @@ static enum sys_playlist_t __sys_pl_convert(const gchar *name)
|
||||||
return SYS_PL_HIDDEN;
|
return SYS_PL_HIDDEN;
|
||||||
else if (string_match(name, "Collection"))
|
else if (string_match(name, "Collection"))
|
||||||
return SYS_PL_COLLECTION;
|
return SYS_PL_COLLECTION;
|
||||||
|
else if (string_match(name, "History"))
|
||||||
|
return SYS_PL_HISTORY;
|
||||||
else if (string_match(name, "Unplayed"))
|
else if (string_match(name, "Unplayed"))
|
||||||
return SYS_PL_UNPLAYED;
|
return SYS_PL_UNPLAYED;
|
||||||
else if (string_match(name, "Most Played"))
|
else if (string_match(name, "Most Played"))
|
||||||
|
@ -121,14 +124,15 @@ static bool __sys_pl_can_add(enum sys_playlist_t plist, struct track *track,
|
||||||
static bool __sys_pl_add(enum sys_playlist_t plist, struct track *track,
|
static bool __sys_pl_add(enum sys_playlist_t plist, struct track *track,
|
||||||
unsigned int average)
|
unsigned int average)
|
||||||
{
|
{
|
||||||
if (plist != SYS_PL_FAVORITES && plist != SYS_PL_HIDDEN) {
|
if (plist != SYS_PL_FAVORITES && plist != SYS_PL_HIDDEN &&
|
||||||
|
plist != SYS_PL_HISTORY) {
|
||||||
if (!__sys_pl_can_add(plist, track, average))
|
if (!__sys_pl_can_add(plist, track, average))
|
||||||
return false;
|
return false;
|
||||||
if (queue_has(__sys_pl_queue(SYS_PL_HIDDEN), track))
|
if (queue_has(__sys_pl_queue(SYS_PL_HIDDEN), track))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue_has(__sys_pl_queue(plist), track))
|
if (plist != SYS_PL_HISTORY && queue_has(__sys_pl_queue(plist), track))
|
||||||
return false;
|
return false;
|
||||||
queue_add(__sys_pl_queue(plist), track);
|
queue_add(__sys_pl_queue(plist), track);
|
||||||
|
|
||||||
|
@ -148,6 +152,10 @@ static bool __sys_pl_add(enum sys_playlist_t plist, struct track *track,
|
||||||
case SYS_PL_LEAST_PLAYED:
|
case SYS_PL_LEAST_PLAYED:
|
||||||
__sys_pl_remove(SYS_PL_UNPLAYED, track);
|
__sys_pl_remove(SYS_PL_UNPLAYED, track);
|
||||||
__sys_pl_remove(SYS_PL_MOST_PLAYED, track);
|
__sys_pl_remove(SYS_PL_MOST_PLAYED, track);
|
||||||
|
break;
|
||||||
|
case SYS_PL_HISTORY:
|
||||||
|
queue_iter_set(__sys_pl_queue(plist),
|
||||||
|
&__sys_pl_queue(plist)->q_cur, 0);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +225,8 @@ static bool pl_system_remove_track(const gchar *name, struct track *track)
|
||||||
static void pl_system_update(const gchar *name)
|
static void pl_system_update(const gchar *name)
|
||||||
{
|
{
|
||||||
enum sys_playlist_t plist = __sys_pl_convert(name);
|
enum sys_playlist_t plist = __sys_pl_convert(name);
|
||||||
if (plist != SYS_PL_FAVORITES && plist != SYS_PL_HIDDEN)
|
if (plist != SYS_PL_FAVORITES && plist != SYS_PL_HIDDEN &&
|
||||||
|
plist != SYS_PL_HISTORY)
|
||||||
idle_schedule(IDLE_SYNC, IDLE_FUNC(__sys_pl_update),
|
idle_schedule(IDLE_SYNC, IDLE_FUNC(__sys_pl_update),
|
||||||
GUINT_TO_POINTER(plist));
|
GUINT_TO_POINTER(plist));
|
||||||
}
|
}
|
||||||
|
@ -226,6 +235,8 @@ static void pl_system_set_flag(const gchar *name, enum queue_flags flag,
|
||||||
bool enabled)
|
bool enabled)
|
||||||
{
|
{
|
||||||
enum sys_playlist_t plist = __sys_pl_convert(name);
|
enum sys_playlist_t plist = __sys_pl_convert(name);
|
||||||
|
if (plist == SYS_PL_HISTORY || plist == SYS_PL_NUM_PLAYLISTS)
|
||||||
|
return;
|
||||||
if (enabled)
|
if (enabled)
|
||||||
queue_set_flag(__sys_pl_queue(plist), flag);
|
queue_set_flag(__sys_pl_queue(plist), flag);
|
||||||
else
|
else
|
||||||
|
@ -261,9 +272,12 @@ void pl_system_init(struct queue_ops *ops)
|
||||||
|
|
||||||
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) {
|
||||||
queue_init(__sys_pl_queue(i), Q_ENABLED | Q_REPEAT, ops, &sys_playlists[i]);
|
queue_init(__sys_pl_queue(i), Q_ENABLED | Q_REPEAT, ops, &sys_playlists[i]);
|
||||||
queue_sort(__sys_pl_queue(i), COMPARE_ARTIST, true);
|
if (i != SYS_PL_HISTORY) {
|
||||||
queue_sort(__sys_pl_queue(i), COMPARE_YEAR, false);
|
queue_sort(__sys_pl_queue(i), COMPARE_ARTIST, true);
|
||||||
queue_sort(__sys_pl_queue(i), COMPARE_TRACK, false);
|
queue_sort(__sys_pl_queue(i), COMPARE_YEAR, false);
|
||||||
|
queue_sort(__sys_pl_queue(i), COMPARE_TRACK, false);
|
||||||
|
} else
|
||||||
|
queue_set_flag(__sys_pl_queue(i), Q_NO_SORT);
|
||||||
if (i >= SYS_PL_COLLECTION)
|
if (i >= SYS_PL_COLLECTION)
|
||||||
queue_set_flag(__sys_pl_queue(i), Q_ADD_FRONT);
|
queue_set_flag(__sys_pl_queue(i), Q_ADD_FRONT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ enum sys_playlist_t {
|
||||||
SYS_PL_FAVORITES, /* Songs that the user likes. */
|
SYS_PL_FAVORITES, /* Songs that the user likes. */
|
||||||
SYS_PL_HIDDEN, /* Songs that the user has hidden. */
|
SYS_PL_HIDDEN, /* Songs that the user has hidden. */
|
||||||
SYS_PL_COLLECTION, /* Songs that have not been hidden. */
|
SYS_PL_COLLECTION, /* Songs that have not been hidden. */
|
||||||
|
SYS_PL_HISTORY, /* Songs that have just been played. */
|
||||||
SYS_PL_UNPLAYED, /* Songs that have not been played yet. */
|
SYS_PL_UNPLAYED, /* Songs that have not been played yet. */
|
||||||
SYS_PL_MOST_PLAYED, /* Songs with an above average play count. */
|
SYS_PL_MOST_PLAYED, /* Songs with an above average play count. */
|
||||||
SYS_PL_LEAST_PLAYED, /* Songs with a below average play count. */
|
SYS_PL_LEAST_PLAYED, /* Songs with a below average play count. */
|
||||||
|
|
|
@ -130,6 +130,36 @@ static void test_collection()
|
||||||
__test_playlist_unhide_track("Collection", queue, 2, true, true);
|
__test_playlist_unhide_track("Collection", queue, 2, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_history()
|
||||||
|
{
|
||||||
|
struct queue *queue = pl_system.pl_get_queue("History");
|
||||||
|
|
||||||
|
test_not_equal((void *)queue, NULL);
|
||||||
|
test_equal(queue_has_flag(queue, Q_ADD_FRONT), (bool)true);
|
||||||
|
test_equal(queue_has_flag(queue, Q_NO_SORT), (bool)true);
|
||||||
|
|
||||||
|
test_equal(queue_has_flag(queue, Q_RANDOM), (bool)false);
|
||||||
|
pl_system.pl_set_flag("History", Q_RANDOM, true);
|
||||||
|
test_equal(queue_has_flag(queue, Q_RANDOM), (bool)false);
|
||||||
|
|
||||||
|
__test_playlist_state(queue, 0, false, false);
|
||||||
|
test_equal(pl_system.pl_add_track("History", track_get(0)), (bool)true);
|
||||||
|
test_equal(pl_system.pl_add_track("History", track_get(0)), (bool)true);
|
||||||
|
test_equal(pl_system.pl_add_track("History", track_get(1)), (bool)true);
|
||||||
|
test_equal(pl_system.pl_add_track("History", track_get(1)), (bool)true);
|
||||||
|
__test_playlist_state(queue, 4, true, true);
|
||||||
|
|
||||||
|
test_equal((void *)queue_next(queue), (void *)track_get(1));
|
||||||
|
test_equal((void *)queue_next(queue), (void *)track_get(0));
|
||||||
|
test_equal(queue_size(queue), 4);
|
||||||
|
test_equal(pl_system.pl_add_track("History", track_get(1)), (bool)true);
|
||||||
|
test_equal(queue_size(queue), 5);
|
||||||
|
test_equal((void *)queue_next(queue), (void *)track_get(1));
|
||||||
|
|
||||||
|
__test_playlist_remove("History", queue);
|
||||||
|
__test_playlist_update("History", queue, 0, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_unplayed()
|
static void test_unplayed()
|
||||||
{
|
{
|
||||||
struct queue *queue = pl_system.pl_get_queue("Unplayed");
|
struct queue *queue = pl_system.pl_get_queue("Unplayed");
|
||||||
|
@ -242,6 +272,7 @@ DECLARE_UNIT_TESTS(
|
||||||
UNIT_TEST("Favorites Playlist", test_favorites),
|
UNIT_TEST("Favorites Playlist", test_favorites),
|
||||||
UNIT_TEST("Hidden Playlist", test_hidden),
|
UNIT_TEST("Hidden Playlist", test_hidden),
|
||||||
UNIT_TEST("Collection Playlist", test_collection),
|
UNIT_TEST("Collection Playlist", test_collection),
|
||||||
|
UNIT_TEST("History Playlist", test_history),
|
||||||
UNIT_TEST("Unplayed Tracks Playlist", test_unplayed),
|
UNIT_TEST("Unplayed Tracks Playlist", test_unplayed),
|
||||||
UNIT_TEST("Most Played Tracks Playlist", test_most_played),
|
UNIT_TEST("Most Played Tracks Playlist", test_most_played),
|
||||||
UNIT_TEST("Least Played Tracks Playlist", test_least_played),
|
UNIT_TEST("Least Played Tracks Playlist", test_least_played),
|
||||||
|
|
Loading…
Reference in New Issue