core/playlist: Move playlist sort order into the playlist struct
Rather than using a variable from the queue layer. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0c197c10f9
commit
f25bdab367
|
@ -205,5 +205,5 @@ bool playlist_sort(struct playlist *playlist, enum compare_t sort)
|
|||
playlist->pl_ops->pl_sort(playlist, sort);
|
||||
if (playlist->pl_type < PL_MAX_TYPE)
|
||||
playlist_types[playlist->pl_type]->pl_save();
|
||||
return g_slist_length(playlist->pl_queue.q_sort) > 0;
|
||||
return g_slist_length(playlist->pl_sort) > 0;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ static int __playlist_generic_less_than(gconstpointer a, gconstpointer b,
|
|||
{
|
||||
struct track *lhs = (struct track *)a;
|
||||
struct track *rhs = (struct track *)b;
|
||||
GSList *cur = (GSList *)data;
|
||||
GSList *cur = ((struct playlist *)data)->pl_sort;
|
||||
int res, field;
|
||||
|
||||
while (cur) {
|
||||
|
@ -41,6 +41,7 @@ void playlist_generic_set_callbacks(struct playlist_callbacks *cb)
|
|||
void playlist_generic_init(struct playlist *playlist, struct queue_ops *ops)
|
||||
{
|
||||
queue_init(&playlist->pl_queue, ops, playlist);
|
||||
playlist->pl_sort = NULL;
|
||||
playlist_generic_sort(playlist, COMPARE_ARTIST);
|
||||
playlist_generic_sort(playlist, COMPARE_YEAR);
|
||||
playlist_generic_sort(playlist, COMPARE_TRACK);
|
||||
|
@ -51,6 +52,7 @@ void playlist_generic_deinit(struct playlist *playlist)
|
|||
{
|
||||
if (playlist) {
|
||||
queue_deinit(&playlist->pl_queue);
|
||||
playlist_clear_sort(playlist);
|
||||
playlist->pl_length = 0;
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +71,7 @@ void playlist_generic_save(struct playlist *playlist, struct file *file,
|
|||
file_writef(file, "%u ", playlist->pl_queue.q_cur.it_pos);
|
||||
|
||||
if (flags & PL_SAVE_FLAGS) {
|
||||
sort = playlist->pl_queue.q_sort;
|
||||
sort = playlist->pl_sort;
|
||||
file_writef(file, "%u ", playlist->pl_random ? PL_RANDOM : 0);
|
||||
file_writef(file, "%u", g_slist_length(sort));
|
||||
while (sort) {
|
||||
|
@ -93,7 +95,6 @@ void playlist_generic_load(struct playlist *playlist, struct file *file,
|
|||
{
|
||||
unsigned int f, n, i, t, it = 0;
|
||||
int field, ascending;
|
||||
GSList *sort = NULL;
|
||||
gchar *line;
|
||||
|
||||
if (!playlist)
|
||||
|
@ -104,15 +105,15 @@ void playlist_generic_load(struct playlist *playlist, struct file *file,
|
|||
|
||||
if (flags & PL_SAVE_FLAGS) {
|
||||
file_readf(file, "%u %u", &f, &n);
|
||||
playlist_clear_sort(playlist);
|
||||
for (i = 0; i < n; i++) {
|
||||
file_readf(file, "%u %d", &field, &ascending);
|
||||
field += 1;
|
||||
if (!ascending)
|
||||
field = -field;
|
||||
sort = g_slist_append(sort, GINT_TO_POINTER(field));
|
||||
playlist->pl_sort = g_slist_append(playlist->pl_sort,
|
||||
GINT_TO_POINTER(field));
|
||||
}
|
||||
playlist_clear_sort(playlist);
|
||||
playlist->pl_queue.q_sort = sort;
|
||||
playlist_generic_resort(playlist);
|
||||
|
||||
if (file_readf(file, "%m\n", &line))
|
||||
|
@ -160,10 +161,9 @@ bool playlist_generic_add(struct playlist *playlist, struct track *track)
|
|||
return false;
|
||||
|
||||
playlist->pl_length += track->tr_length;
|
||||
if (playlist->pl_queue.q_sort) {
|
||||
if (playlist->pl_sort) {
|
||||
g_queue_insert_sorted(&playlist->pl_queue.q_tracks, track,
|
||||
__playlist_generic_less_than,
|
||||
playlist->pl_queue.q_sort);
|
||||
__playlist_generic_less_than, playlist);
|
||||
playlist->pl_queue.q_cur.it_pos = g_queue_link_index(
|
||||
&playlist->pl_queue.q_tracks,
|
||||
playlist->pl_queue.q_cur.it_iter);
|
||||
|
@ -219,28 +219,27 @@ void playlist_generic_set_random(struct playlist *playlist, bool enabled)
|
|||
playlist->pl_random = enabled;
|
||||
}
|
||||
|
||||
void playlist_generic_sort(struct playlist *playlist, enum compare_t sort)
|
||||
void playlist_generic_sort(struct playlist *playlist, enum compare_t field)
|
||||
{
|
||||
GSList *found = g_slist_find_custom(playlist->pl_queue.q_sort,
|
||||
GINT_TO_POINTER(sort),
|
||||
gpointer sort = GINT_TO_POINTER(field);
|
||||
GSList *found = g_slist_find_custom(playlist->pl_sort, sort,
|
||||
__playlist_generic_find_sort);
|
||||
|
||||
if (found)
|
||||
found->data = GINT_TO_POINTER(-GPOINTER_TO_INT(found->data));
|
||||
found->data = GINT_TO_POINTER(-field);
|
||||
else
|
||||
playlist->pl_queue.q_sort = g_slist_append(playlist->pl_queue.q_sort,
|
||||
GINT_TO_POINTER(sort));
|
||||
playlist->pl_sort = g_slist_append(playlist->pl_sort, sort);
|
||||
|
||||
playlist_generic_resort(playlist);
|
||||
}
|
||||
|
||||
void playlist_generic_resort(struct playlist *playlist)
|
||||
{
|
||||
if (!playlist || !playlist->pl_queue.q_sort)
|
||||
if (!playlist || !playlist->pl_sort)
|
||||
return;
|
||||
|
||||
g_queue_sort(&playlist->pl_queue.q_tracks, __playlist_generic_less_than,
|
||||
playlist->pl_queue.q_sort);
|
||||
playlist);
|
||||
|
||||
playlist_generic_update(playlist, NULL);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
queue->q_sort = NULL;
|
||||
queue->q_ops = ops;
|
||||
|
||||
g_queue_init(&queue->q_tracks);
|
||||
|
@ -34,8 +33,6 @@ void queue_deinit(struct queue *queue)
|
|||
{
|
||||
g_queue_clear(&queue->q_tracks);
|
||||
__queue_deinit(queue);
|
||||
g_slist_free(queue->q_sort);
|
||||
queue->q_sort = NULL;
|
||||
queue->q_cur.it_pos = UINT_MAX;
|
||||
queue->q_cur.it_iter = NULL;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ static bool can_scroll = true;
|
|||
static int __gui_treeview_colum_match_sort(enum compare_t compare)
|
||||
{
|
||||
struct playlist *playlist = gui_model_get_playlist();
|
||||
GSList *cur = playlist ? playlist->pl_queue.q_sort : NULL;
|
||||
GSList *cur = playlist ? playlist->pl_sort : NULL;
|
||||
|
||||
while (cur) {
|
||||
int field = GPOINTER_TO_INT(cur->data);
|
||||
|
|
|
@ -49,6 +49,7 @@ struct playlist {
|
|||
|
||||
unsigned int pl_length; /* This playlist's length, in seconds. */
|
||||
bool pl_random; /* This playlist's random setting. */
|
||||
GSList *pl_sort; /* This playlist's sort order. */
|
||||
void *pl_private; /* This playlist's private data. */
|
||||
struct queue pl_queue; /* This playlist's queue of tracks. */
|
||||
|
||||
|
@ -100,8 +101,8 @@ static inline unsigned int playlist_size(struct playlist *playlist)
|
|||
static inline void playlist_clear_sort(struct playlist *playlist)
|
||||
{
|
||||
if (playlist) {
|
||||
g_slist_free(playlist->pl_queue.q_sort);
|
||||
playlist->pl_queue.q_sort = NULL;
|
||||
g_slist_free(playlist->pl_sort);
|
||||
playlist->pl_sort = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ struct queue_iter {
|
|||
|
||||
struct queue {
|
||||
GQueue q_tracks; /* The queue's list of tracks. */
|
||||
GSList *q_sort; /* The queue's sort order. */
|
||||
void *q_private; /* The queue's private data. */
|
||||
|
||||
struct queue_iter q_cur; /* The queue's last-played position. */
|
||||
|
|
|
@ -161,7 +161,7 @@ static void test_playlist()
|
|||
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||
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_sort);
|
||||
g_assert_null(p.pl_sort);
|
||||
}
|
||||
|
||||
static void test_sorting()
|
||||
|
@ -171,9 +171,9 @@ static void test_sorting()
|
|||
unsigned int i;
|
||||
|
||||
playlist_generic_init(&p, NULL);
|
||||
g_assert_cmpuint(g_slist_length(p.pl_queue.q_sort), ==, 3);
|
||||
g_assert_cmpuint(g_slist_length(p.pl_sort), ==, 3);
|
||||
playlist_clear_sort(&p);
|
||||
g_assert_cmpuint(g_slist_length(p.pl_queue.q_sort), ==, 0);
|
||||
g_assert_cmpuint(g_slist_length(p.pl_sort), ==, 0);
|
||||
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = track_get(i);
|
||||
|
@ -245,7 +245,7 @@ static void test_sorting()
|
|||
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||
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_sort);
|
||||
g_assert_null(p.pl_sort);
|
||||
}
|
||||
|
||||
static void test_next()
|
||||
|
@ -291,7 +291,7 @@ static void test_next()
|
|||
g_assert_cmpuint(p.pl_length, ==, 0);
|
||||
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_sort);
|
||||
g_assert_null(p.pl_sort);
|
||||
}
|
||||
|
||||
static void test_save_load()
|
||||
|
@ -326,15 +326,14 @@ static void test_save_load()
|
|||
|
||||
g_assert_true(r.pl_random);
|
||||
g_assert_cmpuint(r.pl_queue.q_cur.it_pos, ==, 3);
|
||||
g_assert_cmpuint(g_slist_length(r.pl_queue.q_sort), ==, 1);
|
||||
g_assert_cmpuint(GPOINTER_TO_UINT(r.pl_queue.q_sort->data),
|
||||
==, COMPARE_TRACK);
|
||||
g_assert_cmpuint(g_slist_length(r.pl_sort), ==, 1);
|
||||
g_assert_cmpuint(GPOINTER_TO_UINT(r.pl_sort->data), ==, COMPARE_TRACK);
|
||||
g_assert_cmpuint(g_queue_get_length(&r.pl_queue.q_tracks), ==, 0);
|
||||
|
||||
g_assert_false(s.pl_random);
|
||||
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_slist_length(s.pl_sort), ==, 0);
|
||||
g_assert_cmpuint(playlist_size(&s), ==, 13);
|
||||
|
||||
/* Deinitialize the playlist. */
|
||||
|
|
|
@ -75,15 +75,15 @@ void test_library()
|
|||
playlist_set_random(playlist, false);
|
||||
g_assert_false(playlist->pl_random);
|
||||
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 3);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 3);
|
||||
playlist_clear_sort(playlist);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 0);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 0);
|
||||
g_assert_true(playlist_sort(playlist, COMPARE_ARTIST));
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 1);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 1);
|
||||
g_assert_true(playlist_sort(playlist, COMPARE_YEAR));
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 2);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 2);
|
||||
g_assert_true(playlist_sort(playlist, COMPARE_TRACK));
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 3);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 3);
|
||||
|
||||
g_rename("tests/Music/Hyrule Symphony/", "tests/Hyrule Symphony/");
|
||||
pl_library_update(playlist);
|
||||
|
|
|
@ -42,11 +42,9 @@ static void test_init()
|
|||
g_assert_false(playlist_select(playlist));
|
||||
|
||||
if (i == SYS_PL_QUEUED || i == SYS_PL_HISTORY) {
|
||||
g_assert_cmpuint(
|
||||
g_slist_length(playlist->pl_queue.q_sort), ==, 0);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 0);
|
||||
} else
|
||||
g_assert_cmpuint(
|
||||
g_slist_length(playlist->pl_queue.q_sort), ==, 3);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 3);
|
||||
}
|
||||
|
||||
/* Add tracks to the collection. */
|
||||
|
@ -99,14 +97,14 @@ static void test_sort()
|
|||
|
||||
if (i == SYS_PL_HISTORY) {
|
||||
g_assert_false(playlist_sort(playlist, COMPARE_TRACK));
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 0);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 0);
|
||||
g_assert_false(playlist_sort(playlist, COMPARE_YEAR));
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 0);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 0);
|
||||
} else {
|
||||
g_assert_true(playlist_sort(playlist, COMPARE_TRACK));
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 1);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 1);
|
||||
g_assert_true(playlist_sort(playlist, COMPARE_YEAR));
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_queue.q_sort), ==, 2);
|
||||
g_assert_cmpuint(g_slist_length(playlist->pl_sort), ==, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ static void test_init()
|
|||
g_assert_null(q.q_private);
|
||||
|
||||
g_assert_cmpuint(q.q_cur.it_pos, ==, (unsigned int)-1);
|
||||
g_assert_null(q.q_sort);
|
||||
g_assert_null(q.q_ops);
|
||||
|
||||
queue_iter_init(&q, &it);
|
||||
|
@ -55,7 +54,6 @@ static void test_init()
|
|||
g_assert_cmpuint(GPOINTER_TO_UINT(q.q_private), ==, 1);
|
||||
|
||||
g_assert_cmpuint(q.q_cur.it_pos, ==, (unsigned int)-1);
|
||||
g_assert_null(q.q_sort);
|
||||
g_assert(q.q_ops == &test_ops);
|
||||
|
||||
queue_deinit(&q);
|
||||
|
|
Loading…
Reference in New Issue