core/queue: Convert file to C
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
799a8d34b5
commit
0b84b6180c
|
@ -1,14 +1,10 @@
|
|||
/**
|
||||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/queue.h>
|
||||
extern "C" {
|
||||
#include <core/random.h>
|
||||
}
|
||||
#include <core/string.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
static int track_less_than(const void *a, const void *b, void *data)
|
||||
|
@ -21,9 +17,9 @@ static int track_less_than(const void *a, const void *b, void *data)
|
|||
while (cur) {
|
||||
field = GPOINTER_TO_INT(cur->data);
|
||||
if (field > 0)
|
||||
res = track_compare(lhs, rhs, (compare_t)field);
|
||||
res = track_compare(lhs, rhs, field);
|
||||
else
|
||||
res = track_compare(rhs, lhs, (compare_t)abs(field));
|
||||
res = track_compare(rhs, lhs, abs(field));
|
||||
if (res == 0) {
|
||||
cur = g_slist_next(cur);
|
||||
continue;
|
||||
|
@ -61,7 +57,7 @@ static inline void __queue_updated(struct queue *queue, unsigned int pos)
|
|||
queue->q_ops->qop_updated(queue, pos);
|
||||
}
|
||||
|
||||
static inline track *__queue_selected(struct queue *queue)
|
||||
static inline struct track *__queue_selected(struct queue *queue)
|
||||
{
|
||||
struct track *track = (struct track *)_q_iter_val(&queue->q_cur);
|
||||
|
|
@ -4,7 +4,9 @@
|
|||
#ifndef OCARINA_CORE_DECK_H
|
||||
#define OCARINA_CORE_DECK_H
|
||||
|
||||
extern "C" {
|
||||
#include <core/queue.h>
|
||||
}
|
||||
#include <list>
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
#ifndef OCARINA_CORE_LIBRARY_H
|
||||
#define OCARINA_CORE_LIBRARY_H
|
||||
|
||||
extern "C" {
|
||||
#include <core/queue.h>
|
||||
}
|
||||
#include <string>
|
||||
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
extern "C" {
|
||||
#include <core/containers/index.h>
|
||||
}
|
||||
#include <core/queue.h>
|
||||
}
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
/**
|
||||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*
|
||||
* Queues are lists of tracks that the user has requested to play next.
|
||||
* Users of queues are expected to implement their own save and load functions,
|
||||
* and to provide a filled out queue_ops structure during initialization.
|
||||
*/
|
||||
#ifndef OCARINA_CORE_QUEUE_H
|
||||
#define OCARINA_CORE_QUEUE_H
|
||||
|
||||
extern "C" {
|
||||
#include <core/containers/queue.h>
|
||||
#include <core/file.h>
|
||||
#include <core/tags/track.h>
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
struct queue;
|
||||
|
||||
|
||||
/**
|
||||
* Enum defining flags that effect a Queue's behavior.
|
||||
*/
|
||||
enum queue_flags {
|
||||
Q_ENABLED = (1 << 0), /* Queue is enabled. */
|
||||
Q_RANDOM = (1 << 1), /* Queue will pick songs randomly. */
|
||||
|
@ -43,15 +41,6 @@ struct queue_ops {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Queues are lists of songs that the user has requested to play next,
|
||||
* although not necessarily in a specific order.
|
||||
*
|
||||
* When writing a Queue to disk: write out the _flags and size values
|
||||
* first, followed by the list of track indexes.
|
||||
*
|
||||
* ... << _flags << _tracks.size() << tracks[N]->index() << ...;
|
||||
*/
|
||||
struct queue {
|
||||
unsigned int q_flags; /* The queue's set of flags. */
|
||||
unsigned int q_length; /* The queue's total runtime (in seconds). */
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
#ifndef OCARINA_GUI_QUEUE_MODEL_H
|
||||
#define OCARINA_GUI_QUEUE_MODEL_H
|
||||
|
||||
extern "C" {
|
||||
#include <core/queue.h>
|
||||
}
|
||||
#include <gtkmm.h>
|
||||
|
||||
class QueueModel : public Gtk::TreeModel, public Glib::Object {
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
#ifndef OCARINA_GUI_QUEUE_TOOLBAR_H
|
||||
#define OCARINA_GUI_QUEUE_TOOLBAR_H
|
||||
|
||||
extern "C" {
|
||||
#include <core/queue.h>
|
||||
}
|
||||
#include <gui/queue/label.h>
|
||||
#include <gui/queue/window.h>
|
||||
#include <gtkmm.h>
|
||||
|
|
|
@ -24,7 +24,7 @@ res += [ CoreTest("filter", "filter.c") ]
|
|||
res += [ CoreTest("idle", "idle.c") ]
|
||||
|
||||
res += SConscript("tags/Sconscript")
|
||||
res += [ CoreTest("queue", "queue.cpp") ]
|
||||
res += [ CoreTest("queue", "queue.c") ]
|
||||
res += [ CoreTest("library", "library.cpp") ]
|
||||
res += [ CoreTest("playlist", "playlist.cpp") ]
|
||||
res += [ CoreTest("deck", "deck.cpp") ]
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/queue.h>
|
||||
extern "C" {
|
||||
#include <core/filter.h>
|
||||
#include <core/queue.h>
|
||||
#include <core/random.h>
|
||||
#include <core/tags/tags.h>
|
||||
}
|
||||
#include "test.h"
|
||||
#include <tests/test.h>
|
||||
|
||||
|
||||
unsigned int count_added = 0;
|
||||
|
@ -89,18 +87,18 @@ static void test_init()
|
|||
test_equal(q.q_cur.it_pos, (unsigned int)-1);
|
||||
test_equal(q.q_flags, 0);
|
||||
test_equal(q.q_length, 0);
|
||||
test_equal(q.q_sort, NULL);
|
||||
test_equal(q.q_ops, NULL);
|
||||
test_equal(queue_next(&q), (struct track *)NULL);
|
||||
test_equal((void *)q.q_sort, NULL);
|
||||
test_equal((void *)q.q_ops, NULL);
|
||||
test_equal((void *)queue_next(&q), (void *)NULL);
|
||||
|
||||
queue_init(&q, Q_ENABLED | Q_RANDOM, &test_ops);
|
||||
|
||||
test_equal(q.q_cur.it_pos, (unsigned int)-1);
|
||||
test_equal(q.q_flags, Q_ENABLED | Q_RANDOM);
|
||||
test_equal(q.q_length, 0);
|
||||
test_equal(q.q_sort, NULL);
|
||||
test_equal(q.q_ops, &test_ops);
|
||||
test_equal(queue_next(&q), (struct track *)NULL);
|
||||
test_equal((void *)q.q_sort, NULL);
|
||||
test_equal((void *)q.q_ops, (void *)&test_ops);
|
||||
test_equal((void *)queue_next(&q), (void *)NULL);
|
||||
}
|
||||
|
||||
static void test_flags()
|
||||
|
@ -109,13 +107,13 @@ static void test_flags()
|
|||
|
||||
queue_init(&q, 0, &test_ops);
|
||||
test_equal(q.q_flags, 0);
|
||||
test_equal(queue_has_flag(&q, Q_ENABLED), false);
|
||||
test_equal(queue_has_flag(&q, Q_RANDOM), false);
|
||||
test_equal(queue_has_flag(&q, Q_REPEAT), false);
|
||||
test_equal(queue_has_flag(&q, Q_NO_SORT), false);
|
||||
test_equal(queue_has_flag(&q, Q_SAVE_FLAGS), false);
|
||||
test_equal(queue_has_flag(&q, Q_SAVE_SORT), false);
|
||||
test_equal(queue_has_flag(&q, Q_ADD_FRONT), false);
|
||||
test_equal(queue_has_flag(&q, Q_ENABLED), (bool)false);
|
||||
test_equal(queue_has_flag(&q, Q_RANDOM), (bool)false);
|
||||
test_equal(queue_has_flag(&q, Q_REPEAT), (bool)false);
|
||||
test_equal(queue_has_flag(&q, Q_NO_SORT), (bool)false);
|
||||
test_equal(queue_has_flag(&q, Q_SAVE_FLAGS), (bool)false);
|
||||
test_equal(queue_has_flag(&q, Q_SAVE_SORT), (bool)false);
|
||||
test_equal(queue_has_flag(&q, Q_ADD_FRONT), (bool)false);
|
||||
|
||||
queue_set_flag(&q, Q_ENABLED);
|
||||
test_equal(q.q_flags, Q_ENABLED);
|
||||
|
@ -131,12 +129,12 @@ static void test_flags()
|
|||
queue_set_flag(&q, Q_REPEAT);
|
||||
queue_set_flag(&q, Q_NO_SORT);
|
||||
queue_set_flag(&q, Q_ADD_FRONT);
|
||||
test_equal(queue_has_flag(&q, Q_ENABLED), true);
|
||||
test_equal(queue_has_flag(&q, Q_RANDOM), true);
|
||||
test_equal(queue_has_flag(&q, Q_REPEAT), true);
|
||||
test_equal(queue_has_flag(&q, Q_NO_SORT), true);
|
||||
test_equal(queue_has_flag(&q, Q_SAVE_FLAGS), true);
|
||||
test_equal(queue_has_flag(&q, Q_ADD_FRONT), true);
|
||||
test_equal(queue_has_flag(&q, Q_ENABLED), (bool)true);
|
||||
test_equal(queue_has_flag(&q, Q_RANDOM), (bool)true);
|
||||
test_equal(queue_has_flag(&q, Q_REPEAT), (bool)true);
|
||||
test_equal(queue_has_flag(&q, Q_NO_SORT), (bool)true);
|
||||
test_equal(queue_has_flag(&q, Q_SAVE_FLAGS), (bool)true);
|
||||
test_equal(queue_has_flag(&q, Q_ADD_FRONT), (bool)true);
|
||||
test_equal(count_flags, 6);
|
||||
|
||||
queue_unset_flag(&q, Q_ENABLED);
|
||||
|
@ -186,7 +184,7 @@ static void test_stress(unsigned int N)
|
|||
ex_length -= track->tr_length * (N / 13);
|
||||
ex_size -= (N / 13);
|
||||
for (i = 0; i < ex_size; i += 11) {
|
||||
test_loop_equal(queue_at(&q, i), track, i);
|
||||
test_loop_equal((void *)queue_at(&q, i), (void *)track, i);
|
||||
queue_remove(&q, i);
|
||||
} test_loop_passed();
|
||||
test_equal(q.q_length, ex_length);
|
||||
|
@ -197,14 +195,15 @@ static void test_stress(unsigned int N)
|
|||
queue_updated(&q, track);
|
||||
test_equal(count_updated, N / 13);
|
||||
|
||||
test_equal(queue_next(&q), NULL);
|
||||
test_equal((void *)queue_next(&q), NULL);
|
||||
test_equal(queue_size(&q), ex_size);
|
||||
|
||||
/* Tracks should not be removed. */
|
||||
queue_set_flag(&q, Q_ENABLED);
|
||||
queue_set_flag(&q, Q_REPEAT);
|
||||
for (i = 0; i < ex_size; i++) {
|
||||
test_loop_equal(queue_next(&q), track_get((i % 11) + 2), i);
|
||||
test_loop_equal((void *)queue_next(&q),
|
||||
(void *)track_get((i % 11) + 2), i);
|
||||
queue_selected(&q, i);
|
||||
test_loop_equal(queue_size(&q), ex_size, i);
|
||||
} test_loop_passed();
|
||||
|
@ -212,7 +211,8 @@ static void test_stress(unsigned int N)
|
|||
/* Tracks should be removed. */
|
||||
queue_unset_flag(&q, Q_REPEAT);
|
||||
for (i = 0; i < ex_size; i++) {
|
||||
test_loop_equal(queue_next(&q), track_get((i % 11) + 2), i);
|
||||
test_loop_equal((void *)queue_next(&q),
|
||||
(void *)track_get((i % 11) + 2), i);
|
||||
test_loop_equal(queue_size(&q), ex_size - (i + 1), i);
|
||||
} test_loop_passed();
|
||||
|
||||
|
@ -234,7 +234,7 @@ static void test_rand_select()
|
|||
|
||||
/* Call next() on an empty queue. */
|
||||
for (i = 0; i < 13; i++) {
|
||||
test_loop_equal(queue_next(&q), NULL, i);
|
||||
test_loop_equal((void *)queue_next(&q), NULL, i);
|
||||
test_loop_equal(queue_size(&q), 0, i);
|
||||
} test_loop_passed();
|
||||
|
||||
|
@ -294,7 +294,7 @@ static void test_rand_select()
|
|||
test_equal(queue_size(&q), 0);
|
||||
|
||||
/* q = { } */
|
||||
test_equal(queue_next(&q), NULL);
|
||||
test_equal((void *)queue_next(&q), NULL);
|
||||
}
|
||||
|
||||
static void test_sorting()
|
||||
|
@ -315,7 +315,7 @@ static void test_sorting()
|
|||
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_not_equal((void *)track, NULL, i);
|
||||
test_loop_equal(track->tr_dbe.dbe_index, 12 - i, i);
|
||||
} test_loop_passed();
|
||||
test_equal(count_sort, 0);
|
||||
|
@ -323,7 +323,7 @@ static void test_sorting()
|
|||
queue_sort(&q, COMPARE_TRACK, true);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_not_equal((void *)track, NULL, i);
|
||||
test_loop_equal(track->tr_dbe.dbe_index, i, i);
|
||||
} test_loop_passed();
|
||||
test_equal(count_sort, 1);
|
||||
|
@ -331,7 +331,7 @@ static void test_sorting()
|
|||
queue_sort(&q, COMPARE_COUNT, true);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_not_equal((void *)track, NULL, i);
|
||||
test_loop_equal(track->tr_dbe.dbe_index, ex_count[i], i);
|
||||
} test_loop_passed();
|
||||
test_equal(count_sort, 2);
|
||||
|
@ -340,7 +340,7 @@ static void test_sorting()
|
|||
queue_sort(&q, COMPARE_TITLE, true);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_not_equal((void *)track, NULL, i);
|
||||
test_loop_equal(track->tr_dbe.dbe_index, ex_count[i], i);
|
||||
} test_loop_passed();
|
||||
test_equal(count_sort, 2);
|
||||
|
@ -349,7 +349,7 @@ static void test_sorting()
|
|||
queue_sort(&q, COMPARE_TITLE, true);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_not_equal((void *)track, NULL, i);
|
||||
test_loop_equal(track->tr_dbe.dbe_index, ex_title[i], i);
|
||||
} test_loop_passed();
|
||||
test_equal(count_sort, 3);
|
||||
|
@ -359,7 +359,7 @@ static void test_sorting()
|
|||
queue_sort(&q, COMPARE_COUNT, false);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_not_equal((void *)track, NULL, i);
|
||||
test_loop_equal(track->tr_dbe.dbe_index, ex_co_ti[i], i);
|
||||
} test_loop_passed();
|
||||
test_equal(count_sort, 6);
|
||||
|
@ -371,7 +371,7 @@ static void test_sorting()
|
|||
queue_sort(&q, COMPARE_TRACK, false);
|
||||
for (i = 0; i < 13; i++) {
|
||||
track = queue_at(&q, i);
|
||||
test_loop_not_equal(track, NULL, i);
|
||||
test_loop_not_equal((void *)track, NULL, i);
|
||||
test_loop_equal(track->tr_dbe.dbe_index, 12 - i, i);
|
||||
} test_loop_passed();
|
||||
test_equal(count_sort, 6);
|
Loading…
Reference in New Issue