2014-10-17 09:42:45 -04:00
|
|
|
/**
|
2013-12-31 15:44:44 -05:00
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2014-06-21 09:37:47 -04:00
|
|
|
#ifndef OCARINA_CORE_QUEUE_H
|
|
|
|
#define OCARINA_CORE_QUEUE_H
|
2013-12-31 15:44:44 -05:00
|
|
|
|
2015-10-09 13:55:34 -04:00
|
|
|
extern "C" {
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/file.h>
|
2014-12-02 08:24:36 -05:00
|
|
|
#include <core/tags/track.h>
|
2015-11-12 10:42:21 -05:00
|
|
|
}
|
2014-05-11 19:52:08 -04:00
|
|
|
|
2013-12-31 15:44:44 -05:00
|
|
|
#include <vector>
|
2014-01-26 12:12:01 -05:00
|
|
|
#include <list>
|
2013-12-31 15:44:44 -05:00
|
|
|
|
2014-12-07 09:57:43 -05:00
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
/**
|
2014-12-07 09:57:43 -05:00
|
|
|
* Enum defining flags that effect a Queue's behavior.
|
2014-10-17 09:42:45 -04:00
|
|
|
*/
|
2014-04-01 20:28:19 -04:00
|
|
|
enum queue_flags {
|
2015-11-23 08:36:29 -05:00
|
|
|
Q_ENABLED = (1 << 0), /* Queue is enabled. */
|
|
|
|
Q_RANDOM = (1 << 1), /* Queue will pick songs randomly. */
|
|
|
|
Q_REPEAT = (1 << 2), /* Queue will not remove songs when picked. */
|
|
|
|
Q_NO_SORT = (1 << 3), /* Queue will not be sorted. */
|
|
|
|
Q_SAVE_FLAGS = (1 << 4), /* Queue will be saved when flags change. */
|
|
|
|
Q_SAVE_SORT = (1 << 5), /* Queue will be saved when sorted. */
|
2015-11-25 09:04:10 -05:00
|
|
|
Q_ADD_FRONT = (1 << 6), /* Queue will add new tracks at the front. */
|
2013-12-31 15:44:44 -05:00
|
|
|
};
|
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
2015-04-03 10:30:46 -04:00
|
|
|
/**
|
|
|
|
* Class to assist in notifying the GUI of queue changes.
|
|
|
|
*/
|
|
|
|
class QNotifier {
|
|
|
|
public:
|
|
|
|
QNotifier() {}; /**< Notifier constructor. */
|
2015-04-03 11:35:23 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a track is added to a queue.
|
|
|
|
*
|
|
|
|
* @param pos Position in the queue that the track was added.
|
|
|
|
*/
|
|
|
|
virtual void on_track_added(unsigned int) = 0;
|
2015-04-03 12:24:26 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a track is removed from a queue.
|
|
|
|
*
|
|
|
|
* @param pos Position in the queue that the track was removed from.
|
|
|
|
*/
|
|
|
|
virtual void on_track_removed(unsigned int) = 0;
|
2015-04-03 20:54:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a track has been updated.
|
|
|
|
*
|
|
|
|
* @param pos Position in the queue of the updated track.
|
|
|
|
*/
|
|
|
|
virtual void on_track_updated(unsigned int) = 0;
|
2015-04-03 10:30:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-23 08:36:29 -05:00
|
|
|
struct queue_ops {
|
|
|
|
/* Called to have a higher layer save the queue. */
|
|
|
|
void (*qop_save)(struct queue *, enum queue_flags);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
/**
|
|
|
|
* Struct for passing sort parameters.
|
|
|
|
*/
|
2014-01-26 14:44:56 -05:00
|
|
|
struct sort_info {
|
2015-11-16 09:54:47 -05:00
|
|
|
compare_t field;
|
|
|
|
bool ascending;
|
2014-01-26 14:44:56 -05:00
|
|
|
};
|
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
2014-12-09 08:39:04 -05:00
|
|
|
* Queues are lists of songs that the user has requested to play next,
|
|
|
|
* although not necessarily in a specific order.
|
|
|
|
*
|
|
|
|
* When writing a Queue to disk: write out the _flags and size values
|
|
|
|
* first, followed by the list of track indexes.
|
|
|
|
*
|
|
|
|
* ... << _flags << _tracks.size() << tracks[N]->index() << ...;
|
2014-10-17 09:42:45 -04:00
|
|
|
*/
|
2015-11-16 09:12:15 -05:00
|
|
|
struct queue {
|
|
|
|
unsigned int q_cur; /* The queue's last-played index. */
|
|
|
|
unsigned int q_flags; /* The queue's set of flags. */
|
|
|
|
unsigned int q_length; /* The queue's total runtime (in seconds). */
|
|
|
|
QNotifier *q_notify; /* The queue's notification functions. */
|
|
|
|
|
|
|
|
std :: vector <struct track *> q_tracks; /* The queue's list of tracks. */
|
|
|
|
std :: vector <struct sort_info> q_sort; /* The queue's sort settings. */
|
2013-12-31 15:44:44 -05:00
|
|
|
|
2015-11-23 08:36:29 -05:00
|
|
|
const struct queue_ops *q_ops; /* The queue's operations vector. */
|
|
|
|
|
2015-11-16 09:12:15 -05:00
|
|
|
|
|
|
|
virtual ~queue(); /**< Queue destructor. */
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a queue to disk.
|
2014-12-09 08:39:04 -05:00
|
|
|
*
|
|
|
|
* @param file File that Queue data will be written to.
|
2014-10-17 09:42:45 -04:00
|
|
|
*/
|
2015-09-10 08:00:42 -04:00
|
|
|
void write(file &);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a queue from disk.
|
2014-12-09 08:39:04 -05:00
|
|
|
*
|
|
|
|
* @param file File to read Queue data from.
|
2014-10-17 09:42:45 -04:00
|
|
|
*/
|
2015-09-10 08:00:42 -04:00
|
|
|
void read(file &);
|
2013-12-31 15:44:44 -05:00
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
2014-12-09 08:48:27 -05:00
|
|
|
* Remove a track based on its queue index.
|
2014-12-09 08:39:04 -05:00
|
|
|
*
|
2014-12-09 08:48:27 -05:00
|
|
|
* @param index Track index to remove from the queue.
|
2014-10-17 09:42:45 -04:00
|
|
|
*/
|
2014-12-09 08:48:27 -05:00
|
|
|
virtual void del(unsigned int);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
2014-12-09 08:48:27 -05:00
|
|
|
* Remove all instances of a track from the queue.
|
2014-12-09 08:39:04 -05:00
|
|
|
*
|
2014-12-09 08:48:27 -05:00
|
|
|
* @param track Track to remove from the queue.
|
2014-10-17 09:42:45 -04:00
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
virtual void del(struct track *);
|
2013-12-31 15:44:44 -05:00
|
|
|
};
|
|
|
|
|
2015-11-19 08:08:14 -05:00
|
|
|
|
2015-11-23 08:36:29 -05:00
|
|
|
/* Called to initialize a queue. */
|
|
|
|
void queue_init(struct queue *, unsigned int, const struct queue_ops *);
|
|
|
|
|
|
|
|
|
2015-12-03 13:41:39 -05:00
|
|
|
/* Called to set a queue flag. */
|
|
|
|
void queue_set_flag(struct queue *, enum queue_flags);
|
|
|
|
|
|
|
|
/* Called to clear a queue flag. */
|
|
|
|
void queue_unset_flag(struct queue *, enum queue_flags);
|
|
|
|
|
2015-11-20 08:18:54 -05:00
|
|
|
/* Called to check if the queue has a specific flag set. */
|
|
|
|
static inline bool queue_has_flag(struct queue *queue, enum queue_flags flag)
|
|
|
|
{
|
|
|
|
return (queue->q_flags & flag) == (unsigned int)flag;
|
|
|
|
}
|
|
|
|
|
2015-11-19 13:48:59 -05:00
|
|
|
/* Called to find the size of the queue. */
|
|
|
|
static inline unsigned int queue_size(struct queue *queue)
|
|
|
|
{
|
|
|
|
return queue->q_tracks.size();
|
|
|
|
}
|
|
|
|
|
2015-11-19 13:50:08 -05:00
|
|
|
/* Called to access the queued track at a given index. */
|
|
|
|
static inline struct track *queue_at(struct queue *queue, unsigned int index)
|
|
|
|
{
|
|
|
|
return queue->q_tracks[index];
|
|
|
|
}
|
|
|
|
|
2015-11-19 13:48:59 -05:00
|
|
|
|
2015-11-25 08:24:04 -05:00
|
|
|
/* Called to add a track to the queue. */
|
|
|
|
unsigned int queue_add(struct queue *, struct track *);
|
|
|
|
|
2015-11-20 08:02:54 -05:00
|
|
|
/* Called to tell the queue that a track has been updated. */
|
|
|
|
void queue_updated(struct queue *, struct track *);
|
|
|
|
|
|
|
|
|
2015-11-19 08:08:14 -05:00
|
|
|
/* Called to tell the queue that a specific index has been selected. */
|
|
|
|
void queue_selected(struct queue *, unsigned int);
|
|
|
|
|
2015-11-19 08:25:53 -05:00
|
|
|
/* Called to pick the next track from the queue. */
|
|
|
|
struct track *queue_next(struct queue *);
|
|
|
|
|
2015-12-03 13:43:15 -05:00
|
|
|
/* Called to sort the queue. */
|
|
|
|
void queue_sort(struct queue *, enum compare_t, bool);
|
|
|
|
|
2014-06-21 09:37:47 -04:00
|
|
|
#endif /* OCARINA_CORE_QUEUE_H */
|