ocarina/design/playqueue.txt

150 lines
3.5 KiB
Plaintext

== Files ==
ocarina/include/
playqueue.h
ocarina/lib/
playqueue.cpp
== Depends ==
file
Playqueue: (lib/playqueue.cpp)
Playqueues are a list of songs that the user has requested to play.
- Flags:
enum playqueue_flags {
PQ_ENABLED (1 << 0),
PQ_RANDOM (1 << 1),
PQ_REPEAT (1 << 2),
};
- Sort order:
enum sort_t {
SORT_ARTIST_ASC = 1,
SORT_ARTIST_DESC = 2,
SORT_ALBUM_ASC = 3,
SORT_ALBUM_DESC = 4,
SORT_COUNT_ASC = 5,
SORT_COUNT_DESC = 6,
SORT_GENRE_ASC = 7,
SORT_GENRE_DESC = 8,
SORT_LENGTH_ASC = 9,
SORT_LENGTH_DESC = 10,
SORT_PLAYED_ASC = 11,
SORT_PLAYED_DESC = 12,
SORT_TITLE_ASC = 13,
SORT_TITLE_DESC = 14,
SORT_TRACK_ASC = 15,
SORT_TRACK_DESC = 16,
SORT_YEAR_ASC = 17,
SORT_YEAR_DESC = 18,
};
- Playqueue:
class Playqueue {
private:
vector<track_id> tracks;
list<sort_t> sort_order; /* default = { SORT_ARTIST_ASC,
SORT_YEAR_ASC,
SORT_TRACK_ASC };
unsigned int cur;
unsigned int flags;
unsigned int length;
public:
Playqueue(flags);
void write(File &);
void read(File &);
void set_flag(playqueue_flags);
void unset_flag(playqueue_flags);
const unsigned int get_flags();
string get_length();
unsigned int add(track_id);
unsigned int add_front(track_id);
void del(playqueue_id);
unsigned int size();
void reset_sort();
void add_sort(sort_t, bool);
void sort();
unsigned int next();
void reset_cur();
}
File << flags << tracks.size() << tracks[0] << tracks[1] << ... << tracks[N];
- API
Playqueue :: Playlist(unsigned int flags);
Create a new playqueue with the appropriate flags set.
sort_order = { (SORT_ARTIST, true), (SORT_YEAR, true),
(SORT_TRACK, true) };
unsigned int Playqueue :: add(unsigned int track_id);
unsigned int Playqueue :: add_front(unsigned int track_id);
Add a new track to the tracks vector and return the index. If
add_front is called, the track will be added to the front of
the playqueue (index = 0).
length += track.length.
void Playqueue :: del(unsigned int playqueue_id);
Erase tracks[playqueue_id] from the tracks vector.
length -= track.length.
void Playqueue :: del_track(unsigned int track_id);
Erase all tracks with track id track_id.
void Playqueue :: set_flag(playqueue_flags flag);
void Playqueue :: unset_flag(playqueue_flags flag);
Set or unset the given flag.
const unsigned int Playqueue :: get_flags();
Return the currently enabled flags.
song Playqueue :: get_length();
Convert the length variable into a string and return the result
to the caller.
unsigned int Playqueue :: size();
Return tracks.size();
void Playqueue :: write(File &);
void Playqueue :: read(File &);
Read or write the playqueue to the file.
void Playqueue :: reset_sort();
Reset the sort_order list to empty.
void Playqueue :: add_sort(sort_t type, bool ascending);
Add a new term to the sort order.
void Playqueue :: sort();
Perform a stable sort on the entire playqueue. Compare tracks
based on the sort_order list.
unsigned int Playqueue :: next();
Return the next track_id to play.
if (tracks.size() == 0)
throw -EEXIST;
if (flags & PL_RANDOM):
cur += rand() % tracks.size();
else:
cur += 1;
if (cur > = tracks.size())
cur -= tracks.size();
track = tracks[cur];
if (!(flags & PL_REPEAT)):
length -= track.length;
tracks.erase(cur);
return track;
void Playqueue :: reset_cur();
This function is intended to be used by the audio layer when
managing the recently played playqueue.
cur = 0;