2014-09-13 10:26:17 -04:00
|
|
|
/**
|
2013-12-22 22:21:19 -05:00
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2015-12-07 09:35:58 -05:00
|
|
|
extern "C" {
|
|
|
|
#include <core/collection.h>
|
2015-12-12 09:04:25 -05:00
|
|
|
#include <core/history.h>
|
2015-12-07 09:35:58 -05:00
|
|
|
}
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/deck.h>
|
|
|
|
#include <core/file.h>
|
2013-12-22 22:21:19 -05:00
|
|
|
|
2015-12-14 12:10:10 -05:00
|
|
|
static std::list<struct queue *> queue_deck;
|
2015-09-10 10:33:24 -04:00
|
|
|
static struct file deck_file;
|
2014-05-26 22:20:07 -04:00
|
|
|
|
|
|
|
|
2015-12-14 09:42:34 -05:00
|
|
|
static unsigned int __tempq_index(struct queue *queue)
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
2015-12-14 12:10:10 -05:00
|
|
|
std::list<struct queue *>::iterator it;
|
2015-12-14 09:42:34 -05:00
|
|
|
|
|
|
|
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
2015-12-14 12:10:10 -05:00
|
|
|
if (*it == queue)
|
2015-12-14 09:42:34 -05:00
|
|
|
return i;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return queue_deck.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-13 09:27:52 -05:00
|
|
|
void tempq_init(struct queue_ops *ops)
|
2013-12-23 10:37:22 -05:00
|
|
|
{
|
2015-12-14 11:18:31 -05:00
|
|
|
unsigned int flags, count, j, id;
|
2015-12-13 09:27:52 -05:00
|
|
|
unsigned int num, i;
|
2015-12-14 11:18:31 -05:00
|
|
|
struct queue *queue;
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2015-09-10 10:33:24 -04:00
|
|
|
file_init(&deck_file, "deck", 1);
|
2015-09-10 09:46:33 -04:00
|
|
|
if (!file_open(&deck_file, OPEN_READ))
|
2014-01-24 21:43:18 -05:00
|
|
|
return;
|
2015-12-13 09:27:52 -05:00
|
|
|
if (file_version(&deck_file) < 1)
|
|
|
|
return;
|
2014-01-16 22:25:04 -05:00
|
|
|
|
2015-10-08 11:16:38 -04:00
|
|
|
file_readf(&deck_file, "%u", &num);
|
2015-12-13 09:27:52 -05:00
|
|
|
for (i = 0; i < num; i++) {
|
2015-12-14 11:18:31 -05:00
|
|
|
file_readf(&deck_file, "%u %u", &flags, &count);
|
|
|
|
queue = tempq_alloc(NULL, flags);
|
|
|
|
for (j = 0; j < count; j++) {
|
|
|
|
file_readf(&deck_file, "%u", &id);
|
|
|
|
queue_add(queue, track_get(id));
|
|
|
|
}
|
2015-12-14 12:10:10 -05:00
|
|
|
queue_deck.back()->q_ops = ops;
|
2015-11-24 09:08:20 -05:00
|
|
|
}
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&deck_file);
|
2013-12-23 10:37:22 -05:00
|
|
|
}
|
|
|
|
|
2015-12-14 10:56:39 -05:00
|
|
|
void tempq_deinit()
|
|
|
|
{
|
2015-12-14 12:10:10 -05:00
|
|
|
while (queue_deck.size() > 0) {
|
|
|
|
queue_deinit(*queue_deck.begin());
|
|
|
|
delete *queue_deck.begin();
|
2015-12-14 10:56:39 -05:00
|
|
|
queue_deck.erase(queue_deck.begin());
|
2015-12-14 12:10:10 -05:00
|
|
|
}
|
2015-12-14 10:56:39 -05:00
|
|
|
}
|
|
|
|
|
2015-12-14 11:08:17 -05:00
|
|
|
void tempq_save(struct queue *queue, enum queue_flags flag)
|
|
|
|
{
|
2015-12-14 12:10:10 -05:00
|
|
|
std::list<struct queue *>::iterator it;
|
2015-12-14 11:08:17 -05:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (!file_open(&deck_file, OPEN_WRITE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
file_writef(&deck_file, "%zu\n", queue_deck.size());
|
|
|
|
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
2015-12-14 12:10:10 -05:00
|
|
|
file_writef(&deck_file, "%u %zu", (*it)->q_flags, queue_size(*it));
|
|
|
|
for (i = 0; i < queue_size(*it); i++) {
|
2015-12-14 11:08:17 -05:00
|
|
|
file_writef(&deck_file, " %u",
|
2015-12-14 12:10:10 -05:00
|
|
|
queue_at(*it, i)->tr_dbe.dbe_index);
|
2015-12-14 11:08:17 -05:00
|
|
|
}
|
|
|
|
file_writef(&deck_file, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
file_close(&deck_file);
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:05:54 -05:00
|
|
|
struct queue *tempq_alloc(struct queue_ops *ops, unsigned int flags)
|
|
|
|
{
|
2015-12-14 12:10:10 -05:00
|
|
|
struct queue *queue = new struct queue;
|
2015-12-14 09:05:54 -05:00
|
|
|
|
2015-12-14 12:10:10 -05:00
|
|
|
queue_deck.push_back(queue);
|
2015-12-14 09:05:54 -05:00
|
|
|
queue_init(queue, flags | Q_ENABLED | Q_SAVE_FLAGS | Q_SAVE_SORT, ops);
|
2015-12-14 11:08:17 -05:00
|
|
|
tempq_save(queue, Q_ENABLED);
|
2015-12-14 09:05:54 -05:00
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:26:58 -05:00
|
|
|
void tempq_free(struct queue *queue)
|
|
|
|
{
|
2015-12-14 12:10:10 -05:00
|
|
|
std::list<struct queue *>::iterator it;
|
2015-12-14 09:26:58 -05:00
|
|
|
|
|
|
|
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
2015-12-14 12:10:10 -05:00
|
|
|
if (*it == queue) {
|
2015-12-14 09:26:58 -05:00
|
|
|
queue_deck.erase(it);
|
2015-12-14 12:10:10 -05:00
|
|
|
tempq_save(queue, Q_ENABLED);
|
|
|
|
queue_deinit(queue);
|
|
|
|
delete queue;
|
2015-12-14 09:26:58 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:50:38 -05:00
|
|
|
struct queue *tempq_get(unsigned int index)
|
|
|
|
{
|
2015-12-14 12:10:10 -05:00
|
|
|
std::list<struct queue *>::iterator it;
|
2015-12-14 09:50:38 -05:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
it = queue_deck.begin();
|
|
|
|
for (i = 0; i < queue_deck.size(); i++) {
|
|
|
|
if (i == index)
|
2015-12-14 12:10:10 -05:00
|
|
|
return *it;
|
2015-12-14 09:50:38 -05:00
|
|
|
it++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-14 10:01:08 -05:00
|
|
|
void tempq_move(struct queue *queue, unsigned int index)
|
|
|
|
{
|
|
|
|
unsigned int old_pos = __tempq_index(queue);
|
2015-12-14 12:10:10 -05:00
|
|
|
std::list<struct queue *>::iterator it_old = queue_deck.begin();
|
|
|
|
std::list<struct queue *>::iterator it_new = queue_deck.begin();
|
2015-12-14 10:01:08 -05:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < queue_deck.size(); i++) {
|
|
|
|
if (i < old_pos)
|
|
|
|
it_old++;
|
|
|
|
|
|
|
|
if (i < index)
|
|
|
|
it_new++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index > old_pos)
|
|
|
|
it_new++;
|
|
|
|
|
|
|
|
queue_deck.splice(it_new, queue_deck, it_old);
|
2015-12-14 11:08:17 -05:00
|
|
|
tempq_save(queue, Q_ENABLED);
|
2015-12-14 10:01:08 -05:00
|
|
|
}
|
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
struct track *tempq_next()
|
|
|
|
{
|
|
|
|
struct track *track = NULL;
|
2015-12-14 12:10:10 -05:00
|
|
|
std::list<struct queue *>::iterator it;
|
2015-12-14 10:24:36 -05:00
|
|
|
|
|
|
|
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
2015-12-14 12:10:10 -05:00
|
|
|
if (queue_has_flag(*it, Q_ENABLED) == false)
|
2015-12-14 10:24:36 -05:00
|
|
|
continue;
|
|
|
|
|
2015-12-14 12:10:10 -05:00
|
|
|
track = queue_next(*it);
|
|
|
|
if (queue_size(*it) == 0)
|
|
|
|
tempq_free(*it);
|
2015-12-14 10:24:36 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int tempq_count()
|
2013-12-23 10:22:37 -05:00
|
|
|
{
|
2015-12-14 10:24:36 -05:00
|
|
|
return queue_deck.size();
|
2014-05-26 22:20:07 -04:00
|
|
|
}
|