core/tempq: Remove tempq.c
Multiple temporary queues has been replaced with a single Queued Tracks playlist. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
69e628f505
commit
e4cd59b895
|
@ -5,7 +5,6 @@
|
|||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/settings.h>
|
||||
#include <core/tempq.h>
|
||||
|
||||
static const char *SETTINGS_TRACK = "core.audio.cur";
|
||||
static struct file audio_file = FILE_INIT("cur_track", 0, 0);
|
||||
|
@ -52,7 +51,7 @@ static struct track *__audio_load_basic(struct track *track, GstState state)
|
|||
audio_ops->on_load(track);
|
||||
__audio_change_state(state);
|
||||
|
||||
tempq_updated(prev);
|
||||
queue_updated(playlist_get_queue(PL_SYSTEM, "Queued Tracks"), prev);
|
||||
queue_updated(playlist_get_queue(PL_SYSTEM, "Collection"), prev);
|
||||
queue_updated(playlist_get_queue(PL_SYSTEM, "Collection"), audio_track);
|
||||
|
||||
|
@ -71,10 +70,7 @@ static struct track *__audio_load(struct track *track, GstState state)
|
|||
|
||||
static struct track *__audio_next(GstState state)
|
||||
{
|
||||
struct track *track = tempq_next();
|
||||
if (!track)
|
||||
track = playlist_next();
|
||||
return __audio_load(track, state);
|
||||
return __audio_load(playlist_next(), state);
|
||||
}
|
||||
|
||||
static gboolean __audio_message(GstBus *bus, GstMessage *message, gpointer data)
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <core/playlist.h>
|
||||
#include <core/settings.h>
|
||||
#include <core/tags/tags.h>
|
||||
#include <core/tempq.h>
|
||||
|
||||
|
||||
void core_init(int *argc, char ***argv, struct core_init_data *init)
|
||||
|
@ -20,14 +19,12 @@ void core_init(int *argc, char ***argv, struct core_init_data *init)
|
|||
settings_init();
|
||||
tags_init();
|
||||
playlist_init(init->playlist_ops);
|
||||
tempq_init(init->tempq_ops);
|
||||
audio_init(argc, argv, init->audio_ops);
|
||||
}
|
||||
|
||||
void core_deinit()
|
||||
{
|
||||
audio_deinit();
|
||||
tempq_deinit();
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
settings_deinit();
|
||||
|
|
153
core/tempq.c
153
core/tempq.c
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/file.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/tempq.h>
|
||||
#include <glib.h>
|
||||
|
||||
static struct file tempq_file = FILE_INIT("deck", 1, 1);
|
||||
static struct queue_ops *tempq_ops = NULL;
|
||||
static GSList *tempq_list;
|
||||
static struct file tempq_file;
|
||||
|
||||
static struct queue *__tempq_alloc(unsigned int flags)
|
||||
{
|
||||
struct queue *queue = g_malloc(sizeof(struct queue));
|
||||
flags = flags | Q_SAVE_FLAGS | Q_SAVE_SORT;
|
||||
|
||||
tempq_list = g_slist_append(tempq_list, queue);
|
||||
queue_init(queue, flags, tempq_ops, NULL);
|
||||
return queue;
|
||||
}
|
||||
|
||||
static void __tempq_free(struct queue *queue)
|
||||
{
|
||||
tempq_list = g_slist_remove(tempq_list, queue);
|
||||
queue_deinit(queue);
|
||||
g_free(queue);
|
||||
}
|
||||
|
||||
static void __tempq_read_queue()
|
||||
{
|
||||
struct queue *queue;
|
||||
unsigned int flags;
|
||||
|
||||
file_readf(&tempq_file, "%u", &flags);
|
||||
queue = __tempq_alloc(flags);
|
||||
queue_load_tracks(queue, &tempq_file);
|
||||
}
|
||||
|
||||
static void __tempq_write_queue(struct queue *queue)
|
||||
{
|
||||
file_writef(&tempq_file, "%u ", queue->q_flags);
|
||||
queue_save_tracks(queue, &tempq_file);
|
||||
file_writef(&tempq_file, "\n");
|
||||
}
|
||||
|
||||
static bool __tempq_init_idle(void *data)
|
||||
{
|
||||
unsigned int num, i;
|
||||
|
||||
if (!file_open(&tempq_file, OPEN_READ))
|
||||
return true;
|
||||
|
||||
file_readf(&tempq_file, "%u", &num);
|
||||
for (i = 0; i < num; i++)
|
||||
__tempq_read_queue();
|
||||
file_close(&tempq_file);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void tempq_init(struct queue_ops *ops)
|
||||
{
|
||||
tempq_ops = ops;
|
||||
idle_schedule(IDLE_SYNC, __tempq_init_idle, NULL);
|
||||
}
|
||||
|
||||
void tempq_deinit()
|
||||
{
|
||||
while (tempq_list)
|
||||
__tempq_free((struct queue *)tempq_list->data);
|
||||
}
|
||||
|
||||
void tempq_save(struct queue *queue, enum queue_flags flag)
|
||||
{
|
||||
GSList *cur;
|
||||
|
||||
if (!file_open(&tempq_file, OPEN_WRITE))
|
||||
return;
|
||||
|
||||
file_writef(&tempq_file, "%zu\n", g_slist_length(tempq_list));
|
||||
for (cur = tempq_list; cur; cur = g_slist_next(cur))
|
||||
__tempq_write_queue((struct queue *)cur->data);
|
||||
|
||||
file_close(&tempq_file);
|
||||
}
|
||||
|
||||
struct queue *tempq_alloc(unsigned int flags)
|
||||
{
|
||||
struct queue *queue = __tempq_alloc(Q_ENABLED | flags);
|
||||
tempq_save(queue, Q_ENABLED);
|
||||
return queue;
|
||||
}
|
||||
|
||||
void tempq_free(struct queue *queue)
|
||||
{
|
||||
__tempq_free(queue);
|
||||
tempq_save(NULL, Q_ENABLED);
|
||||
}
|
||||
|
||||
struct queue *tempq_get(unsigned int index)
|
||||
{
|
||||
return (struct queue *)g_slist_nth_data(tempq_list, index);
|
||||
}
|
||||
|
||||
unsigned int tempq_index(struct queue *queue)
|
||||
{
|
||||
return g_slist_index(tempq_list, queue);
|
||||
}
|
||||
|
||||
void tempq_move(struct queue *queue, unsigned int index)
|
||||
{
|
||||
GSList *cur = g_slist_find(tempq_list, queue);
|
||||
GSList *nth = g_slist_nth(tempq_list, index);
|
||||
if (cur && nth && (cur != nth)) {
|
||||
tempq_list = g_slist_remove(tempq_list, queue);
|
||||
tempq_list = g_slist_insert_before(tempq_list, nth, queue);
|
||||
tempq_save(queue, Q_ENABLED);
|
||||
}
|
||||
}
|
||||
|
||||
struct track *tempq_next()
|
||||
{
|
||||
struct track *track = NULL;
|
||||
struct queue *queue = NULL;
|
||||
GSList *cur;
|
||||
|
||||
for (cur = tempq_list; cur; cur = g_slist_next(cur)) {
|
||||
queue = (struct queue *)cur->data;
|
||||
if (queue_has_flag(queue, Q_ENABLED)) {
|
||||
track = queue_next(queue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (queue && queue_size(queue) == 0)
|
||||
tempq_free(queue);
|
||||
return track;
|
||||
}
|
||||
|
||||
unsigned int tempq_count()
|
||||
{
|
||||
return g_slist_length(tempq_list);
|
||||
}
|
||||
|
||||
void tempq_updated(struct track *track)
|
||||
{
|
||||
GSList *cur;
|
||||
|
||||
for (cur = tempq_list; cur; cur = g_slist_next(cur))
|
||||
queue_updated((struct queue *)cur->data, track);
|
||||
}
|
|
@ -23,7 +23,6 @@ const static gchar *OCARINA_NAME = "org.gtk.ocarina-debug";
|
|||
|
||||
struct core_init_data init_data = {
|
||||
&playlist_ops,
|
||||
NULL,
|
||||
&audio_ops,
|
||||
};
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
struct core_init_data {
|
||||
struct queue_ops *playlist_ops;
|
||||
struct queue_ops *tempq_ops;
|
||||
struct audio_ops *audio_ops;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*
|
||||
* The temporary queue manager controls access to any temporary
|
||||
* queues created by the user. When saving to disk:
|
||||
*
|
||||
* length(tempq_list)
|
||||
* flags num_tracks track_0 track_1 ... track_N
|
||||
* flags num_tracks track_0 track_1 ... track_N
|
||||
*/
|
||||
#ifndef OCARINA_CORE_DECK_H
|
||||
#define OCARINA_CORE_DECK_H
|
||||
|
||||
#include <core/queue.h>
|
||||
|
||||
|
||||
/* Called to initialize the temporary queue manager. */
|
||||
void tempq_init(struct queue_ops *);
|
||||
|
||||
/* Called to deinitialize the temporary queue manager. */
|
||||
void tempq_deinit();
|
||||
|
||||
/* Called to save the temporary queue list. */
|
||||
void tempq_save(struct queue *, enum queue_flags);
|
||||
|
||||
|
||||
/* Called to allocate a new temporary queue. */
|
||||
struct queue *tempq_alloc(unsigned int);
|
||||
|
||||
/* Called to free a temporary queue. */
|
||||
void tempq_free(struct queue *);
|
||||
|
||||
/* Called to find a temporary queue by index. */
|
||||
struct queue *tempq_get(unsigned int);
|
||||
|
||||
/* Called to find the index of a temporary queue. */
|
||||
unsigned int tempq_index(struct queue *);
|
||||
|
||||
/* Called to move a temporary queue to a new index in the list. */
|
||||
void tempq_move(struct queue *, unsigned int);
|
||||
|
||||
/* Called to find the next track to play. */
|
||||
struct track *tempq_next();
|
||||
|
||||
/* Called to find the number of temporary queues currently allocated. */
|
||||
unsigned int tempq_count();
|
||||
|
||||
/* Called to tell temporary queues that a track has been updated. */
|
||||
void tempq_updated(struct track *);
|
||||
|
||||
#endif /* OCARINA_CORE_DECK_H */
|
|
@ -6,5 +6,4 @@ idle
|
|||
settings
|
||||
database
|
||||
queue
|
||||
tempq
|
||||
audio
|
||||
|
|
|
@ -16,5 +16,4 @@ add_subdirectory(tags/)
|
|||
core_unit_test(Queue)
|
||||
|
||||
add_subdirectory(playlists/)
|
||||
core_unit_test(Tempq)
|
||||
core_unit_test(Audio)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <core/audio.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tempq.h>
|
||||
#include <core/core.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
|
@ -125,17 +124,16 @@ static void test_playback()
|
|||
static void test_next()
|
||||
{
|
||||
struct queue *history_q = playlist_get_queue(PL_SYSTEM, "History");
|
||||
struct queue *temp_q = tempq_alloc(0);
|
||||
int i;
|
||||
|
||||
state_count = 0;
|
||||
/* First, let's test getting tracks from a temporary queue. */
|
||||
queue_add(temp_q, track_get(2));
|
||||
queue_add(temp_q, track_get(1));
|
||||
queue_add(temp_q, track_get(0));
|
||||
playlist_add(PL_SYSTEM, "Queued Tracks", track_get(2));
|
||||
playlist_add(PL_SYSTEM, "Queued Tracks", track_get(1));
|
||||
playlist_add(PL_SYSTEM, "Queued Tracks", track_get(0));
|
||||
|
||||
for (i = 2; i >= 0; i--) {
|
||||
g_assert_cmpuint(queue_size(temp_q), ==, i + 1);
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, i + 1);
|
||||
if (i > 0)
|
||||
g_assert_cmpuint(audio_next()->tr_track, ==, track_get(i)->tr_track);
|
||||
else /* Simulate an error. */
|
||||
|
@ -145,7 +143,7 @@ static void test_next()
|
|||
g_assert(audio_cur_track() == track_get(i));
|
||||
}
|
||||
g_assert_cmpuint(state_count, ==, 3);
|
||||
g_assert_null(tempq_get(0));
|
||||
g_assert_cmpuint(playlist_size(PL_SYSTEM, "Queued Tracks"), ==, 0);
|
||||
|
||||
/* Tracks should now be picked from the collection. */
|
||||
for (i = 1; i <= 3; i++) {
|
||||
|
|
|
@ -1,175 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/tags/tags.h>
|
||||
#include <core/tempq.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
|
||||
static void test_init()
|
||||
{
|
||||
g_assert_null(tempq_next());
|
||||
|
||||
tempq_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
|
||||
g_assert_null(tempq_next());
|
||||
tempq_move(NULL, 1);
|
||||
g_assert_null(tempq_get(0));
|
||||
g_assert_cmpuint(tempq_count(), ==, 0);
|
||||
g_assert_cmpuint(tempq_index(NULL), ==, (unsigned int)-1);
|
||||
}
|
||||
|
||||
static void test_alloc()
|
||||
{
|
||||
struct queue *q0, *q1;
|
||||
|
||||
q0 = tempq_alloc(0);
|
||||
g_assert_nonnull(q0);
|
||||
g_assert_true(queue_has_flag(q0, Q_ENABLED));
|
||||
g_assert_false(queue_has_flag(q0, Q_RANDOM));
|
||||
g_assert_true(queue_has_flag(q0, Q_SAVE_SORT));
|
||||
g_assert_true(queue_has_flag(q0, Q_SAVE_FLAGS));
|
||||
g_assert(tempq_get(0) == q0);
|
||||
g_assert_cmpuint(tempq_count(), ==, 1);
|
||||
g_assert_cmpuint(tempq_index(q0), ==, 0);
|
||||
|
||||
q1 = tempq_alloc(Q_RANDOM);
|
||||
g_assert_nonnull(q1);
|
||||
g_assert_true(queue_has_flag(q1, Q_ENABLED));
|
||||
g_assert_true(queue_has_flag(q1, Q_RANDOM));
|
||||
g_assert_true(queue_has_flag(q1, Q_SAVE_SORT));
|
||||
g_assert_true(queue_has_flag(q1, Q_SAVE_FLAGS));
|
||||
g_assert(tempq_get(1) == q1);
|
||||
g_assert_cmpuint(tempq_count(), ==, 2);
|
||||
g_assert_cmpuint(tempq_index(q1), ==, 1);
|
||||
|
||||
tempq_deinit();
|
||||
g_assert_cmpuint(tempq_count(), ==, 0);
|
||||
tempq_init(NULL);
|
||||
g_assert_cmpuint(tempq_count(), ==, 0);
|
||||
while (idle_run_task()) {};
|
||||
g_assert_cmpuint(tempq_count(), ==, 2);
|
||||
|
||||
q0 = tempq_get(0);
|
||||
q1 = tempq_get(1);
|
||||
g_assert_false(queue_has_flag(q0, Q_RANDOM));
|
||||
g_assert_true(queue_has_flag(q1, Q_RANDOM));
|
||||
}
|
||||
|
||||
static void test_move()
|
||||
{
|
||||
struct queue *q0 = tempq_get(0);
|
||||
struct queue *q1 = tempq_get(1);
|
||||
|
||||
tempq_move(NULL, 0);
|
||||
|
||||
tempq_move(q1, 0);
|
||||
g_assert(tempq_get(0) == q1);
|
||||
g_assert(tempq_get(1) == q0);
|
||||
g_assert_null(tempq_get(2));
|
||||
|
||||
tempq_move(q0, 1);
|
||||
g_assert(tempq_get(0) == q1);
|
||||
g_assert(tempq_get(1) == q0);
|
||||
g_assert_null(tempq_get(2));
|
||||
|
||||
tempq_deinit();
|
||||
g_assert_cmpuint(tempq_count(), ==, 0);
|
||||
tempq_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
|
||||
q0 = tempq_get(1);
|
||||
q1 = tempq_get(0);
|
||||
g_assert_false(queue_has_flag(q0, Q_RANDOM));
|
||||
g_assert_true(queue_has_flag(q1, Q_RANDOM));
|
||||
}
|
||||
|
||||
static void test_free()
|
||||
{
|
||||
struct queue *q0 = tempq_get(1);
|
||||
struct queue *q1 = tempq_get(0);
|
||||
|
||||
tempq_free(q0);
|
||||
g_assert(tempq_get(0) == q1);
|
||||
g_assert_cmpuint(tempq_count(), ==, 1);
|
||||
|
||||
tempq_free(q1);
|
||||
g_assert_null(tempq_get(0));
|
||||
g_assert_cmpuint(tempq_count(), ==, 0);
|
||||
|
||||
tempq_deinit();
|
||||
tempq_init(NULL);
|
||||
g_assert_cmpuint(tempq_count(), ==, 0);
|
||||
}
|
||||
|
||||
static void test_next()
|
||||
{
|
||||
const struct database *track_db = track_db_get();
|
||||
struct queue *q0, *q1;
|
||||
unsigned int i;
|
||||
|
||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task()) {};
|
||||
|
||||
q0 = tempq_alloc(0);
|
||||
q1 = tempq_alloc(0);
|
||||
for (i = 0; i < track_db->db_size; i++) {
|
||||
queue_add(q0, track_get(i));
|
||||
queue_add(q1, track_get(i));
|
||||
}
|
||||
|
||||
tempq_save(NULL, Q_ENABLED);
|
||||
tempq_deinit();
|
||||
tempq_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
g_assert_cmpuint(tempq_count(), ==, 2);
|
||||
q0 = tempq_get(0);
|
||||
q1 = tempq_get(1);
|
||||
|
||||
for (i = 0; i < track_db->db_size; i++) {
|
||||
g_assert_cmpuint(queue_size(q0), ==, track_db->db_size - i);
|
||||
g_assert(tempq_next() == track_get(i));
|
||||
}
|
||||
g_assert(tempq_get(0) == q1);
|
||||
g_assert_cmpuint(tempq_count(), ==, 1);
|
||||
g_assert_cmpuint(queue_size(q1), ==, track_db->db_size);
|
||||
|
||||
tempq_deinit();
|
||||
tempq_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
g_assert_cmpuint(tempq_count(), ==, 1);
|
||||
q1 = tempq_get(0);
|
||||
|
||||
for (i = 0; i < track_db->db_size; i++) {
|
||||
g_assert_cmpuint(queue_size(q1), ==, track_db->db_size - i);
|
||||
g_assert(tempq_next() == track_get(i));
|
||||
}
|
||||
g_assert_null(tempq_get(0));
|
||||
g_assert_cmpuint(tempq_count(), ==, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
|
||||
idle_init_sync();
|
||||
tags_init();
|
||||
playlist_init(NULL);
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Core/Temporary Queue/Initialization", test_init);
|
||||
g_test_add_func("/Core/Temporary Queue/Alloc", test_alloc);
|
||||
g_test_add_func("/Core/Temporary Queue/Move", test_move);
|
||||
g_test_add_func("/Core/Temporary Queue/Free", test_free);
|
||||
g_test_add_func("/Core/Temporary Queue/Next Track", test_next);
|
||||
ret = g_test_run();
|
||||
|
||||
tempq_deinit();
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
idle_deinit();
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue