core/queue: Move queue_next() out of the queue struct
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
6bd625f65b
commit
331e56716a
|
@ -207,14 +207,14 @@ struct track *deck :: next()
|
|||
if (it->has_flag(Q_ENABLED) == false)
|
||||
continue;
|
||||
|
||||
track = it->next();
|
||||
track = queue_next(&(*it));
|
||||
if (it->size() == 0)
|
||||
_destroy(it);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!track)
|
||||
track = collection :: get_queue()->next();
|
||||
track = queue_next(collection :: get_queue());
|
||||
if (track)
|
||||
recent_queue.add(track);
|
||||
return track;
|
||||
|
@ -222,7 +222,7 @@ struct track *deck :: next()
|
|||
|
||||
struct track *deck :: prev()
|
||||
{
|
||||
return recent_queue.next();
|
||||
return queue_next(&recent_queue);
|
||||
}
|
||||
|
||||
std::list<TempQueue> &deck :: get_queues()
|
||||
|
|
|
@ -158,24 +158,25 @@ void queue_selected(struct queue *queue, unsigned int index)
|
|||
queue->del(index);
|
||||
}
|
||||
|
||||
struct track *queue :: next()
|
||||
struct track *queue_next(struct queue *queue)
|
||||
{
|
||||
unsigned int size = queue->size();
|
||||
struct track *res;
|
||||
|
||||
if (!(q_flags & Q_ENABLED))
|
||||
if (!(queue->q_flags & Q_ENABLED))
|
||||
return NULL;
|
||||
else if (q_tracks.size() == 0)
|
||||
else if (size == 0)
|
||||
return NULL;
|
||||
else if (q_tracks.size() == 1)
|
||||
q_cur = 0;
|
||||
else if (q_flags & Q_RANDOM)
|
||||
q_cur += random_range(1, q_tracks.size() / 2);
|
||||
else if (size == 1)
|
||||
queue->q_cur = 0;
|
||||
else if (queue->has_flag(Q_RANDOM))
|
||||
queue->q_cur += random_range(1, size / 2);
|
||||
else
|
||||
q_cur++;
|
||||
queue->q_cur++;
|
||||
|
||||
q_cur %= q_tracks.size();
|
||||
res = q_tracks[q_cur];
|
||||
queue_selected(this, q_cur);
|
||||
queue->q_cur %= size;
|
||||
res = queue->q_tracks[queue->q_cur];
|
||||
queue_selected(queue, queue->q_cur);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -163,16 +163,6 @@ struct queue {
|
|||
*/
|
||||
void updated(struct track *);
|
||||
|
||||
/**
|
||||
* Pick the next track from the queue. If Q_RANDOM is set then a
|
||||
* random Track will be returned, otherwise _cur will be incremented
|
||||
* and used to pick the next Track. If Q_REPEAT is not set then
|
||||
* the chosen track will be removed from the queue.
|
||||
*
|
||||
* @return The next Track on the queue, or NULL if the Queue is empty.
|
||||
*/
|
||||
struct track *next();
|
||||
|
||||
|
||||
/**
|
||||
* Find the size of the queue.
|
||||
|
@ -207,4 +197,7 @@ struct queue {
|
|||
/* Called to tell the queue that a specific index has been selected. */
|
||||
void queue_selected(struct queue *, unsigned int);
|
||||
|
||||
/* Called to pick the next track from the queue. */
|
||||
struct track *queue_next(struct queue *);
|
||||
|
||||
#endif /* OCARINA_CORE_QUEUE_H */
|
||||
|
|
|
@ -64,7 +64,7 @@ static void test_init()
|
|||
test_equal(q.q_flags, 0);
|
||||
test_equal(q.q_length, 0);
|
||||
test_equal(q.q_sort.size(), (size_t)0);
|
||||
test_equal(q.next(), (struct track *)NULL);
|
||||
test_equal(queue_next(&q), (struct track *)NULL);
|
||||
test_not_equal(q.q_notify, NULL);
|
||||
|
||||
q = queue(Q_ENABLED | Q_RANDOM);
|
||||
|
@ -74,7 +74,7 @@ static void test_init()
|
|||
test_equal(q.q_flags, Q_ENABLED | Q_RANDOM);
|
||||
test_equal(q.q_length, 0);
|
||||
test_equal(q.q_sort.size(), 0);
|
||||
test_equal(q.next(), (struct track *)NULL);
|
||||
test_equal(queue_next(&q), (struct track *)NULL);
|
||||
test_equal(q.q_notify, &test_notifier);
|
||||
}
|
||||
|
||||
|
@ -151,14 +151,14 @@ static void test_stress(unsigned int N)
|
|||
q.updated(track);
|
||||
test_equal(count_updated, N / 13);
|
||||
|
||||
test_equal(q.next(), NULL);
|
||||
test_equal(queue_next(&q), NULL);
|
||||
test_equal(q.size(), ex_size);
|
||||
|
||||
/* Tracks should not be removed. */
|
||||
q.set_flag(Q_ENABLED);
|
||||
q.set_flag(Q_REPEAT);
|
||||
for (i = 0; i < ex_size; i++) {
|
||||
test_loop_equal(q.next(), track_get((i % 11) + 2), i);
|
||||
test_loop_equal(queue_next(&q), track_get((i % 11) + 2), i);
|
||||
queue_selected(&q, i);
|
||||
test_loop_equal(q.size(), ex_size, i);
|
||||
} test_loop_passed();
|
||||
|
@ -166,7 +166,7 @@ static void test_stress(unsigned int N)
|
|||
/* Tracks should be removed. */
|
||||
q.unset_flag(Q_REPEAT);
|
||||
for (i = 0; i < ex_size; i++) {
|
||||
test_loop_equal(q.next(), track_get((i % 11) + 2), i);
|
||||
test_loop_equal(queue_next(&q), track_get((i % 11) + 2), i);
|
||||
test_loop_equal(q.size(), ex_size - (i + 1), i);
|
||||
} test_loop_passed();
|
||||
|
||||
|
@ -187,7 +187,7 @@ static void test_rand_select()
|
|||
|
||||
/* Call next() on an empty queue. */
|
||||
for (i = 0; i < 13; i++) {
|
||||
test_loop_equal(q.next(), NULL, i);
|
||||
test_loop_equal(queue_next(&q), NULL, i);
|
||||
test_loop_equal(q.size(), 0, i);
|
||||
} test_loop_passed();
|
||||
|
||||
|
@ -202,52 +202,52 @@ static void test_rand_select()
|
|||
*/
|
||||
|
||||
/* rand() = 2, q = { <>, 0, [1], 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 1);
|
||||
test_equal(queue_next(&q)->tr_dbe.dbe_index, 1);
|
||||
|
||||
/* select = 6, q = { <0>, 2, 3, 4, 5, 6, (7), 8, 9, 10, 11, 12 } */
|
||||
queue_selected(&q, 6);
|
||||
test_equal(q.size(), 11);
|
||||
|
||||
/* rand() = 3, q = { 0, 2, 3, 4, 5, <6>, 8, 9, [10], 11, 12 } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 10);
|
||||
test_equal(queue_next(&q)->tr_dbe.dbe_index, 10);
|
||||
|
||||
/* select = 7, q = { 0, 2, 3, 4, 5, 6, 8, (<9>), 11, 12 } */
|
||||
queue_selected(&q, 7);
|
||||
test_equal(q.size(), 9);
|
||||
|
||||
/* rand() = 4, q = { 0, 2, 3, 4, 5, 6, <8>, [11], 12 } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 11);
|
||||
test_equal(queue_next(&q)->tr_dbe.dbe_index, 11);
|
||||
|
||||
/* select = 2, q = { 0, 2, (3), 4, 5, 6, <8>, 12 } */
|
||||
queue_selected(&q, 2);
|
||||
test_equal(q.size(), 7);
|
||||
|
||||
/* rand() = 1, q = { 0, <2>, [4], 5, 6, 8, 12 } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 4);
|
||||
test_equal(queue_next(&q)->tr_dbe.dbe_index, 4);
|
||||
|
||||
/* select = 1, q = { 0, <2>, 5, 6, 8, (12) } */
|
||||
queue_selected(&q, 5);
|
||||
test_equal(q.size(), 5);
|
||||
|
||||
/* rand() = 1, q = { [0], 2, 5, 6, <8>, } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 0);
|
||||
test_equal(queue_next(&q)->tr_dbe.dbe_index, 0);
|
||||
|
||||
/* rand() = 1, q = { <>, [2], 5, 6, 8, } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 2);
|
||||
test_equal(queue_next(&q)->tr_dbe.dbe_index, 2);
|
||||
|
||||
/* select = 1, q = { <>, 5, (6), 8, } */
|
||||
queue_selected(&q, 1);
|
||||
test_equal(q.size(), 2);
|
||||
|
||||
/* rand() = 1, q = { <5>, [8], } */
|
||||
test_equal(q.next()->tr_dbe.dbe_index, 8);
|
||||
test_equal(queue_next(&q)->tr_dbe.dbe_index, 8);
|
||||
|
||||
/* select = 1, q = { <[5]> } */
|
||||
queue_selected(&q, 0);
|
||||
test_equal(q.size(), 0);
|
||||
|
||||
/* q = { } */
|
||||
test_equal(q.next(), NULL);
|
||||
test_equal(queue_next(&q), NULL);
|
||||
}
|
||||
|
||||
static void test_sorting()
|
||||
|
|
Loading…
Reference in New Issue