libsaria: Remove PlaylistType in favor of flags
Flags let me manually set properties after the playlist has been created, rather than needing to decide upfront with no way of converting to something else. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
a730eaa2cc
commit
bf5b8a3bdd
|
@ -25,7 +25,7 @@ namespace libsaria
|
|||
void prev();
|
||||
void init();
|
||||
|
||||
Playlist *new_playlist(list<Track *> &, PlaylistType, bool);
|
||||
Playlist *new_playlist(list<Track *> &, unsigned int, bool);
|
||||
void delete_playlist(Playlist *);
|
||||
unsigned int move_playlist(Playlist *, unsigned int);
|
||||
unsigned int num_playlists();
|
||||
|
|
|
@ -16,6 +16,8 @@ enum notify_t {
|
|||
PLAYLIST_DELETE, // libsaria::Playlist *
|
||||
PLAYLIST_RENUMBER, // libsaria::Playlist *
|
||||
PLAYLIST_DISABLE, // libsaria::Playlist *
|
||||
PLAYLIST_RANDOM, // libsaria::Playlist *
|
||||
PLAYLIST_SORTED, // libsaria::Playlist *
|
||||
PLAYLIST_ADD, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_RM, // libsaria::PlaylistNotification *
|
||||
PLAYLIST_UPDATE, // libsaria::PlaylistNotification *
|
||||
|
|
|
@ -15,11 +15,8 @@ enum PlaylistFlags {
|
|||
PL_NO_DRAIN = (1 << 0),
|
||||
PL_STATIC = (1 << 1),
|
||||
PL_DISABLED = (1 << 2),
|
||||
};
|
||||
|
||||
enum PlaylistType {
|
||||
PLIST_SET,
|
||||
PLIST_QUEUE,
|
||||
PL_RANDOM = (1 << 3),
|
||||
PL_SORTED = (1 << 4),
|
||||
};
|
||||
|
||||
namespace libsaria
|
||||
|
@ -34,11 +31,11 @@ namespace libsaria
|
|||
int number;
|
||||
unsigned int flags;
|
||||
unsigned int length;
|
||||
PlaylistType type;
|
||||
DataState data_state;
|
||||
list<Track *>::iterator cur;
|
||||
Index index;
|
||||
|
||||
void set_flag(bool, PlaylistFlags);
|
||||
void schedule_save();
|
||||
void rm_file();
|
||||
void notify_ui(notify_t, Track *, unsigned int);
|
||||
|
@ -62,7 +59,7 @@ namespace libsaria
|
|||
void add_sorted(list<Track *> &);
|
||||
|
||||
public:
|
||||
Playlist(string, unsigned int, PlaylistType);
|
||||
Playlist(string, unsigned int);
|
||||
virtual ~Playlist();
|
||||
void set_renderer(PlaylistRenderer *);
|
||||
PlaylistRenderer *get_renderer();
|
||||
|
@ -72,6 +69,11 @@ namespace libsaria
|
|||
void push_back(list<Track *> &);
|
||||
Track *next();
|
||||
|
||||
void set_random(bool);
|
||||
bool get_random();
|
||||
void set_sorted(bool);
|
||||
bool get_sorted();
|
||||
|
||||
void save(ofstream &);
|
||||
bool is_static();
|
||||
bool is_disabled();
|
||||
|
@ -87,7 +89,6 @@ namespace libsaria
|
|||
unsigned int get_number();
|
||||
unsigned int get_size();
|
||||
unsigned int get_length();
|
||||
PlaylistType get_type();
|
||||
|
||||
void remove_indices(list<unsigned int> &);
|
||||
void remove_track(Track *);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <library.h>
|
||||
#include <ban.h>
|
||||
|
||||
static libsaria::Playlist banned_plist("Banned", PL_STATIC | PL_NO_DRAIN, PLIST_SET);
|
||||
static libsaria::Playlist banned_plist("Banned", PL_STATIC | PL_NO_DRAIN | PL_RANDOM | PL_SORTED);
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ using namespace std;
|
|||
|
||||
static unsigned int next_id = 0;
|
||||
static list<struct libsaria::library::Path> path_list;
|
||||
libsaria::Playlist lib_playlist("Library", PL_STATIC | PL_NO_DRAIN, PLIST_SET);
|
||||
libsaria::Playlist lib_playlist("Library", PL_STATIC | PL_NO_DRAIN | PL_RANDOM | PL_SORTED);
|
||||
|
||||
libsaria::library::Path *push_path(libsaria::library::Path &path)
|
||||
{
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace libsaria
|
|||
unsigned int index = 0;
|
||||
plist.push_front(track);
|
||||
|
||||
if (type == PLIST_SET) {
|
||||
if (get_sorted()) {
|
||||
plist.sort();
|
||||
index = find_index(track);
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ namespace libsaria
|
|||
{
|
||||
unsigned int index = plist.size() + 1;
|
||||
plist.push_back(track);
|
||||
if (type == PLIST_SET) {
|
||||
if (get_sorted()) {
|
||||
plist.sort();
|
||||
index = find_index(track);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ namespace libsaria
|
|||
{
|
||||
list<Track *>::iterator it;
|
||||
|
||||
if (type == PLIST_SET)
|
||||
if (get_sorted())
|
||||
add_sorted(tracks);
|
||||
else {
|
||||
for (it = tracks.begin(); it != tracks.end(); it++)
|
||||
|
|
|
@ -15,7 +15,7 @@ static AutoPauseType pause_type;
|
|||
static unsigned short pause_count = 0;
|
||||
|
||||
static list<libsaria::Playlist *> playlist_deck;
|
||||
static libsaria::Playlist recent_plist("Recent", PL_STATIC | PL_NO_DRAIN, PLIST_QUEUE);
|
||||
static libsaria::Playlist recent_plist("Recent", PL_STATIC | PL_NO_DRAIN);
|
||||
|
||||
static void renumber_playlists()
|
||||
{
|
||||
|
@ -104,13 +104,13 @@ namespace libsaria
|
|||
track->load_unlisted(true);
|
||||
}
|
||||
|
||||
Playlist *deck::new_playlist(list<Track *> &tracks, PlaylistType type, bool front)
|
||||
Playlist *deck::new_playlist(list<Track *> &tracks, unsigned int flags, bool front)
|
||||
{
|
||||
Playlist *plist;
|
||||
|
||||
if (playlist_deck.size() == MAX_PLAYLISTS)
|
||||
return NULL;
|
||||
plist = new Playlist("Playlist", PL_NONE, type);
|
||||
plist = new Playlist("Playlist", flags);
|
||||
|
||||
if (front)
|
||||
deck::push_front(plist);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
#define PLAYLIST_CURRENT_VERSION 2
|
||||
#define PLAYLIST_CURRENT_VERSION 3 // 9 / 14 / 2012
|
||||
|
||||
static string plistdir = "playlist";
|
||||
|
||||
|
@ -31,15 +31,25 @@ static void save_playlist(ofstream &stream, void *plist)
|
|||
void read_plist(ifstream &stream)
|
||||
{
|
||||
unsigned int version, type, size;
|
||||
unsigned int libid, trackid;
|
||||
unsigned int libid, trackid, flags = 0;
|
||||
bool disabled = false;
|
||||
bool random = false;
|
||||
bool sorted = false;
|
||||
list<libsaria::Track *> tracks;
|
||||
libsaria::Track *track;
|
||||
libsaria::Playlist *plist;
|
||||
|
||||
stream >> version >> type >> size;
|
||||
if (version == 2)
|
||||
stream >> disabled;
|
||||
stream >> version;
|
||||
if (version < 3)
|
||||
stream >> type;
|
||||
stream >> size >> disabled;
|
||||
|
||||
if (version >= 3) {
|
||||
stream >> random;
|
||||
stream >> sorted;
|
||||
} else if (type == 0) { /* Old PLIST_SET type */
|
||||
random = true;
|
||||
sorted = true;
|
||||
}
|
||||
|
||||
println("playlist type: %u size: %u disabled: %d", type, size, disabled);
|
||||
|
||||
|
@ -51,8 +61,11 @@ void read_plist(ifstream &stream)
|
|||
}
|
||||
|
||||
if (tracks.size() > 0) {
|
||||
plist = libsaria::deck::new_playlist(tracks, (PlaylistType)type, false);
|
||||
plist->set_disabled(disabled);
|
||||
if (disabled)
|
||||
flags |= PL_DISABLED;
|
||||
if (random)
|
||||
flags |= PL_RANDOM;
|
||||
libsaria::deck::new_playlist(tracks, flags, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,9 +77,10 @@ namespace libsaria
|
|||
list<Track *>::iterator it;
|
||||
|
||||
stream << PLAYLIST_CURRENT_VERSION << "\n";
|
||||
stream << type << " ";
|
||||
stream << plist.size() << " ";
|
||||
stream << is_disabled() <<"\n";
|
||||
stream << plist.size() << " ";
|
||||
stream << is_disabled() <<" ";
|
||||
stream << get_random() << " ";
|
||||
stream << get_sorted() << "\n";
|
||||
|
||||
for (it = plist.begin(); it != plist.end(); it++) {
|
||||
stream << (*it)->get_libid() << " ";
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace libsaria
|
|||
if (get_size() == 0)
|
||||
return NULL;
|
||||
|
||||
if (type == PLIST_SET)
|
||||
if (get_random())
|
||||
pick_random();
|
||||
else
|
||||
pick_sequential();
|
||||
|
|
|
@ -7,12 +7,11 @@
|
|||
namespace libsaria
|
||||
{
|
||||
|
||||
Playlist::Playlist(string n, unsigned int f, PlaylistType t)
|
||||
Playlist::Playlist(string n, unsigned int f)
|
||||
{
|
||||
name = n;
|
||||
number = -1;
|
||||
flags = f;
|
||||
type = t;
|
||||
length = 0;
|
||||
renderer = NULL;
|
||||
cur = plist.begin();
|
||||
|
@ -22,6 +21,37 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
void Playlist::set_flag(bool enabled, PlaylistFlags flag)
|
||||
{
|
||||
if (enabled)
|
||||
flags |= flag;
|
||||
else
|
||||
flags &= ~flag;
|
||||
schedule_save();
|
||||
}
|
||||
|
||||
bool Playlist::get_sorted()
|
||||
{
|
||||
return (flags & PL_SORTED) == PL_SORTED;
|
||||
}
|
||||
|
||||
void Playlist::set_sorted(bool sorted)
|
||||
{
|
||||
set_flag(sorted, PL_SORTED);
|
||||
notify(PLAYLIST_SORTED, this);
|
||||
}
|
||||
|
||||
bool Playlist::get_random()
|
||||
{
|
||||
return (flags & PL_RANDOM) == PL_RANDOM;
|
||||
}
|
||||
|
||||
void Playlist::set_random(bool random)
|
||||
{
|
||||
set_flag(random, PL_RANDOM);
|
||||
notify(PLAYLIST_RANDOM, this);
|
||||
}
|
||||
|
||||
bool Playlist::is_static()
|
||||
{
|
||||
return (flags & PL_STATIC) == PL_STATIC;
|
||||
|
@ -34,11 +64,7 @@ namespace libsaria
|
|||
|
||||
void Playlist::set_disabled(bool disabled)
|
||||
{
|
||||
if (disabled)
|
||||
flags |= PL_DISABLED;
|
||||
else
|
||||
flags &= ~PL_DISABLED;
|
||||
schedule_save();
|
||||
set_flag(disabled, PL_DISABLED);
|
||||
notify(PLAYLIST_DISABLE, this);
|
||||
}
|
||||
|
||||
|
@ -99,11 +125,6 @@ namespace libsaria
|
|||
return length;
|
||||
}
|
||||
|
||||
PlaylistType Playlist::get_type()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
void Playlist::set_renderer(PlaylistRenderer *r)
|
||||
{
|
||||
renderer = r;
|
||||
|
|
|
@ -194,15 +194,15 @@ static void list_selected_indices(GtkTreeView *treeview, list<unsigned int> *ind
|
|||
static void new_playlist(const string &key, GtkTreeView *treeview, bool front)
|
||||
{
|
||||
list<libsaria::Track *> tracks;
|
||||
unsigned int flags = PL_NONE;
|
||||
|
||||
list_selected_tracks(treeview, &tracks);
|
||||
if (tracks.size() == 0)
|
||||
return;
|
||||
|
||||
if (key == "s" || key == "S")
|
||||
libsaria::deck::new_playlist(tracks, PLIST_SET, front);
|
||||
if (key == "q" || key == "Q")
|
||||
libsaria::deck::new_playlist(tracks, PLIST_QUEUE, front);
|
||||
flags |= PL_SORTED | PL_RANDOM;
|
||||
libsaria::deck::new_playlist(tracks, flags, front);
|
||||
}
|
||||
|
||||
static bool add_to_playlist(GtkTreeView *treeview, int n)
|
||||
|
|
Loading…
Reference in New Issue