core/history: Move history queue into a new file
I think managing this separately from temporary queues will make the code simpler. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
460aeded4e
commit
77d4815eb6
|
@ -4,6 +4,7 @@
|
||||||
#include <core/audio.h>
|
#include <core/audio.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <core/collection.h>
|
#include <core/collection.h>
|
||||||
|
#include <core/history.h>
|
||||||
}
|
}
|
||||||
#include <core/deck.h>
|
#include <core/deck.h>
|
||||||
#include <core/string.h>
|
#include <core/string.h>
|
||||||
|
@ -144,7 +145,7 @@ void audio :: load_track(struct track *track)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_load_track(track, cur_driver->is_playing());
|
_load_track(track, cur_driver->is_playing());
|
||||||
queue_add(deck :: get_queue(), cur_track);
|
queue_add(history_get_queue(), cur_track);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct track *audio :: current_track()
|
struct track *audio :: current_track()
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
*/
|
*/
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <core/collection.h>
|
#include <core/collection.h>
|
||||||
|
#include <core/history.h>
|
||||||
}
|
}
|
||||||
#include <core/deck.h>
|
#include <core/deck.h>
|
||||||
#include <core/file.h>
|
#include <core/file.h>
|
||||||
|
|
||||||
static std::list<TempQueue> queue_deck;
|
static std::list<TempQueue> queue_deck;
|
||||||
static struct queue recent_queue;
|
|
||||||
static struct file deck_file;
|
static struct file deck_file;
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ void deck :: init(struct queue_ops *history_ops, struct queue_ops *temp_ops)
|
||||||
bool upgraded = false;
|
bool upgraded = false;
|
||||||
std::list<TempQueue>::iterator it;
|
std::list<TempQueue>::iterator it;
|
||||||
|
|
||||||
queue_init(&recent_queue, Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_ADD_FRONT, history_ops);
|
queue_init(history_get_queue(), Q_ENABLED | Q_REPEAT | Q_NO_SORT | Q_ADD_FRONT, history_ops);
|
||||||
file_init(&deck_file, "deck", 1);
|
file_init(&deck_file, "deck", 1);
|
||||||
|
|
||||||
if (!file_open(&deck_file, OPEN_READ))
|
if (!file_open(&deck_file, OPEN_READ))
|
||||||
|
@ -219,24 +219,20 @@ struct track *deck :: next()
|
||||||
if (!track)
|
if (!track)
|
||||||
track = queue_next(collection_get_queue());
|
track = queue_next(collection_get_queue());
|
||||||
if (track) {
|
if (track) {
|
||||||
queue_remove_all(&recent_queue, track);
|
queue_remove_all(history_get_queue(), track);
|
||||||
queue_add(&recent_queue, track);
|
queue_add(history_get_queue(), track);
|
||||||
_q_iter_set(&recent_queue.q_tracks, &recent_queue.q_cur, 0);
|
_q_iter_set(&history_get_queue()->q_tracks,
|
||||||
|
&history_get_queue()->q_cur, 0);
|
||||||
}
|
}
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct track *deck :: prev()
|
struct track *deck :: prev()
|
||||||
{
|
{
|
||||||
return queue_next(&recent_queue);
|
return queue_next(history_get_queue());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<TempQueue> &deck :: get_queues()
|
std::list<TempQueue> &deck :: get_queues()
|
||||||
{
|
{
|
||||||
return queue_deck;
|
return queue_deck;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue *deck :: get_queue()
|
|
||||||
{
|
|
||||||
return &recent_queue;
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/history.h>
|
||||||
|
|
||||||
|
static struct queue history_queue;
|
||||||
|
|
||||||
|
|
||||||
|
struct queue *history_get_queue()
|
||||||
|
{
|
||||||
|
return &history_queue;
|
||||||
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2014 (c) Anna Schumaker.
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
*/
|
*/
|
||||||
|
extern "C" {
|
||||||
|
#include <core/history.h>
|
||||||
|
}
|
||||||
#include <core/deck.h>
|
#include <core/deck.h>
|
||||||
#include <gui/tabs.h>
|
#include <gui/tabs.h>
|
||||||
#include <gui/queue/label.h>
|
#include <gui/queue/label.h>
|
||||||
|
@ -11,7 +14,7 @@ private:
|
||||||
HistoryLabel *history_label;
|
HistoryLabel *history_label;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HistoryTab() : Tab(deck :: get_queue())
|
HistoryTab() : Tab(history_get_queue())
|
||||||
{
|
{
|
||||||
tab_builder->add_from_file(gui :: share_file("QueueLabel.ui"));
|
tab_builder->add_from_file(gui :: share_file("QueueLabel.ui"));
|
||||||
tab_builder->get_widget_derived("HistoryLabel", history_label);
|
tab_builder->get_widget_derived("HistoryLabel", history_label);
|
||||||
|
|
|
@ -110,11 +110,6 @@ namespace deck
|
||||||
*/
|
*/
|
||||||
std::list<TempQueue> &get_queues();
|
std::list<TempQueue> &get_queues();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The queue of recent tracks.
|
|
||||||
*/
|
|
||||||
queue *get_queue();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* OCARINA_CORE_DECK_H */
|
#endif /* OCARINA_CORE_DECK_H */
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#ifndef OCARINA_CORE_HISTORY_H
|
||||||
|
#define OCARINA_CORE_HISTORY_H
|
||||||
|
|
||||||
|
#include <core/queue.h>
|
||||||
|
|
||||||
|
/* Called to access the queue of recent tracks. */
|
||||||
|
struct queue *history_get_queue();
|
||||||
|
|
||||||
|
#endif /* OCARINA_CORE_HISTORY_H */
|
|
@ -6,6 +6,7 @@ deck
|
||||||
driver
|
driver
|
||||||
file
|
file
|
||||||
filter
|
filter
|
||||||
|
history
|
||||||
idle
|
idle
|
||||||
index
|
index
|
||||||
playlist
|
playlist
|
||||||
|
|
|
@ -40,6 +40,7 @@ res += SConscript("tags/Sconscript")
|
||||||
res += [ CoreTest("queue") ]
|
res += [ CoreTest("queue") ]
|
||||||
res += [ CoreTest("playlist") ]
|
res += [ CoreTest("playlist") ]
|
||||||
res += [ CoreTest("collection") ]
|
res += [ CoreTest("collection") ]
|
||||||
|
res += [ CoreTest("history") ]
|
||||||
res += [ CoreTest("deck") ]
|
res += [ CoreTest("deck") ]
|
||||||
res += [ CoreTest("audio") ]
|
res += [ CoreTest("audio") ]
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <core/collection.h>
|
#include <core/collection.h>
|
||||||
#include <core/filter.h>
|
#include <core/filter.h>
|
||||||
|
#include <core/history.h>
|
||||||
#include <core/playlist.h>
|
#include <core/playlist.h>
|
||||||
#include <core/tags/tags.h>
|
#include <core/tags/tags.h>
|
||||||
}
|
}
|
||||||
|
@ -104,7 +105,7 @@ static void test_create_mv_destroy()
|
||||||
static void test_next_prev()
|
static void test_next_prev()
|
||||||
{
|
{
|
||||||
std::list<TempQueue>::iterator it = deck :: get_queues().begin();
|
std::list<TempQueue>::iterator it = deck :: get_queues().begin();
|
||||||
queue *q = deck :: get_queue();
|
queue *q = history_get_queue();
|
||||||
queue *q0 = deck :: get(0);
|
queue *q0 = deck :: get(0);
|
||||||
queue *q1 = deck :: get(1);
|
queue *q1 = deck :: get(1);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2015 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#include <core/history.h>
|
||||||
|
#include <tests/test.h>
|
||||||
|
|
||||||
|
static void test_init()
|
||||||
|
{
|
||||||
|
struct queue *q = history_get_queue();
|
||||||
|
|
||||||
|
test_not_equal((void *)q, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
DECLARE_UNIT_TESTS(
|
||||||
|
UNIT_TEST("History Initialization", test_init),
|
||||||
|
);
|
Loading…
Reference in New Issue