libsaria: Load playlists to a new playlist_deck vector
The vector should be simpler than a linked list for tracking playlists. I also changed reading playlists to use a function in the playlist class rather than a function outside of the playlist. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
27b2e386f0
commit
b091df8ec4
|
@ -30,7 +30,7 @@ namespace libsaria
|
|||
unsigned int num_playlists();
|
||||
|
||||
Playlist *get_playlist(unsigned int);
|
||||
int get_playlist_index(Playlist *);
|
||||
unsigned int get_playlist_index(Playlist *);
|
||||
Playlist *get_recent_plist();
|
||||
|
||||
void list_recent(Track *);
|
||||
|
|
|
@ -57,6 +57,7 @@ namespace libsaria
|
|||
bool check_flag(PlaylistFlags);
|
||||
|
||||
void save(ofstream &);
|
||||
void load(ifstream &);
|
||||
void prepare_for_removal();
|
||||
void reset_iterator();
|
||||
|
||||
|
|
|
@ -1,22 +1,41 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#include <deck.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
* TODO: Move this into some header file somewhere...
|
||||
* or maybe create a new playlist constructor?
|
||||
*/
|
||||
void read_plist(ifstream &);
|
||||
static vector<libsaria::Playlist *> playlist_deck;
|
||||
|
||||
static void read_playlist(ifstream &stream)
|
||||
{
|
||||
libsaria::Playlist *plist = new libsaria::Playlist(0);
|
||||
playlist_deck.push_back(plist);
|
||||
notify(PLAYLIST_NEW, plist);
|
||||
plist->load(stream);
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
Playlist *deck::get_playlist(unsigned int n)
|
||||
{
|
||||
if (n >= playlist_deck.size())
|
||||
return NULL;
|
||||
return playlist_deck[n];
|
||||
}
|
||||
|
||||
unsigned int deck::get_playlist_index(Playlist *plist)
|
||||
{
|
||||
for (unsigned int i = 0; i < playlist_deck.size(); i++) {
|
||||
if (playlist_deck[i] == plist)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void deck::init()
|
||||
{
|
||||
app::mkdir("playlist");
|
||||
app::read_numdir("playlist", read_plist);
|
||||
app::read_numdir("playlist", read_playlist);
|
||||
}
|
||||
|
||||
}; /* Namespace: Libsaria */
|
||||
|
|
|
@ -168,32 +168,6 @@ namespace libsaria
|
|||
return &recent_plist;
|
||||
}
|
||||
|
||||
Playlist *deck::get_playlist(unsigned int n)
|
||||
{
|
||||
list<libsaria::Playlist *>::iterator it;
|
||||
|
||||
if (n >= playlist_deck.size())
|
||||
return NULL;
|
||||
|
||||
it = playlist_deck.begin();
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
it++;
|
||||
|
||||
return *it;
|
||||
}
|
||||
|
||||
int deck::get_playlist_index(Playlist *plist)
|
||||
{
|
||||
list<libsaria::Playlist *>::iterator it;
|
||||
int n = 0;
|
||||
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++) {
|
||||
if ((*it) == plist)
|
||||
return n;
|
||||
n++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void deck::track_removed(Track *track)
|
||||
{
|
||||
list<Playlist *>::iterator it;
|
||||
|
|
|
@ -28,52 +28,52 @@ static void save_playlist(ofstream &stream, void *plist)
|
|||
playlist->save(stream);
|
||||
}
|
||||
|
||||
void read_plist(ifstream &stream)
|
||||
namespace libsaria
|
||||
{
|
||||
unsigned int version, type, size;
|
||||
unsigned int libid, trackid, flags = 0;
|
||||
bool disabled = false;
|
||||
bool random = false;
|
||||
bool sorted = false;
|
||||
list<libsaria::Track *> tracks;
|
||||
libsaria::Track *track;
|
||||
|
||||
stream >> version;
|
||||
if (version < 3)
|
||||
stream >> type;
|
||||
stream >> size >> disabled;
|
||||
void Playlist::load(ifstream &stream)
|
||||
{
|
||||
unsigned int version, type, size, libid, trackid;
|
||||
bool disabled = false;
|
||||
bool random = false;
|
||||
bool sorted = false;
|
||||
Track *track;
|
||||
|
||||
if (version >= 3) {
|
||||
stream >> random;
|
||||
stream >> sorted;
|
||||
} else if (type == 0) { /* Old PLIST_SET type */
|
||||
random = true;
|
||||
sorted = true;
|
||||
}
|
||||
number = -1;
|
||||
flags = 0;
|
||||
cur = 0;
|
||||
|
||||
println("playlist size: %u disabled: %d random: %d sorted: %d",
|
||||
stream >> version;
|
||||
if (version < 3)
|
||||
stream >> type;
|
||||
stream >> size >> disabled;
|
||||
|
||||
if (version >= 3)
|
||||
stream >> random >> sorted;
|
||||
else if (type == 0) { /* Old PLIST_SET type */
|
||||
random = true;
|
||||
sorted = true;
|
||||
}
|
||||
|
||||
println("playlist size: %u disabled: %d random: %d sorted: %d",
|
||||
size, disabled, random, sorted);
|
||||
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
stream >> libid >> trackid;
|
||||
track = libsaria::library::lookup(libid, trackid);
|
||||
if (track)
|
||||
tracks.push_back(track);
|
||||
}
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
stream >> libid >> trackid;
|
||||
track = library::lookup(libid, trackid);
|
||||
if (track)
|
||||
push_back(track);
|
||||
}
|
||||
|
||||
if (tracks.size() > 0) {
|
||||
if (disabled)
|
||||
flags |= PL_DISABLED;
|
||||
if (random)
|
||||
flags |= PL_RANDOM;
|
||||
if (sorted)
|
||||
if (sorted) {
|
||||
flags |= PL_SORTED;
|
||||
libsaria::deck::new_playlist(tracks, flags, false);
|
||||
do_sort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void Playlist::save(ofstream &stream)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue