diff --git a/core/playlists/library.c b/core/playlists/library.c index f4e1e67e..b5e18be1 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -14,6 +14,9 @@ static struct playlist *__lib_pl_alloc(const gchar *path) playlist->pl_name = path; playlist->pl_type = PL_LIBRARY; queue_init(&playlist->pl_queue, Q_ENABLED | Q_REPEAT, lib_ops, playlist); + queue_sort(&playlist->pl_queue, COMPARE_ARTIST, true); + queue_sort(&playlist->pl_queue, COMPARE_YEAR, false); + queue_sort(&playlist->pl_queue, COMPARE_TRACK, false); return playlist; } @@ -71,12 +74,19 @@ static void pl_library_set_flag(const gchar *name, enum queue_flags flag, queue_unset_flag(&playlist->pl_queue, flag); } +static void pl_library_sort(const gchar *name, enum compare_t sort, bool reset) +{ + struct playlist *playlist = __lib_pl_lookup(name); + queue_sort(&playlist->pl_queue, sort, reset); +} + struct playlist_type pl_library = { .pl_get_queue = pl_library_get_queue, .pl_add_track = pl_library_add_rm, .pl_remove_track = pl_library_add_rm, .pl_set_flag = pl_library_set_flag, + .pl_sort = pl_library_sort, }; diff --git a/tests/core/playlists/library.c b/tests/core/playlists/library.c index 68abc27b..a8135e00 100644 --- a/tests/core/playlists/library.c +++ b/tests/core/playlists/library.c @@ -51,6 +51,14 @@ void test_library() pl_library.pl_set_flag("tests/Music", Q_RANDOM, false); test_equal(queue_has_flag(&playlist->pl_queue, Q_RANDOM), (bool)false); + test_equal(g_slist_length(playlist->pl_queue.q_sort), 3); + pl_library.pl_sort("tests/Music", COMPARE_ARTIST, true); + test_equal(g_slist_length(playlist->pl_queue.q_sort), 1); + pl_library.pl_sort("tests/Music", COMPARE_YEAR, false); + test_equal(g_slist_length(playlist->pl_queue.q_sort), 2); + pl_library.pl_sort("tests/Music", COMPARE_TRACK, false); + test_equal(g_slist_length(playlist->pl_queue.q_sort), 3); + pl_library_deinit(); test_equal(library->li_playlist, NULL);