diff --git a/core/playlist.c b/core/playlist.c index e7164c91..d3930b59 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -188,11 +188,6 @@ bool playlist_remove(struct playlist *playlist, struct track *track) return ret; } -unsigned int playlist_size(struct playlist *playlist) -{ - return playlist ? queue_size(&playlist->pl_queue) : 0; -} - void playlist_set_random(struct playlist *playlist, bool enabled) { if (playlist && playlist->pl_ops->pl_set_random) { diff --git a/core/playlists/generic.c b/core/playlists/generic.c index 85cf22c3..bc9780eb 100644 --- a/core/playlists/generic.c +++ b/core/playlists/generic.c @@ -73,7 +73,7 @@ void playlist_generic_save(struct playlist *playlist, struct file *file, } if (flags & PL_SAVE_TRACKS) { - file_writef(file, "%u", queue_size(&playlist->pl_queue)); + file_writef(file, "%u", playlist_size(playlist)); queue_for_each(&playlist->pl_queue, &it) file_writef(file, " %u", track_index(queue_iter_val(&it))); file_writef(file, "\n"); @@ -127,7 +127,7 @@ void playlist_generic_load(struct playlist *playlist, struct file *file, bool playlist_generic_can_select(struct playlist *playlist) { - return queue_size(&playlist->pl_queue) > 0; + return playlist_size(playlist) > 0; } void playlist_generic_clear(struct playlist *playlist) @@ -137,7 +137,7 @@ void playlist_generic_clear(struct playlist *playlist) if (!playlist) return; - n = queue_size(&playlist->pl_queue); + n = playlist_size(playlist); g_queue_clear(&playlist->pl_queue.q_tracks); playlist->pl_queue.q_length = 0; playlist->pl_queue.q_cur.it_iter = NULL; @@ -226,12 +226,12 @@ void playlist_generic_resort(struct playlist *playlist) struct track *playlist_generic_next(struct playlist *playlist) { - unsigned int pos, size = playlist ? queue_size(&playlist->pl_queue) : 0; + unsigned int pos, size = playlist_size(playlist); if (size == 0) return NULL; else if (playlist->pl_random) { - pos = g_random_int_range(1, queue_size(&playlist->pl_queue)); + pos = g_random_int_range(1, size); pos += playlist->pl_queue.q_cur.it_pos; queue_iter_set(&playlist->pl_queue, &playlist->pl_queue.q_cur, pos % size); diff --git a/core/playlists/system.c b/core/playlists/system.c index c4622103..b8bbd080 100644 --- a/core/playlists/system.c +++ b/core/playlists/system.c @@ -116,7 +116,7 @@ static bool sys_pl_hidden_clear(struct playlist *playlist) { struct track *track; - while (queue_size(&playlist->pl_queue) > 0) { + while (playlist_size(playlist) > 0) { track = queue_at(&playlist->pl_queue, 0); sys_pl_hidden_remove(playlist, track); } diff --git a/core/queue.c b/core/queue.c index eb5ba22a..36338ebe 100644 --- a/core/queue.c +++ b/core/queue.c @@ -55,7 +55,7 @@ static inline unsigned int __queue_add_tail(struct queue *queue, struct track *track) { g_queue_push_tail(&queue->q_tracks, track); - return __queue_added(queue, track, queue_size(queue) - 1); + return __queue_added(queue, track, g_queue_get_length(&queue->q_tracks) - 1); } static inline unsigned int __queue_add_sorted(struct queue *queue, diff --git a/gui/model.c b/gui/model.c index 52320fd0..0765f507 100644 --- a/gui/model.c +++ b/gui/model.c @@ -148,7 +148,7 @@ static gint __gui_model_iter_n_children(GtkTreeModel *model, GtkTreeIter *iter) { if (iter != NULL || !cur_playlist) return 0; - return queue_size(&cur_playlist->pl_queue); + return playlist_size(cur_playlist); } static gboolean __gui_model_iter_nth_child(GtkTreeModel *model, @@ -158,7 +158,7 @@ static gboolean __gui_model_iter_nth_child(GtkTreeModel *model, { struct queue *queue = &cur_playlist->pl_queue; - if (parent || !cur_playlist || n >= queue_size(queue)) + if (parent || !cur_playlist || n >= playlist_size(cur_playlist)) return FALSE; iter->stamp = gui_model->gm_stamp; @@ -322,13 +322,12 @@ void gui_model_update(struct playlist *playlist, struct track *track) void gui_model_set_playlist(struct playlist *playlist) { if (cur_playlist) - gui_model_remove(cur_playlist, NULL, - queue_size(&cur_playlist->pl_queue)); + gui_model_remove(cur_playlist, NULL, playlist_size(cur_playlist)); cur_playlist = playlist; __gui_model_set_runtime(); - if (playlist && queue_size(&playlist->pl_queue) > 0) + if (playlist && playlist_size(playlist) > 0) gui_model_add(playlist, 0); } diff --git a/include/core/playlist.h b/include/core/playlist.h index fe232214..65ddef3f 100644 --- a/include/core/playlist.h +++ b/include/core/playlist.h @@ -63,9 +63,6 @@ bool playlist_remove(struct playlist *, struct track *); /* Called to check if a specific track is in the playlist. */ bool playlist_has(struct playlist *, struct track *); -/* Called to find the number of tracks in the playlist. */ -unsigned int playlist_size(struct playlist *); - /* Called to set the playlist's random flag. */ void playlist_set_random(struct playlist *, bool); diff --git a/include/core/playlists/playlist.h b/include/core/playlists/playlist.h index 49ca6af8..c058d553 100644 --- a/include/core/playlists/playlist.h +++ b/include/core/playlists/playlist.h @@ -89,6 +89,12 @@ static inline bool playlist_has(struct playlist *playlist, struct track *track) false; } +/* Called to find the size of a playlist. */ +static inline unsigned int playlist_size(struct playlist *playlist) +{ + return playlist ? g_queue_get_length(&playlist->pl_queue.q_tracks) : 0; +} + /* Called to clear the sort order of the playlist. */ static inline void playlist_clear_sort(struct playlist *playlist) { diff --git a/include/core/queue.h b/include/core/queue.h index be657837..e1510730 100644 --- a/include/core/queue.h +++ b/include/core/queue.h @@ -91,12 +91,6 @@ void queue_init(struct queue *, const struct queue_ops *, void *); void queue_deinit(struct queue *); -/* Called to find the size of the queue. */ -static inline unsigned int queue_size(struct queue *queue) -{ - return g_queue_get_length(&queue->q_tracks); -} - /* Called to access the queued track at a given index. */ static inline struct track *queue_at(struct queue *queue, unsigned int index) { diff --git a/tests/core/playlist.c b/tests/core/playlist.c index 86f3218a..ac8eced5 100644 --- a/tests/core/playlist.c +++ b/tests/core/playlist.c @@ -81,13 +81,16 @@ static void test_playlist() unsigned int ex_length = 0; unsigned int i; + g_assert_cmpuint(playlist_size(&p), ==, 0); playlist_generic_init(&p, NULL); + g_assert_cmpuint(playlist_size(&p), ==, 0); for (i = 0; i < 13; i++) { ex_length += track_get(i)->tr_length; playlist_generic_add_front(&p, track_get(i)); g_assert_true(playlist_has(&p, track_get(i))); g_assert_cmpuint(p.pl_queue.q_length, ==, ex_length); + g_assert_cmpuint(playlist_size(&p), ==, i + 1); g_assert(cb_playlist == &p); g_assert(cb_track == track_get(i)); } @@ -111,8 +114,9 @@ static void test_playlist() g_assert_false(playlist_has(&p, track_get(i))); g_assert(cb_playlist == &p); g_assert(cb_track == track_get(i)); - g_assert_cmpuint(p.pl_queue.q_length, ==, ex_length); + g_assert_cmpuint(p.pl_queue.q_length, ==, ex_length); g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, (11 - i)); + g_assert_cmpuint(playlist_size(&p), ==, (12 - i)); if (i < 12) g_assert_nonnull(p.pl_queue.q_cur.it_iter); } @@ -282,7 +286,7 @@ static void test_save_load() g_assert_cmpuint(s.pl_queue.q_cur.it_pos, ==, 4); g_assert(queue_iter_val(&s.pl_queue.q_cur) == queue_at(&q.pl_queue, 4)); g_assert_cmpuint(g_slist_length(s.pl_queue.q_sort), ==, 0); - g_assert_cmpuint(g_queue_get_length(&s.pl_queue.q_tracks), ==, 13); + g_assert_cmpuint(playlist_size(&s), ==, 13); } int main(int argc, char **argv) diff --git a/tests/core/queue.c b/tests/core/queue.c index 9157345f..18cb54cf 100644 --- a/tests/core/queue.c +++ b/tests/core/queue.c @@ -75,7 +75,6 @@ static void test_queue(gconstpointer arg) { unsigned int N = GPOINTER_TO_UINT(arg); unsigned int ex_length = 0; - unsigned int ex_size = N; struct queue_iter it; struct track *track; unsigned int i; @@ -93,7 +92,6 @@ static void test_queue(gconstpointer arg) g_assert_cmpuint(count_added, ==, i + 1); } g_assert_cmpuint(q.q_length, ==, ex_length); - g_assert_cmpuint(queue_size(&q), ==, ex_size); /* queue_iter_init() */ if (N > 0) { @@ -110,7 +108,6 @@ static void test_queue(gconstpointer arg) i++; } g_assert_cmpuint(i, ==, N); - g_assert_cmpuint(queue_size(&q), ==, ex_size); queue_deinit(&q); g_assert_null(q.q_sort);