2014-10-17 09:42:45 -04:00
|
|
|
/**
|
|
|
|
* @file
|
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
|
|
|
|
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>
|
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-10-17 09:42:45 -04:00
|
|
|
/**
|
|
|
|
* Enum defining queue flags.
|
|
|
|
*/
|
2014-04-01 20:28:19 -04:00
|
|
|
enum queue_flags {
|
2014-10-17 09:42:45 -04:00
|
|
|
/** Queue is enabled. */
|
2014-04-01 20:28:19 -04:00
|
|
|
Q_ENABLED = (1 << 0),
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/** Queue will pick songs randomly. */
|
2014-04-01 20:28:19 -04:00
|
|
|
Q_RANDOM = (1 << 1),
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/** Queue will not remove songs when picked. */
|
2014-04-01 20:28:19 -04:00
|
|
|
Q_REPEAT = (1 << 2),
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/** Queue will not be sorted. */
|
2014-04-13 18:38:49 -04:00
|
|
|
Q_NO_SORT = (1 << 3),
|
2013-12-31 15:44:44 -05:00
|
|
|
};
|
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mask of valid flags.
|
|
|
|
*/
|
2014-06-06 14:46:06 -04:00
|
|
|
static const unsigned int Q_FLAG_MASK = Q_ENABLED | Q_RANDOM | Q_REPEAT | Q_NO_SORT;
|
2014-04-13 18:38:49 -04:00
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
2014-11-28 10:28:15 -05:00
|
|
|
/**
|
|
|
|
* Track fields that can be compared.
|
|
|
|
*/
|
|
|
|
enum sort_t {
|
|
|
|
/** Artist name */
|
|
|
|
SORT_ARTIST,
|
|
|
|
/** Album name */
|
|
|
|
SORT_ALBUM,
|
|
|
|
/** Play count */
|
|
|
|
SORT_COUNT,
|
|
|
|
/** Genre */
|
|
|
|
SORT_GENRE,
|
|
|
|
/** Track length */
|
|
|
|
SORT_LENGTH,
|
|
|
|
/** Date the track was last played */
|
|
|
|
SORT_PLAYED,
|
|
|
|
/** Track title */
|
|
|
|
SORT_TITLE,
|
|
|
|
/** Track number */
|
|
|
|
SORT_TRACK,
|
|
|
|
/** Track year */
|
|
|
|
SORT_YEAR,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
/**
|
|
|
|
* Struct for passing sort parameters.
|
|
|
|
*/
|
2014-01-26 14:44:56 -05:00
|
|
|
struct sort_info {
|
|
|
|
sort_t field;
|
|
|
|
bool ascending;
|
|
|
|
};
|
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class defining playback queues.
|
|
|
|
*/
|
2014-04-01 20:28:19 -04:00
|
|
|
class Queue {
|
2014-04-13 12:26:32 -04:00
|
|
|
protected:
|
|
|
|
std :: vector <Track *> _tracks;
|
2014-05-18 14:11:21 -04:00
|
|
|
std :: vector <struct sort_info> _sort_order;
|
2014-04-13 12:26:32 -04:00
|
|
|
unsigned int _cur;
|
|
|
|
unsigned int _flags;
|
|
|
|
unsigned int _length;
|
2013-12-31 15:44:44 -05:00
|
|
|
|
2014-03-29 11:44:39 -04:00
|
|
|
unsigned int find_sorted_id(Track *);
|
2014-05-11 10:53:48 -04:00
|
|
|
unsigned int _add_at(Track *, unsigned int);
|
2014-05-11 11:23:15 -04:00
|
|
|
void _del_at(Track *, unsigned int);
|
2014-01-25 14:43:51 -05:00
|
|
|
|
2013-12-31 15:44:44 -05:00
|
|
|
public:
|
2014-10-17 09:42:45 -04:00
|
|
|
/**
|
|
|
|
* Default queue constructor.
|
|
|
|
*/
|
2014-04-01 20:28:19 -04:00
|
|
|
Queue();
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Alternat queue constructor.
|
|
|
|
* @param f Create a queue with flags set to f.
|
|
|
|
*/
|
2014-04-13 18:38:49 -04:00
|
|
|
Queue(unsigned int);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue destructor.
|
|
|
|
*/
|
2014-04-01 20:28:19 -04:00
|
|
|
~Queue();
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a queue to disk.
|
|
|
|
* @param f File queue data will be written to.
|
|
|
|
*/
|
2013-12-31 15:44:44 -05:00
|
|
|
void write(File &);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a queue from disk.
|
|
|
|
* @param f File to read queue data from.
|
|
|
|
*/
|
2013-12-31 15:44:44 -05:00
|
|
|
void read(File &);
|
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a queue flag.
|
|
|
|
* @param f queue_flag to set.
|
|
|
|
*/
|
2014-05-24 12:47:33 -04:00
|
|
|
virtual void set_flag(queue_flags);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear a queue flag.
|
|
|
|
* @param f queue_flag to clear.
|
|
|
|
*/
|
2014-05-24 12:47:33 -04:00
|
|
|
virtual void unset_flag(queue_flags);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a queue has a specific flag set.
|
|
|
|
* @param f queue_flag to check.
|
|
|
|
* @return true if queue_flag is set.
|
|
|
|
*/
|
2014-04-13 12:26:32 -04:00
|
|
|
bool has_flag(queue_flags);
|
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a track to the queue.
|
|
|
|
* @param track Track to add to the queue.
|
|
|
|
* @return The index of the track in the queue.
|
|
|
|
*/
|
2014-05-11 10:53:48 -04:00
|
|
|
virtual unsigned int add(Track *);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all instances of a track from the queue.
|
|
|
|
* @param track Track to remove from the queue.
|
|
|
|
*/
|
2014-05-31 09:09:44 -04:00
|
|
|
virtual void del(Track *);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a track based on its queue index.
|
|
|
|
* @param index Track index to remove from the queue.
|
|
|
|
*/
|
2014-05-31 09:09:44 -04:00
|
|
|
virtual void del(unsigned int);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal to the queue that a track has been updated.
|
|
|
|
* @param track The track that has been modified.
|
|
|
|
*/
|
2014-05-11 18:32:53 -04:00
|
|
|
void updated(Track *);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pick the next track from the queue.
|
|
|
|
* @return The next Track on the queue.
|
|
|
|
*/
|
2014-05-18 11:08:58 -04:00
|
|
|
Track *next();
|
2014-05-11 19:52:08 -04:00
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the size of the queue.
|
|
|
|
* @return The number of tracks on the queue.
|
|
|
|
*/
|
2013-12-31 15:44:44 -05:00
|
|
|
unsigned int size();
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the size of the queue, as a string.
|
|
|
|
* @return The number of tracks on the queue, in string form.
|
|
|
|
*/
|
2014-05-11 19:52:08 -04:00
|
|
|
const std::string size_str();
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the runtime of the queue.
|
|
|
|
* @return The runtime of the queue, as a string.
|
|
|
|
*/
|
2014-05-11 19:52:08 -04:00
|
|
|
const std::string length_str();
|
2013-12-31 15:44:44 -05:00
|
|
|
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new parameter for sorting the queue.
|
|
|
|
* @param field Field to sort by.
|
|
|
|
* @param reset Set to true if current sort data should be discarded.
|
|
|
|
*/
|
2014-05-24 12:47:33 -04:00
|
|
|
virtual void sort(sort_t, bool);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Access a track by index.
|
|
|
|
* @param index The index to look up.
|
|
|
|
* @return The track found at the requested index.
|
|
|
|
*/
|
2014-04-13 12:26:32 -04:00
|
|
|
Track *operator[](unsigned int);
|
2014-10-17 09:42:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell the queue that a track has been selected for playback without
|
|
|
|
* calling Queue :: next().
|
|
|
|
* @param index The index that is now playing.
|
|
|
|
*/
|
2014-05-18 14:24:46 -04:00
|
|
|
void track_selected(unsigned int);
|
2013-12-31 15:44:44 -05:00
|
|
|
};
|
|
|
|
|
2014-06-21 09:37:47 -04:00
|
|
|
#endif /* OCARINA_CORE_QUEUE_H */
|