core: Initialize the playlist before the collection
I think it makes more sense to have the collection manage if banned tracks are displayed or not, rather than doing this from the playlist layer. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
beda9bfa3f
commit
fef3ef3353
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
#include <core/collection.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -106,7 +107,8 @@ void collection_init(struct queue_ops *ops)
|
|||
queue_init(&c_queue, Q_ENABLED | Q_REPEAT | Q_ADD_FRONT, ops);
|
||||
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
if (TRACK(track)->tr_library->li_enabled)
|
||||
if (TRACK(track)->tr_library->li_enabled &&
|
||||
!playlist_has(PL_BANNED, TRACK(track)))
|
||||
queue_add(&c_queue, TRACK(track));
|
||||
}
|
||||
queue_unset_flag(&c_queue, Q_ADD_FRONT);
|
||||
|
@ -200,14 +202,18 @@ void collection_update_all()
|
|||
|
||||
bool collection_ban(struct track *track)
|
||||
{
|
||||
queue_remove_all(&c_queue, track);
|
||||
return true;
|
||||
bool ret = playlist_add(PL_BANNED, track);
|
||||
if (ret)
|
||||
queue_remove_all(&c_queue, track);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool collection_unban(struct track *track)
|
||||
{
|
||||
queue_add(&c_queue, track);
|
||||
return true;
|
||||
bool ret = playlist_remove(PL_BANNED, track);
|
||||
if (ret)
|
||||
queue_add(&c_queue, track);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void collection_set_enabled(struct library *library, bool enabled)
|
||||
|
@ -224,9 +230,10 @@ void collection_set_enabled(struct library *library, bool enabled)
|
|||
db_for_each(dbe, next, track_db_get()) {
|
||||
track = TRACK(dbe);
|
||||
if (track->tr_library == library) {
|
||||
if (enabled)
|
||||
queue_add(&c_queue, track);
|
||||
else
|
||||
if (enabled) {
|
||||
if (!playlist_has(PL_BANNED, track))
|
||||
queue_add(&c_queue, track);
|
||||
} else
|
||||
queue_remove_all(&c_queue, track);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,16 +16,16 @@ void core :: init(struct core_init_data *init)
|
|||
{
|
||||
filter_init();
|
||||
tags_init();
|
||||
collection_init(init->collection_ops);
|
||||
playlist_init(init->playlist_ops);
|
||||
collection_init(init->collection_ops);
|
||||
deck :: init(init->history_ops, init->tempq_ops);
|
||||
audio :: init();
|
||||
}
|
||||
|
||||
void core :: deinit()
|
||||
{
|
||||
playlist_deinit();
|
||||
collection_deinit();
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
}
|
||||
|
|
|
@ -80,7 +80,6 @@ void playlist_init(struct queue_ops *ops)
|
|||
|
||||
index_init(&playlist_db, "playlist.db", true);
|
||||
db_load(&playlist_db);
|
||||
playlist_fixup_collection();
|
||||
}
|
||||
|
||||
void playlist_deinit()
|
||||
|
@ -89,18 +88,6 @@ void playlist_deinit()
|
|||
db_deinit(&playlist_db);
|
||||
}
|
||||
|
||||
void playlist_fixup_collection()
|
||||
{
|
||||
struct index_entry *ent = __playlist_lookup(PL_BANNED);
|
||||
struct set_iter it;
|
||||
|
||||
if (!ent)
|
||||
return;
|
||||
|
||||
set_for_each(&ent->ie_set, &it)
|
||||
queue_remove_all(collection_get_queue(), track_get(it.it_val));
|
||||
}
|
||||
|
||||
bool playlist_add(enum playlist_t plist, struct track *track)
|
||||
{
|
||||
if (!track || !__playlist_is_static(plist) || playlist_has(plist, track))
|
||||
|
@ -110,8 +97,6 @@ bool playlist_add(enum playlist_t plist, struct track *track)
|
|||
track->tr_dbe.dbe_index);
|
||||
if (playlist_cur == plist)
|
||||
queue_add(&playlist_q, track);
|
||||
if (plist == PL_BANNED)
|
||||
queue_remove_all(collection_get_queue(), track);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -124,8 +109,6 @@ bool playlist_remove(enum playlist_t plist, struct track *track)
|
|||
track->tr_dbe.dbe_index);
|
||||
if (playlist_cur == plist)
|
||||
queue_remove_all(&playlist_q, track);
|
||||
if (plist == PL_BANNED)
|
||||
queue_add(collection_get_queue(), track);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
tab_selected_ids(ids);
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
playlist_add(PL_BANNED, track_get(ids[i]));
|
||||
collection_ban(track_get(ids[i]));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -156,8 +156,6 @@ static void on_toggled(const Glib::ustring &str)
|
|||
|
||||
collection_set_enabled(lib, !lib->li_enabled);
|
||||
row[c_cols.c_enabled] = lib->li_enabled;
|
||||
if (lib->li_enabled)
|
||||
playlist_fixup_collection();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
#include <core/audio.h>
|
||||
extern "C" {
|
||||
#include <core/collection.h>
|
||||
#include <core/playlist.h>
|
||||
}
|
||||
#include <gui/tabs.h>
|
||||
|
@ -124,7 +125,10 @@ public:
|
|||
|
||||
tab_selected_ids(ids);
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
playlist_remove(cur, track_get(ids[i]));
|
||||
if (cur == PL_BANNED)
|
||||
collection_unban(track_get(ids[i]));
|
||||
else
|
||||
playlist_remove(cur, track_get(ids[i]));
|
||||
return true;
|
||||
}
|
||||
} *p_tab;
|
||||
|
@ -135,10 +139,10 @@ static void on_ban()
|
|||
{
|
||||
struct track *track = audio :: current_track();
|
||||
if (o_ban->get_active()) {
|
||||
if (playlist_add(PL_BANNED, track))
|
||||
if (collection_ban(track))
|
||||
audio :: next();
|
||||
} else
|
||||
playlist_remove(PL_BANNED, track);
|
||||
collection_unban(track);
|
||||
}
|
||||
|
||||
static void on_favorite()
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
#include <core/deck.h>
|
||||
extern "C" {
|
||||
#include <core/collection.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/string.h>
|
||||
}
|
||||
|
@ -225,8 +226,12 @@ bool Tab :: tab_add_to_playlist(enum playlist_t plist)
|
|||
std::vector<unsigned int> ids;
|
||||
|
||||
tab_selected_ids(ids);
|
||||
for (unsigned int i = 0; i < ids.size(); i++)
|
||||
playlist_add(plist, track_get(ids[i]));
|
||||
for (unsigned int i = 0; i < ids.size(); i++) {
|
||||
if (plist == PL_BANNED)
|
||||
collection_ban(track_get(ids[i]));
|
||||
else
|
||||
playlist_add(plist, track_get(ids[i]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,6 @@ void playlist_init(struct queue_ops *);
|
|||
/* Called to deinitialize the playlist manager. */
|
||||
void playlist_deinit();
|
||||
|
||||
/* Called to remove banned tracks from the collection queue. */
|
||||
void playlist_fixup_collection();
|
||||
|
||||
|
||||
/* Called to add a track to a playlist. */
|
||||
bool playlist_add(enum playlist_t, struct track *);
|
||||
|
|
|
@ -25,8 +25,8 @@ res += [ CoreTest("idle", "idle.c") ]
|
|||
|
||||
res += SConscript("tags/Sconscript")
|
||||
res += [ CoreTest("queue", "queue.c") ]
|
||||
res += [ CoreTest("collection", "collection.c") ]
|
||||
res += [ CoreTest("playlist", "playlist.c") ]
|
||||
res += [ CoreTest("collection", "collection.c") ]
|
||||
res += [ CoreTest("deck", "deck.cpp") ]
|
||||
res += [ CoreTest("audio", "audio.cpp") ]
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
extern "C" {
|
||||
#include <core/collection.h>
|
||||
#include <core/filter.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/tags.h>
|
||||
}
|
||||
#include <core/deck.h>
|
||||
|
@ -88,6 +89,7 @@ void test_init()
|
|||
|
||||
filter_init();
|
||||
tags_init();
|
||||
playlist_init(NULL);
|
||||
collection_init(NULL);
|
||||
deck :: init(NULL, NULL);
|
||||
audio :: init();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <core/collection.h>
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/tags.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
|
@ -14,6 +15,7 @@ static void test_init()
|
|||
|
||||
filter_init();
|
||||
tags_init();
|
||||
playlist_init(NULL);
|
||||
collection_init(NULL);
|
||||
|
||||
test_not_equal((void *)q, NULL);
|
||||
|
@ -115,10 +117,43 @@ static void test_update()
|
|||
test_equal(queue_size(q), 48);
|
||||
}
|
||||
|
||||
static void test_ban()
|
||||
{
|
||||
const struct database *track_db = track_db_get();
|
||||
struct queue *q = collection_get_queue();
|
||||
struct db_entry *dbe, *next;
|
||||
struct track *track;
|
||||
unsigned int i = 0;
|
||||
|
||||
db_for_each(dbe, next, track_db) {
|
||||
track = TRACK(dbe);
|
||||
test_loop_equal(playlist_has(PL_BANNED, track), (bool)false, i);
|
||||
test_loop_equal(collection_ban(track), (bool)true, i);
|
||||
test_loop_equal(collection_ban(track), (bool)false, i);
|
||||
test_loop_equal(playlist_has(PL_BANNED, track), (bool)true, i);
|
||||
test_loop_equal(queue_size(q), track_db->db_size - (i + 1), i);
|
||||
i++;
|
||||
} test_loop_passed();
|
||||
test_equal(queue_size(q), 0);
|
||||
|
||||
i = 0;
|
||||
db_for_each(dbe, next, track_db) {
|
||||
track = TRACK(dbe);
|
||||
test_loop_equal(playlist_has(PL_BANNED, track), (bool)true, i);
|
||||
test_loop_equal(collection_unban(track), (bool)true, i);
|
||||
test_loop_equal(collection_unban(track), (bool)false, i);
|
||||
test_loop_equal(playlist_has(PL_BANNED, track), (bool)false, i);
|
||||
test_loop_equal(queue_size(q), i + 1, i);
|
||||
i++;
|
||||
} test_loop_passed();
|
||||
test_equal(queue_size(q), track_db->db_size);
|
||||
}
|
||||
|
||||
static void test_enable()
|
||||
{
|
||||
struct queue *q = collection_get_queue();
|
||||
struct library *lib = library_get(0);
|
||||
struct db_entry *dbe, *next;
|
||||
|
||||
collection_set_enabled(NULL, true);
|
||||
test_equal(queue_size(q), 48);
|
||||
|
@ -129,38 +164,29 @@ static void test_enable()
|
|||
collection_set_enabled(lib, false);
|
||||
test_equal(queue_size(q), 0);
|
||||
|
||||
collection_set_enabled(lib, true);
|
||||
test_equal(queue_size(q), 48);
|
||||
/* Banned tracks should not be re-added to the queue. */
|
||||
db_for_each(dbe, next, track_db_get()) {
|
||||
collection_ban(TRACK(dbe));
|
||||
next = db_next(track_db_get(), next);
|
||||
}
|
||||
|
||||
collection_set_enabled(lib, true);
|
||||
test_equal(queue_size(q), 24);
|
||||
|
||||
collection_set_enabled(lib, true);
|
||||
test_equal(queue_size(q), 24);
|
||||
|
||||
db_for_each(dbe, next, track_db_get()) {
|
||||
collection_unban(TRACK(dbe));
|
||||
next = db_next(track_db_get(), next);
|
||||
}
|
||||
test_equal(queue_size(q), 48);
|
||||
}
|
||||
|
||||
static void test_ban()
|
||||
{
|
||||
struct queue *q = collection_get_queue();
|
||||
struct db_entry *track, *next;
|
||||
unsigned int i = 0;
|
||||
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
test_loop_equal(collection_ban(TRACK(track)), (bool)true, i);
|
||||
test_loop_equal(queue_size(q), track_db_get()->db_size - (i + 1), i);
|
||||
i++;
|
||||
} test_loop_passed();
|
||||
test_equal(queue_size(q), 0);
|
||||
|
||||
i = 0;
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
test_loop_equal(collection_unban(TRACK(track)), (bool)true, i);
|
||||
test_loop_equal(queue_size(q), i + 1, i);
|
||||
i++;
|
||||
} test_loop_passed();
|
||||
test_equal(queue_size(q), track_db_get()->db_size);
|
||||
}
|
||||
|
||||
static void test_save_load()
|
||||
{
|
||||
struct queue *q = collection_get_queue();
|
||||
struct db_entry *dbe, *next;
|
||||
GSList *list;
|
||||
|
||||
collection_save(NULL, Q_ENABLED);
|
||||
|
@ -177,10 +203,21 @@ static void test_save_load()
|
|||
test_equal(queue_size(q), 0);
|
||||
test_equal(g_slist_length(q->q_sort), 0);
|
||||
|
||||
db_for_each(dbe, next, track_db_get()) {
|
||||
collection_ban(TRACK(dbe));
|
||||
next = db_next(track_db_get(), next);
|
||||
}
|
||||
|
||||
collection_init(NULL);
|
||||
test_equal(queue_size(q), 48);
|
||||
test_equal(queue_size(q), track_db_get()->db_size / 2);
|
||||
test_equal(g_slist_length(q->q_sort), 2);
|
||||
|
||||
db_for_each(dbe, next, track_db_get()) {
|
||||
collection_unban(TRACK(dbe));
|
||||
next = db_next(track_db_get(), next);
|
||||
}
|
||||
test_equal(queue_size(q), track_db_get()->db_size);
|
||||
|
||||
list = q->q_sort;
|
||||
test_equal(GPOINTER_TO_INT(list->data), -COMPARE_TRACK);
|
||||
list = g_slist_next(list);
|
||||
|
@ -200,6 +237,7 @@ static void test_remove()
|
|||
test_equal(queue_size(q), 0);
|
||||
|
||||
collection_deinit();
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
}
|
||||
|
@ -208,8 +246,8 @@ DECLARE_UNIT_TESTS(
|
|||
UNIT_TEST("Collection Initialization", test_init),
|
||||
UNIT_TEST("Collection Add Path", test_add),
|
||||
UNIT_TEST("Collection Update Path", test_update),
|
||||
UNIT_TEST("Collection Enable and Disable", test_enable),
|
||||
UNIT_TEST("Collection Ban and Unban", test_ban),
|
||||
UNIT_TEST("Collection Enable and Disable", test_enable),
|
||||
UNIT_TEST("Collection Save and Load", test_save_load),
|
||||
UNIT_TEST("Collection Remove Path", test_remove),
|
||||
);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
extern "C" {
|
||||
#include <core/collection.h>
|
||||
#include <core/filter.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/tags.h>
|
||||
}
|
||||
#include "test.h"
|
||||
|
@ -23,6 +24,7 @@ static void test_init()
|
|||
test_cp_data_dir();
|
||||
filter_init();
|
||||
tags_init();
|
||||
playlist_init(NULL);
|
||||
collection_init(NULL);
|
||||
deck :: init(NULL, NULL);
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/collection.h>
|
||||
#include <core/filter.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
|
@ -11,11 +10,11 @@
|
|||
static void test_init()
|
||||
{
|
||||
struct queue *q = playlist_get_queue();
|
||||
struct library *library;
|
||||
GSList *list;
|
||||
|
||||
filter_init();
|
||||
tags_init();
|
||||
collection_init(NULL);
|
||||
playlist_init(NULL);
|
||||
|
||||
test_not_equal((void *)q, NULL);
|
||||
|
@ -33,13 +32,25 @@ static void test_init()
|
|||
test_equal(GPOINTER_TO_INT(list->data), COMPARE_TRACK);
|
||||
|
||||
/* Add tracks to the collection. */
|
||||
collection_add("tests/Music/Hyrule Symphony/");
|
||||
while (idle_run_task());
|
||||
library = library_find("tests/Music");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/01 - Title Theme.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/02 - Kokiri Forest.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/03 - Hyrule Field.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/04 - Hyrule Castle.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/05 - Lon Lon Ranch.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/06 - Kakariko Village.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/07 - Death Mountain.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/08 - Zora's Domain.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/09 - Gerudo Valley.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/10 - Ganondorf.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/11 - Princess Zelda.ogg");
|
||||
track_add(library, "tests/Music/Hyrule Symphony/12 - Ocarina Medley.ogg");
|
||||
track_add(library,
|
||||
"tests/Music/Hyrule Symphony/13 - The Legend of Zelda Medley.ogg");
|
||||
}
|
||||
|
||||
static void test_add()
|
||||
{
|
||||
struct queue *c = collection_get_queue();
|
||||
struct queue *q = playlist_get_queue();
|
||||
struct track *track = track_get(0);
|
||||
|
||||
|
@ -58,23 +69,14 @@ static void test_add()
|
|||
track = track_get(2);
|
||||
playlist_select(PL_BANNED);
|
||||
test_equal(queue_size(q), 0);
|
||||
test_equal(queue_size(c), 13);
|
||||
test_equal(playlist_has(PL_BANNED, track), (bool)false);
|
||||
test_equal(playlist_add(PL_BANNED, track), (bool)true);
|
||||
test_equal(playlist_has(PL_BANNED, track), (bool)true);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(queue_size(c), 12);
|
||||
|
||||
/* Check playlist_fixup_collection() while we're here. */
|
||||
queue_add(c, track);
|
||||
test_equal(queue_size(c), 13);
|
||||
playlist_fixup_collection();
|
||||
test_equal(queue_size(c), 12);
|
||||
}
|
||||
|
||||
static void test_remove()
|
||||
{
|
||||
struct queue *c = collection_get_queue();
|
||||
struct queue *q = playlist_get_queue();
|
||||
struct track *track = track_get(0);
|
||||
|
||||
|
@ -95,12 +97,10 @@ static void test_remove()
|
|||
track = track_get(2);
|
||||
playlist_select(PL_BANNED);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(queue_size(c), 12);
|
||||
test_equal(playlist_has(PL_BANNED, track), (bool)true);
|
||||
test_equal(playlist_remove(PL_BANNED, track), (bool)true);
|
||||
test_equal(playlist_has(PL_BANNED, track), (bool)false);
|
||||
test_equal(queue_size(q), 0);
|
||||
test_equal(queue_size(c), 13);
|
||||
}
|
||||
|
||||
static void test_dynamic()
|
||||
|
@ -155,7 +155,6 @@ static void test_deinit()
|
|||
struct queue *q = playlist_get_queue();
|
||||
|
||||
playlist_deinit();
|
||||
collection_deinit();
|
||||
tags_deinit();
|
||||
filter_deinit();
|
||||
|
||||
|
|
Loading…
Reference in New Issue