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
|
|
|
|
2014-05-31 09:09:44 -04:00
|
|
|
static std::list<TempQueue> queue_deck;
|
2015-09-10 10:33:24 -04:00
|
|
|
static struct file deck_file;
|
2014-05-26 22:20:07 -04:00
|
|
|
|
|
|
|
|
2015-11-29 17:34:21 -05:00
|
|
|
void TempQueue :: write(file &file)
|
|
|
|
{
|
2015-12-01 11:17:25 -05:00
|
|
|
file_writef(&file, "%u %zu", q_flags, queue_size(this));
|
|
|
|
for (unsigned int i = 0; i < queue_size(this); i++)
|
|
|
|
file_writef(&file, " %u", queue_at(this, i)->tr_dbe.dbe_index);
|
2015-11-29 17:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TempQueue :: read(file &file)
|
|
|
|
{
|
|
|
|
unsigned int n, id;
|
|
|
|
file_readf(&file, "%u %u", &q_flags, &n);
|
|
|
|
for (unsigned int i = 0; i < n; i++) {
|
|
|
|
file_readf(&file, "%u", &id);
|
2015-12-01 11:17:25 -05:00
|
|
|
queue_add(this, track_get(id));
|
2015-11-29 17:34:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
unsigned int TempQueue :: add(struct track *track)
|
2014-05-31 09:09:44 -04:00
|
|
|
{
|
2015-11-25 08:24:04 -05:00
|
|
|
unsigned int res = queue_add(this, track);
|
2014-05-31 09:09:44 -04:00
|
|
|
deck :: write();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
void TempQueue :: del(struct track *track)
|
2014-05-31 09:09:44 -04:00
|
|
|
{
|
2015-11-29 16:34:51 -05:00
|
|
|
queue_remove_all(this, track);
|
2014-05-31 09:09:44 -04:00
|
|
|
deck :: write();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TempQueue :: del(unsigned int id)
|
|
|
|
{
|
2015-11-28 15:24:03 -05:00
|
|
|
queue_remove(this, id);
|
2014-05-31 09:09:44 -04:00
|
|
|
deck :: write();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 09:42:34 -05:00
|
|
|
static unsigned int __tempq_index(struct queue *queue)
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
std::list<TempQueue>::iterator it;
|
|
|
|
|
|
|
|
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
|
|
|
if (&(*it) == queue)
|
|
|
|
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-13 09:27:52 -05:00
|
|
|
unsigned int num, i;
|
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 09:05:54 -05:00
|
|
|
((TempQueue *)tempq_alloc(NULL, 0))->read(deck_file);
|
2015-12-13 09:27:52 -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()
|
|
|
|
{
|
|
|
|
while (queue_deck.size() > 0)
|
|
|
|
queue_deck.erase(queue_deck.begin());
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:05:54 -05:00
|
|
|
struct queue *tempq_alloc(struct queue_ops *ops, unsigned int flags)
|
|
|
|
{
|
|
|
|
struct queue *queue;
|
|
|
|
|
|
|
|
queue_deck.push_back(TempQueue());
|
|
|
|
queue = &queue_deck.back();
|
|
|
|
queue_init(queue, flags | Q_ENABLED | Q_SAVE_FLAGS | Q_SAVE_SORT, ops);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:26:58 -05:00
|
|
|
void tempq_free(struct queue *queue)
|
|
|
|
{
|
|
|
|
std::list<TempQueue>::iterator it;
|
|
|
|
|
|
|
|
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
|
|
|
if (&(*it) == queue) {
|
2015-12-14 10:24:36 -05:00
|
|
|
queue_deinit(&(*it));
|
2015-12-14 09:26:58 -05:00
|
|
|
queue_deck.erase(it);
|
|
|
|
deck :: write();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:50:38 -05:00
|
|
|
struct queue *tempq_get(unsigned int index)
|
|
|
|
{
|
|
|
|
std::list<TempQueue>::iterator it;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
it = queue_deck.begin();
|
|
|
|
for (i = 0; i < queue_deck.size(); i++) {
|
|
|
|
if (i == index)
|
|
|
|
return &(*it);
|
|
|
|
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);
|
|
|
|
std::list<TempQueue>::iterator it_old = queue_deck.begin();
|
|
|
|
std::list<TempQueue>::iterator it_new = queue_deck.begin();
|
|
|
|
|
|
|
|
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);
|
|
|
|
deck :: write();
|
|
|
|
}
|
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
struct track *tempq_next()
|
|
|
|
{
|
|
|
|
struct track *track = NULL;
|
|
|
|
std::list<TempQueue>::iterator it;
|
|
|
|
|
|
|
|
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
|
|
|
if (queue_has_flag(&(*it), Q_ENABLED) == false)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
track = queue_next(&(*it));
|
|
|
|
if (queue_size(&(*it)) == 0)
|
|
|
|
tempq_free(&(*it));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
2014-01-24 21:43:18 -05:00
|
|
|
void deck :: write()
|
2013-12-23 10:37:22 -05:00
|
|
|
{
|
2014-05-31 09:09:44 -04:00
|
|
|
std::list<TempQueue>::iterator it;
|
2013-12-23 10:37:22 -05:00
|
|
|
|
2015-09-10 09:46:33 -04:00
|
|
|
if (!file_open(&deck_file, OPEN_WRITE))
|
2014-05-26 22:20:07 -04:00
|
|
|
return;
|
2014-01-26 14:44:56 -05:00
|
|
|
|
2015-10-08 09:41:51 -04:00
|
|
|
file_writef(&deck_file, "%zu\n", queue_deck.size());
|
2014-05-26 22:20:07 -04:00
|
|
|
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
|
2014-01-24 21:43:18 -05:00
|
|
|
it->write(deck_file);
|
2015-10-08 09:41:51 -04:00
|
|
|
file_writef(&deck_file, "\n");
|
2013-12-23 10:37:22 -05:00
|
|
|
}
|
2014-05-26 22:20:07 -04:00
|
|
|
|
2015-09-10 09:12:48 -04:00
|
|
|
file_close(&deck_file);
|
2013-12-23 10:37:22 -05:00
|
|
|
}
|
|
|
|
|
2015-11-24 09:08:20 -05:00
|
|
|
void deck :: save(struct queue *queue, enum queue_flags flag)
|
|
|
|
{
|
|
|
|
deck :: write();
|
|
|
|
}
|
|
|
|
|
2015-12-14 10:24:36 -05:00
|
|
|
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
|
|
|
}
|