core/playlist: Move playlist length into the playlist struct
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
fda29aaf13
commit
0c197c10f9
|
@ -49,8 +49,10 @@ void playlist_generic_init(struct playlist *playlist, struct queue_ops *ops)
|
||||||
|
|
||||||
void playlist_generic_deinit(struct playlist *playlist)
|
void playlist_generic_deinit(struct playlist *playlist)
|
||||||
{
|
{
|
||||||
if (playlist)
|
if (playlist) {
|
||||||
queue_deinit(&playlist->pl_queue);
|
queue_deinit(&playlist->pl_queue);
|
||||||
|
playlist->pl_length = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void playlist_generic_save(struct playlist *playlist, struct file *file,
|
void playlist_generic_save(struct playlist *playlist, struct file *file,
|
||||||
|
@ -145,7 +147,7 @@ void playlist_generic_clear(struct playlist *playlist)
|
||||||
|
|
||||||
n = playlist_size(playlist);
|
n = playlist_size(playlist);
|
||||||
g_queue_clear(&playlist->pl_queue.q_tracks);
|
g_queue_clear(&playlist->pl_queue.q_tracks);
|
||||||
playlist->pl_queue.q_length = 0;
|
playlist->pl_length = 0;
|
||||||
playlist->pl_queue.q_cur.it_iter = NULL;
|
playlist->pl_queue.q_cur.it_iter = NULL;
|
||||||
playlist->pl_queue.q_cur.it_pos = UINT_MAX;
|
playlist->pl_queue.q_cur.it_pos = UINT_MAX;
|
||||||
if (callbacks)
|
if (callbacks)
|
||||||
|
@ -157,7 +159,7 @@ bool playlist_generic_add(struct playlist *playlist, struct track *track)
|
||||||
if (!playlist || !track || playlist_has(playlist, track))
|
if (!playlist || !track || playlist_has(playlist, track))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
playlist->pl_queue.q_length += track->tr_length;
|
playlist->pl_length += track->tr_length;
|
||||||
if (playlist->pl_queue.q_sort) {
|
if (playlist->pl_queue.q_sort) {
|
||||||
g_queue_insert_sorted(&playlist->pl_queue.q_tracks, track,
|
g_queue_insert_sorted(&playlist->pl_queue.q_tracks, track,
|
||||||
__playlist_generic_less_than,
|
__playlist_generic_less_than,
|
||||||
|
@ -178,7 +180,7 @@ bool playlist_generic_add_front(struct playlist *playlist, struct track *track)
|
||||||
if (!playlist || !track)
|
if (!playlist || !track)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
playlist->pl_queue.q_length += track->tr_length;
|
playlist->pl_length += track->tr_length;
|
||||||
g_queue_push_head(&playlist->pl_queue.q_tracks, track);
|
g_queue_push_head(&playlist->pl_queue.q_tracks, track);
|
||||||
if (callbacks)
|
if (callbacks)
|
||||||
callbacks->pl_cb_added(playlist, track);
|
callbacks->pl_cb_added(playlist, track);
|
||||||
|
@ -196,7 +198,7 @@ bool playlist_generic_remove(struct playlist *playlist, struct track *track)
|
||||||
queue_iter_prev(&playlist->pl_queue.q_cur);
|
queue_iter_prev(&playlist->pl_queue.q_cur);
|
||||||
|
|
||||||
count = g_queue_remove_all(&playlist->pl_queue.q_tracks, track);
|
count = g_queue_remove_all(&playlist->pl_queue.q_tracks, track);
|
||||||
playlist->pl_queue.q_length -= (count * track->tr_length);
|
playlist->pl_length -= (count * track->tr_length);
|
||||||
playlist->pl_queue.q_cur.it_pos = g_queue_link_index(
|
playlist->pl_queue.q_cur.it_pos = g_queue_link_index(
|
||||||
&playlist->pl_queue.q_tracks,
|
&playlist->pl_queue.q_tracks,
|
||||||
playlist->pl_queue.q_cur.it_iter);
|
playlist->pl_queue.q_cur.it_iter);
|
||||||
|
|
|
@ -21,7 +21,6 @@ static inline void __queue_deinit(struct queue *queue)
|
||||||
|
|
||||||
void queue_init(struct queue *queue, const struct queue_ops *ops, void *data)
|
void queue_init(struct queue *queue, const struct queue_ops *ops, void *data)
|
||||||
{
|
{
|
||||||
queue->q_length = 0;
|
|
||||||
queue->q_sort = NULL;
|
queue->q_sort = NULL;
|
||||||
queue->q_ops = ops;
|
queue->q_ops = ops;
|
||||||
|
|
||||||
|
@ -37,7 +36,6 @@ void queue_deinit(struct queue *queue)
|
||||||
__queue_deinit(queue);
|
__queue_deinit(queue);
|
||||||
g_slist_free(queue->q_sort);
|
g_slist_free(queue->q_sort);
|
||||||
queue->q_sort = NULL;
|
queue->q_sort = NULL;
|
||||||
queue->q_length = 0;
|
|
||||||
queue->q_cur.it_pos = UINT_MAX;
|
queue->q_cur.it_pos = UINT_MAX;
|
||||||
queue->q_cur.it_iter = NULL;
|
queue->q_cur.it_iter = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ static void __gui_model_set_runtime(void)
|
||||||
gchar *len = NULL;
|
gchar *len = NULL;
|
||||||
|
|
||||||
if (cur_playlist)
|
if (cur_playlist)
|
||||||
len = string_sec2str_long(cur_playlist->pl_queue.q_length);
|
len = string_sec2str_long(cur_playlist->pl_length);
|
||||||
|
|
||||||
gtk_label_set_text(gui_model_runtime(), len);
|
gtk_label_set_text(gui_model_runtime(), len);
|
||||||
g_free(len);
|
g_free(len);
|
||||||
|
|
|
@ -47,9 +47,10 @@ struct playlist {
|
||||||
gchar *pl_name; /* This playlist's name. */
|
gchar *pl_name; /* This playlist's name. */
|
||||||
unsigned int pl_id; /* This playlist's identifier. */
|
unsigned int pl_id; /* This playlist's identifier. */
|
||||||
|
|
||||||
bool pl_random; /* This playlist's random setting. */
|
unsigned int pl_length; /* This playlist's length, in seconds. */
|
||||||
void *pl_private; /* This playlist's private data. */
|
bool pl_random; /* This playlist's random setting. */
|
||||||
struct queue pl_queue; /* This playlist's queue of tracks. */
|
void *pl_private; /* This playlist's private data. */
|
||||||
|
struct queue pl_queue; /* This playlist's queue of tracks. */
|
||||||
|
|
||||||
const struct playlist_ops *pl_ops; /* This playlist's supported operations. */
|
const struct playlist_ops *pl_ops; /* This playlist's supported operations. */
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,6 @@ struct queue_iter {
|
||||||
|
|
||||||
|
|
||||||
struct queue {
|
struct queue {
|
||||||
unsigned int q_length; /* The queue's total runtime (in seconds). */
|
|
||||||
GQueue q_tracks; /* The queue's list of tracks. */
|
GQueue q_tracks; /* The queue's list of tracks. */
|
||||||
GSList *q_sort; /* The queue's sort order. */
|
GSList *q_sort; /* The queue's sort order. */
|
||||||
void *q_private; /* The queue's private data. */
|
void *q_private; /* The queue's private data. */
|
||||||
|
|
|
@ -88,13 +88,14 @@ static void test_playlist()
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||||
playlist_generic_init(&p, NULL);
|
playlist_generic_init(&p, NULL);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||||
|
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||||
|
|
||||||
for (i = 0; i < 13; i++) {
|
for (i = 0; i < 13; i++) {
|
||||||
ex_length += track_get(i)->tr_length;
|
ex_length += track_get(i)->tr_length;
|
||||||
playlist_generic_add_front(&p, track_get(i));
|
playlist_generic_add_front(&p, track_get(i));
|
||||||
g_assert_true(playlist_has(&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(p.pl_length, ==, ex_length);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, i + 1);
|
g_assert_cmpuint(playlist_size(&p), ==, i + 1);
|
||||||
g_assert(cb_playlist == &p);
|
g_assert(cb_playlist == &p);
|
||||||
g_assert(cb_track == track_get(i));
|
g_assert(cb_track == track_get(i));
|
||||||
}
|
}
|
||||||
|
@ -118,7 +119,7 @@ static void test_playlist()
|
||||||
g_assert_false(playlist_has(&p, track_get(i)));
|
g_assert_false(playlist_has(&p, track_get(i)));
|
||||||
g_assert(cb_playlist == &p);
|
g_assert(cb_playlist == &p);
|
||||||
g_assert(cb_track == track_get(i));
|
g_assert(cb_track == track_get(i));
|
||||||
g_assert_cmpuint(p.pl_queue.q_length, ==, ex_length);
|
g_assert_cmpuint(p.pl_length, ==, ex_length);
|
||||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, (11 - i));
|
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, (11 - i));
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, (12 - i));
|
g_assert_cmpuint(playlist_size(&p), ==, (12 - i));
|
||||||
if (i < 12)
|
if (i < 12)
|
||||||
|
@ -128,7 +129,7 @@ static void test_playlist()
|
||||||
g_assert_false(playlist_has(&p, track_get(i)));
|
g_assert_false(playlist_has(&p, track_get(i)));
|
||||||
g_assert(cb_playlist == &p);
|
g_assert(cb_playlist == &p);
|
||||||
g_assert(cb_track == track_get(12));
|
g_assert(cb_track == track_get(12));
|
||||||
g_assert_cmpuint(p.pl_queue.q_length, ==, ex_length);
|
g_assert_cmpuint(p.pl_length, ==, ex_length);
|
||||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||||
|
|
||||||
|
@ -138,26 +139,26 @@ static void test_playlist()
|
||||||
g_assert_true( playlist_add(&p, track_get(i)));
|
g_assert_true( playlist_add(&p, track_get(i)));
|
||||||
g_assert_false(playlist_add(&p, track_get(i)));
|
g_assert_false(playlist_add(&p, track_get(i)));
|
||||||
g_assert_true(playlist_has(&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(p.pl_length, ==, ex_length);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, i + 1);
|
g_assert_cmpuint(playlist_size(&p), ==, i + 1);
|
||||||
g_assert(cb_playlist == &p);
|
g_assert(cb_playlist == &p);
|
||||||
g_assert(cb_track == track_get(i));
|
g_assert(cb_track == track_get(i));
|
||||||
}
|
}
|
||||||
g_assert_false(playlist_generic_add(&p, NULL));
|
g_assert_false(playlist_generic_add(&p, NULL));
|
||||||
g_assert_cmpuint(p.pl_queue.q_length, ==, ex_length);
|
g_assert_cmpuint(p.pl_length, ==, ex_length);
|
||||||
|
|
||||||
/* Now clear the playlist. */
|
/* Now clear the playlist. */
|
||||||
queue_iter_set(&p.pl_queue, &p.pl_queue.q_cur, 12);
|
queue_iter_set(&p.pl_queue, &p.pl_queue.q_cur, 12);
|
||||||
playlist_generic_clear(&p);
|
playlist_generic_clear(&p);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||||
|
|
||||||
/* Deinitialize the playlist. */
|
/* Deinitialize the playlist. */
|
||||||
playlist_generic_deinit(&p);
|
playlist_generic_deinit(&p);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||||
g_assert_null(p.pl_queue.q_sort);
|
g_assert_null(p.pl_queue.q_sort);
|
||||||
|
@ -241,7 +242,7 @@ static void test_sorting()
|
||||||
/* Deinitialize the playlist. */
|
/* Deinitialize the playlist. */
|
||||||
playlist_generic_deinit(&p);
|
playlist_generic_deinit(&p);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||||
g_assert_null(p.pl_queue.q_sort);
|
g_assert_null(p.pl_queue.q_sort);
|
||||||
|
@ -287,7 +288,7 @@ static void test_next()
|
||||||
/* Deinitialize the playlist. */
|
/* Deinitialize the playlist. */
|
||||||
playlist_generic_deinit(&p);
|
playlist_generic_deinit(&p);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||||
g_assert_null(p.pl_queue.q_sort);
|
g_assert_null(p.pl_queue.q_sort);
|
||||||
|
@ -339,7 +340,7 @@ static void test_save_load()
|
||||||
/* Deinitialize the playlist. */
|
/* Deinitialize the playlist. */
|
||||||
playlist_generic_deinit(&p);
|
playlist_generic_deinit(&p);
|
||||||
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
g_assert_cmpuint(playlist_size(&p), ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_length, ==, 0);
|
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||||
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
g_assert_cmpuint(p.pl_queue.q_cur.it_pos, ==, UINT_MAX);
|
||||||
g_assert_null(p.pl_queue.q_cur.it_iter);
|
g_assert_null(p.pl_queue.q_cur.it_iter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ static void test_init()
|
||||||
g_assert_null(q.q_private);
|
g_assert_null(q.q_private);
|
||||||
|
|
||||||
g_assert_cmpuint(q.q_cur.it_pos, ==, (unsigned int)-1);
|
g_assert_cmpuint(q.q_cur.it_pos, ==, (unsigned int)-1);
|
||||||
g_assert_cmpuint(q.q_length, ==, 0);
|
|
||||||
g_assert_null(q.q_sort);
|
g_assert_null(q.q_sort);
|
||||||
g_assert_null(q.q_ops);
|
g_assert_null(q.q_ops);
|
||||||
|
|
||||||
|
@ -56,7 +55,6 @@ static void test_init()
|
||||||
g_assert_cmpuint(GPOINTER_TO_UINT(q.q_private), ==, 1);
|
g_assert_cmpuint(GPOINTER_TO_UINT(q.q_private), ==, 1);
|
||||||
|
|
||||||
g_assert_cmpuint(q.q_cur.it_pos, ==, (unsigned int)-1);
|
g_assert_cmpuint(q.q_cur.it_pos, ==, (unsigned int)-1);
|
||||||
g_assert_cmpuint(q.q_length, ==, 0);
|
|
||||||
g_assert_null(q.q_sort);
|
g_assert_null(q.q_sort);
|
||||||
g_assert(q.q_ops == &test_ops);
|
g_assert(q.q_ops == &test_ops);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue