From a33decf549f36485e66024f869ad014056add33b Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 13 Sep 2016 10:08:00 -0400 Subject: [PATCH] core/queue: Remove Q_REPEAT flag It is unused now that the queued tracks playlist manually removes tracks when picked. Signed-off-by: Anna Schumaker --- core/playlists/artist.c | 2 +- core/playlists/library.c | 2 +- core/playlists/system.c | 11 +++-- core/playlists/user.c | 2 +- core/queue.c | 7 +--- include/core/queue.h | 16 ++++---- tests/core/playlists/system.c | 1 - tests/core/queue.c | 76 +++++------------------------------ 8 files changed, 29 insertions(+), 88 deletions(-) diff --git a/core/playlists/artist.c b/core/playlists/artist.c index 8b25696b..40b28a6b 100644 --- a/core/playlists/artist.c +++ b/core/playlists/artist.c @@ -24,7 +24,7 @@ static struct playlist *__artist_pl_alloc(struct artist *artist) playlist->pl_type = PL_ARTIST; playlist->pl_id = artist_index(artist); playlist->pl_ops = &pl_artist_ops; - playlist_generic_init(playlist, Q_REPEAT, artist_ops); + playlist_generic_init(playlist, 0, artist_ops); return playlist; } diff --git a/core/playlists/library.c b/core/playlists/library.c index fec9eb82..45475737 100644 --- a/core/playlists/library.c +++ b/core/playlists/library.c @@ -28,7 +28,7 @@ static struct playlist *__lib_pl_alloc(struct library *library) playlist->pl_type = PL_LIBRARY; playlist->pl_id = library_index(library); playlist->pl_ops = &pl_library_ops; - playlist_generic_init(playlist, Q_REPEAT, lib_ops); + playlist_generic_init(playlist, 0, lib_ops); return playlist; } diff --git a/core/playlists/system.c b/core/playlists/system.c index 67c3aff6..936079ce 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -30,7 +30,7 @@ static bool sys_pl_delete_clear(struct playlist *playlist) static void sys_pl_generic_init(struct playlist *playlist, unsigned int flags, struct queue_ops *ops) { - playlist_generic_init(playlist, Q_REPEAT, ops); + playlist_generic_init(playlist, 0, ops); } static void sys_pl_update_init(struct playlist *playlist, unsigned int flags, @@ -55,7 +55,6 @@ static void sys_pl_save_full(struct playlist *playlist, struct file *file) static void sys_pl_load_partial(struct playlist *playlist, struct file *file) { queue_load_flags(&playlist->pl_queue, file, true); - queue_set_flag(&playlist->pl_queue, Q_REPEAT); } static void sys_pl_load_full(struct playlist *playlist, struct file *file) @@ -169,7 +168,7 @@ static bool sys_pl_queued_load() file_readf(&sys_deck_f, "%u", &num); for (i = 0; i < num; i++) { file_readf(&sys_deck_f, "%u", &flags); - flags &= Q_UNUSED_MASK; + flags &= Q_VALID_FLAGS; if (i == 0) queue->q_flags |= flags; queue_load_tracks(queue, &sys_deck_f); @@ -183,7 +182,7 @@ static bool sys_pl_queued_load() static void sys_pl_queued_init(struct playlist *playlist, unsigned int flags, struct queue_ops *ops) { - queue_init(&playlist->pl_queue, Q_REPEAT, ops, playlist); + queue_init(&playlist->pl_queue, 0, ops, playlist); } static struct track *sys_pl_queued_next(struct playlist *playlist) @@ -261,7 +260,7 @@ static struct sys_playlist sys_collection = { static void sys_pl_history_init(struct playlist *playlist, unsigned int flags, struct queue_ops *ops) { - queue_init(&playlist->pl_queue, Q_REPEAT, ops, playlist); + queue_init(&playlist->pl_queue, 0, ops, playlist); } static bool sys_pl_history_add(struct playlist *playlist, struct track *track) @@ -526,7 +525,7 @@ void pl_system_init(struct queue_ops *ops) for (i = 0; i < SYS_PL_NUM_PLAYLISTS; i++) { sys_pl = sys_playlists[i]; - sys_pl->spl_init(&sys_pl->spl_playlist, Q_REPEAT, ops); + sys_pl->spl_init(&sys_pl->spl_playlist, 0, ops); } } diff --git a/core/playlists/user.c b/core/playlists/user.c index b5552efa..817fcede 100644 --- a/core/playlists/user.c +++ b/core/playlists/user.c @@ -16,7 +16,7 @@ static struct user_playlist *__user_db_alloc(gchar *name, unsigned int index) playlist->pl_playlist.pl_type = PL_USER; playlist->pl_playlist.pl_id = index; playlist->pl_playlist.pl_ops = &user_ops; - playlist_generic_init(&playlist->pl_playlist, Q_REPEAT, user_pl_ops); + playlist_generic_init(&playlist->pl_playlist, 0, user_pl_ops); return playlist; } diff --git a/core/queue.c b/core/queue.c index eda16dd4..a3112300 100644 --- a/core/queue.c +++ b/core/queue.c @@ -110,10 +110,7 @@ static inline struct track *__queue_selected(struct queue *queue, unsigned int p { struct track *track = queue_iter_val(&queue->q_cur); - if (queue_has_flag(queue, Q_REPEAT) == false) - __queue_remove(queue, &queue->q_cur); - else - __queue_updated(queue, pos); + __queue_updated(queue, pos); return track; } @@ -184,7 +181,7 @@ void queue_load_flags(struct queue *queue, struct file *file, bool iter) queue_sort(queue, field + 1, false); } - flags &= Q_UNUSED_MASK; + flags &= Q_VALID_FLAGS; queue->q_flags |= flags; queue->q_cur.it_pos = it; diff --git a/include/core/queue.h b/include/core/queue.h index 4361f83f..729fb92d 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -15,16 +15,16 @@ struct queue; enum queue_flags { - Q_UNUSED_0 = (1 << 0), /* Removed: 6.5.4 */ - Q_RANDOM = (1 << 1), /* Queue will pick songs randomly. */ - Q_REPEAT = (1 << 2), /* Queue will not remove songs when picked. */ - Q_UNUSED_3 = (1 << 3), /* Removed: 6.5.4 */ - Q_UNUSED_4 = (1 << 4), /* Removed: 6.5.4 */ - Q_UNUSED_5 = (1 << 5), /* Removed: 6.5.4 */ - Q_UNUSED_6 = (1 << 6), /* Removed: 6.5.4 */ + Q_UNUSED_0 = (1 << 0), /* Removed: 6.5.4 */ + Q_RANDOM = (1 << 1), /* Queue will pick songs randomly. */ + Q_UNUSED_2 = (1 << 2), /* Removed: 6.5.4 */ + Q_UNUSED_3 = (1 << 3), /* Removed: 6.5.4 */ + Q_UNUSED_4 = (1 << 4), /* Removed: 6.5.4 */ + Q_UNUSED_5 = (1 << 5), /* Removed: 6.5.4 */ + Q_UNUSED_6 = (1 << 6), /* Removed: 6.5.4 */ }; -#define Q_UNUSED_MASK (~(Q_UNUSED_0 | Q_UNUSED_3 | Q_UNUSED_4 | Q_UNUSED_5 | Q_UNUSED_6)) +#define Q_VALID_FLAGS (Q_RANDOM) struct queue_ops { diff --git a/tests/core/playlists/system.c b/tests/core/playlists/system.c index 3fa2e9fe..46e01760 100644 --- a/tests/core/playlists/system.c +++ b/tests/core/playlists/system.c @@ -41,7 +41,6 @@ static void test_init() g_assert_cmpuint(playlist->pl_id, ==, i); g_assert_false(playlist_select(playlist)); - g_assert_true(queue_has_flag(&playlist->pl_queue, Q_REPEAT)); if (i == SYS_PL_QUEUED || i == SYS_PL_HISTORY) { g_assert_cmpuint( g_slist_length(playlist->pl_queue.q_sort), ==, 0); diff --git a/tests/core/queue.c b/tests/core/queue.c index 352e0b5a..b324f1f3 100644 --- a/tests/core/queue.c +++ b/tests/core/queue.c @@ -104,19 +104,15 @@ static void test_flags() g_assert_cmpuint(q.q_flags, ==, 0); g_assert_false(queue_has_flag(&q, Q_UNUSED_0)); g_assert_false(queue_has_flag(&q, Q_RANDOM)); - g_assert_false(queue_has_flag(&q, Q_REPEAT)); + g_assert_false(queue_has_flag(&q, Q_UNUSED_2)); g_assert_false(queue_has_flag(&q, Q_UNUSED_3)); g_assert_false(queue_has_flag(&q, Q_UNUSED_4)); g_assert_false(queue_has_flag(&q, Q_UNUSED_5)); g_assert_false(queue_has_flag(&q, Q_UNUSED_6)); queue_set_flag(&q, Q_RANDOM); - queue_set_flag(&q, Q_REPEAT); g_assert_true(queue_has_flag(&q, Q_RANDOM)); - g_assert_true(queue_has_flag(&q, Q_REPEAT)); - queue_unset_flag(&q, Q_RANDOM); - queue_unset_flag(&q, Q_REPEAT); g_assert_cmpuint(q.q_flags, ==, 0); } @@ -194,7 +190,6 @@ static void test_queue(gconstpointer arg) g_assert_cmpuint(count_updated, ==, N / 13); /* Tracks should not be removed. */ - queue_set_flag(&q, Q_REPEAT); for (i = 0; i < ex_size; i++) { g_assert(queue_next(&q) == track_get((i % 11) + 2)); g_assert_cmpuint(count_updated, ==, (N / 13) + (2 * i) + 1); @@ -203,18 +198,6 @@ static void test_queue(gconstpointer arg) g_assert_cmpuint(queue_size(&q), ==, ex_size); } - /* Tracks should be removed. */ - queue_unset_flag(&q, Q_REPEAT); - for (i = 0; i < ex_size / 2; i++) { - track = queue_next(&q); - ex_length -= track->tr_length; - ex_size--; - - g_assert(track == track_get((i % 11) + 2)); - g_assert_cmpuint(queue_size(&q), ==, ex_size); - g_assert_cmpuint(q.q_length, ==, ex_length); - } - queue_clear(&q); g_assert_cmpuint(count_cleared, ==, 1); g_assert_cmpuint(queue_size(&q), ==, 0); @@ -250,62 +233,25 @@ static void test_rand_select() * [val]: The value picked by q.next(). */ - /* rand() = 9, q = { <>, 1, 2, 3, 4, 5, 6, 7, 8, [9], 10, 11, 12, 13 } */ + /* rand() = 10, track = 9 */ g_assert_cmpuint(queue_next(&q)->tr_track, ==, 9); - g_assert_cmpuint(queue_size(&q), ==, 12); - /* select = 6, q = { 1, 2, 3, 4, 5, 6, (7), <8>, 10, 11, 12, 13 } */ + /* select = 6, track = 7 */ g_assert_cmpuint(queue_selected(&q, 6)->tr_track, ==, 7); - g_assert_cmpuint(queue_size(&q), ==, 11); - /* rand() = 10, q = { 1, 2, 3, 4, [5], <6>, 8, 10, 11, 12, 13 } */ - g_assert_cmpuint(queue_next(&q)->tr_track, ==, 5); - g_assert_cmpuint(queue_size(&q), ==, 10); + /* rand() = 4, track = 11 */ + g_assert_cmpuint(queue_next(&q)->tr_track, ==, 11); - /* select = 7, q = { 1, 2, 3, <4>, 6, 8, 10, (11), 12, 13 } */ - g_assert_cmpuint(queue_selected(&q, 7)->tr_track, ==, 11); - g_assert_cmpuint(queue_size(&q), ==, 9); + /* select = 7, track = 8 */ + g_assert_cmpuint(queue_selected(&q, 7)->tr_track, ==, 8); - /* rand() = 6, q = { 1, 2, 3, [4], 6, 8, <10>, 12, 13 } */ - g_assert_cmpuint(queue_next(&q)->tr_track, ==, 4); - g_assert_cmpuint(queue_size(&q), ==, 8); - - /* select = 2, q = { 1, 2, (<3>), 6, 8, 10, 12, 13 } */ - g_assert_cmpuint(queue_selected(&q, 2)->tr_track, ==, 3); - g_assert_cmpuint(queue_size(&q), ==, 7); - - /* rand() = 1, q = { 1, <2>, [6], 8, 10, 12, 13 } */ - g_assert_cmpuint(queue_next(&q)->tr_track, ==, 6); - g_assert_cmpuint(queue_size(&q), ==, 6); - - /* select = 1, q = { 1, (<2>), 8, 10, 12, 13 } */ - g_assert_cmpuint(queue_selected(&q, 1)->tr_track, ==, 2); - g_assert_cmpuint(queue_size(&q), ==, 5); - - /* rand() = 4, q = { <1>, 8, 10, 12, [13] } */ - g_assert_cmpuint(queue_next(&q)->tr_track, ==, 13); - g_assert_cmpuint(queue_size(&q), ==, 4); - - /* rand() = 1, q = { [1], 8, 10, <12> } */ + /* rand() = 6, track = 1 */ g_assert_cmpuint(queue_next(&q)->tr_track, ==, 1); - g_assert_cmpuint(queue_size(&q), ==, 3); - /* select = 1, q = { <>, 8, (10), 12 } */ - g_assert_cmpuint(queue_selected(&q, 1)->tr_track, ==, 10); - g_assert_cmpuint(queue_size(&q), ==, 2); - - /* rand() = 1, q = { <8>, [12] } */ - g_assert_cmpuint(queue_next(&q)->tr_track, ==, 12); - g_assert_cmpuint(queue_size(&q), ==, 1); - - /* select = 0, q = { (<8>) } */ - g_assert_cmpuint(queue_selected(&q, 0)->tr_track, ==, 8); - g_assert_cmpuint(queue_size(&q), ==, 0); - - /* q = { } */ - g_assert_null(queue_next(&q)); - g_assert_null(queue_selected(&q, 3)); + /* select = 2, track = 3 */ + g_assert_cmpuint(queue_selected(&q, 2)->tr_track, ==, 3); + g_assert_null(queue_selected(&q, 14)); queue_deinit(&q); }