ocarina/design/playlist.txt

85 lines
1.7 KiB
Plaintext

== Files ==
ocarina/include/
playlist.h
ocarina/lib/
playlist.cpp
== Depends ==
file
Playlist: (lib/playlist.cpp)
Playlists are a list of songs that the user has requested to play.
- Flags:
enum playlist_flags {
PL_ENABLED (1 << 0),
PL_RANDOM (1 << 1),
PL_LOCKED (1 << 2),
};
- Playlist:
class Playlist {
private:
vector<track_id> tracks;
unsigned int cur;
unsigned int flags;
public:
Playlist(flags);
void write(File &);
void read(File &);
void set_flag(playlist_flags);
void unset_flag(playlist_flags);
const unsigned int get_flags();
unsigned int add(track_id);
void del(playlist_id);
unsigned int size();
void sort();
unsigned int next();
}
File << flags << tracks.size() << tracks[0] << tracks[1] << ... << tracks[N];
- API
Playlist :: Playlist(unsigned int flags);
Create a new playlist with the appropriate flags set.
unsigned int Playlist :: add(unsigned int track_id);
Add a new track to the tracks vector and return the index.
void del(unsigned int playlist_id);
Erase tracks[playlist_id] from the tracks vector.
void set_flag(playlist_flags flag);
void unset_flag(playlist_flags flag);
Set or unset the given flag.
const unsigned int get_flags();
Return the currently enabled flags.
unsigned int size();
Return tracks.size();
void write(File &);
void read(File &);
Read or write the playlist to the file.
void sort();
Sort a playlist in Artist -> Year -> Track number order.
unsigned int next();
if (flags & PL_RANDOM):
cur += rand() % tracks.size();
else:
cur += 1;
if (cur > = tracks.size())
cur -= tracks.size();
track = tracks[cur];
if (!(flags & PL_LOCKED)):
tracks.erase(cur);
return track;