2012-08-25 10:24:34 +02:00
|
|
|
#include "config.h"
|
2013-01-04 20:50:00 +01:00
|
|
|
#include "Queue.hxx"
|
2011-07-19 00:34:33 +02:00
|
|
|
#include "song.h"
|
2013-01-02 22:52:08 +01:00
|
|
|
#include "Directory.hxx"
|
2012-08-25 10:24:34 +02:00
|
|
|
|
2013-01-30 22:53:12 +01:00
|
|
|
#include <glib.h>
|
|
|
|
|
2013-01-02 23:06:20 +01:00
|
|
|
Directory detached_root;
|
2012-08-25 10:24:34 +02:00
|
|
|
|
2013-01-03 02:12:34 +01:00
|
|
|
Directory::Directory() {}
|
2013-01-03 01:36:28 +01:00
|
|
|
Directory::~Directory() {}
|
|
|
|
|
2012-08-25 10:24:34 +02:00
|
|
|
struct song *
|
|
|
|
song_dup_detached(const struct song *src)
|
|
|
|
{
|
2013-01-02 22:52:08 +01:00
|
|
|
return const_cast<song *>(src);
|
2012-08-25 10:24:34 +02:00
|
|
|
}
|
2011-07-19 00:34:33 +02:00
|
|
|
|
|
|
|
void
|
2013-01-30 22:53:12 +01:00
|
|
|
song_free(gcc_unused struct song *song)
|
2011-07-19 00:34:33 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-30 22:53:12 +01:00
|
|
|
gcc_unused
|
2011-07-19 00:34:33 +02:00
|
|
|
static void
|
|
|
|
dump_order(const struct queue *queue)
|
|
|
|
{
|
2013-01-06 21:33:58 +01:00
|
|
|
g_printerr("queue length=%u, order:\n", queue->GetLength());
|
|
|
|
for (unsigned i = 0; i < queue->GetLength(); ++i)
|
2011-07-19 00:34:33 +02:00
|
|
|
g_printerr(" [%u] -> %u (prio=%u)\n", i, queue->order[i],
|
|
|
|
queue->items[queue->order[i]].priority);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-01-06 21:33:58 +01:00
|
|
|
check_descending_priority(const struct queue *queue,
|
2011-07-19 00:34:33 +02:00
|
|
|
unsigned start_order)
|
|
|
|
{
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(start_order < queue->GetLength());
|
2011-07-19 00:34:33 +02:00
|
|
|
|
|
|
|
uint8_t last_priority = 0xff;
|
2013-01-06 21:33:58 +01:00
|
|
|
for (unsigned order = start_order; order < queue->GetLength(); ++order) {
|
|
|
|
unsigned position = queue->OrderToPosition(order);
|
2011-07-19 00:34:33 +02:00
|
|
|
uint8_t priority = queue->items[position].priority;
|
|
|
|
assert(priority <= last_priority);
|
2011-09-16 08:07:41 +02:00
|
|
|
(void)last_priority;
|
2011-07-19 00:34:33 +02:00
|
|
|
last_priority = priority;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-01-30 22:53:12 +01:00
|
|
|
main(gcc_unused int argc, gcc_unused char **argv)
|
2011-07-19 00:34:33 +02:00
|
|
|
{
|
2013-01-06 21:33:58 +01:00
|
|
|
static struct song songs[16];
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2013-01-06 14:58:54 +01:00
|
|
|
struct queue queue(32);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < G_N_ELEMENTS(songs); ++i)
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.Append(&songs[i], 0);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.GetLength() == G_N_ELEMENTS(songs));
|
2011-07-19 00:34:33 +02:00
|
|
|
|
|
|
|
/* priority=10 for 4 items */
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.SetPriorityRange(4, 8, 10, -1);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
|
|
|
queue.random = true;
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.ShuffleOrder();
|
2011-07-19 00:34:33 +02:00
|
|
|
check_descending_priority(&queue, 0);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 4; ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) >= 4);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 4; i < 8; ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) < 4);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 8; i < G_N_ELEMENTS(songs); ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) >= 4);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* priority=50 one more item */
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.SetPriorityRange(15, 16, 50, -1);
|
2011-07-19 00:34:33 +02:00
|
|
|
check_descending_priority(&queue, 0);
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(15) == 0);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < 4; ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) >= 4);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 4; i < 8; ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) >= 1 &&
|
|
|
|
queue.PositionToOrder(i) < 5);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 8; i < 15; ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) >= 5);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* priority=20 for one of the 4 priority=10 items */
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.SetPriorityRange(3, 4, 20, -1);
|
2011-07-19 00:34:33 +02:00
|
|
|
check_descending_priority(&queue, 0);
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(3) == 1);
|
|
|
|
assert(queue.PositionToOrder(15) == 0);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < 3; ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) >= 5);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 4; i < 8; ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) >= 2 &&
|
|
|
|
queue.PositionToOrder(i) < 6);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 8; i < 15; ++i) {
|
2013-01-06 21:33:58 +01:00
|
|
|
assert(queue.PositionToOrder(i) >= 6);
|
2011-07-19 00:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* priority=20 for another one of the 4 priority=10 items;
|
|
|
|
pass "after_order" (with priority=10) and see if it's moved
|
|
|
|
after that one */
|
|
|
|
|
|
|
|
unsigned current_order = 4;
|
|
|
|
unsigned current_position =
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.OrderToPosition(current_order);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
|
|
|
unsigned a_order = 3;
|
2013-01-06 21:33:58 +01:00
|
|
|
unsigned a_position = queue.OrderToPosition(a_order);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(queue.items[a_position].priority == 10);
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.SetPriority(a_position, 20, current_order);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
current_order = queue.PositionToOrder(current_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(current_order == 3);
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
a_order = queue.PositionToOrder(a_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(a_order == 4);
|
|
|
|
|
|
|
|
check_descending_priority(&queue, current_order + 1);
|
|
|
|
|
|
|
|
/* priority=70 for one of the last items; must be inserted
|
|
|
|
right after the current song, before the priority=20 one we
|
|
|
|
just created */
|
|
|
|
|
|
|
|
unsigned b_order = 10;
|
2013-01-06 21:33:58 +01:00
|
|
|
unsigned b_position = queue.OrderToPosition(b_order);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(queue.items[b_position].priority == 0);
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.SetPriority(b_position, 70, current_order);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
current_order = queue.PositionToOrder(current_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(current_order == 3);
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
b_order = queue.PositionToOrder(b_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(b_order == 4);
|
|
|
|
|
|
|
|
check_descending_priority(&queue, current_order + 1);
|
|
|
|
|
|
|
|
/* priority=60 for the old prio50 item; must not be moved,
|
|
|
|
because it's before the current song, and it's status
|
|
|
|
hasn't changed (it was already higher before) */
|
|
|
|
|
|
|
|
unsigned c_order = 0;
|
2013-01-06 21:33:58 +01:00
|
|
|
unsigned c_position = queue.OrderToPosition(c_order);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(queue.items[c_position].priority == 50);
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.SetPriority(c_position, 60, current_order);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
current_order = queue.PositionToOrder(current_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(current_order == 3);
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
c_order = queue.PositionToOrder(c_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(c_order == 0);
|
|
|
|
|
|
|
|
/* move the prio=20 item back */
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
a_order = queue.PositionToOrder(a_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(a_order == 5);
|
|
|
|
assert(queue.items[a_position].priority == 20);
|
2013-01-06 21:33:58 +01:00
|
|
|
queue.SetPriority(a_position, 5, current_order);
|
2011-07-19 00:34:33 +02:00
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
current_order = queue.PositionToOrder(current_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(current_order == 3);
|
|
|
|
|
2013-01-06 21:33:58 +01:00
|
|
|
a_order = queue.PositionToOrder(a_position);
|
2011-07-19 00:34:33 +02:00
|
|
|
assert(a_order == 6);
|
|
|
|
}
|