libsaria: Created Queue playlist class
This was much easier using inheritance... Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
3f665712a1
commit
5dc215d69a
|
@ -43,7 +43,9 @@ namespace libsaria
|
|||
PlaylistRenderer *renderer;
|
||||
|
||||
Track *pick_random();
|
||||
Track *pick_sequential();
|
||||
void add_sorted(list<Track *> &);
|
||||
void add_to_end(list<Track *> &);
|
||||
|
||||
public:
|
||||
Playlist(string, unsigned int);
|
||||
|
@ -70,6 +72,16 @@ namespace libsaria
|
|||
void add_tracks(list<Track *> &);
|
||||
};
|
||||
|
||||
|
||||
class Queue : public Playlist {
|
||||
public:
|
||||
Queue(string, unsigned int);
|
||||
~Queue();
|
||||
|
||||
Track *next();
|
||||
void add_tracks(list<Track *> &);
|
||||
};
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
||||
#endif /* LIBSARIA_PLAYLIST_H */
|
||||
|
|
|
@ -43,4 +43,21 @@ namespace libsaria
|
|||
RENDER(insert_done());
|
||||
}
|
||||
|
||||
void Playlist::add_to_end(list<Track *> &tracks)
|
||||
{
|
||||
list<Track *>::iterator it;
|
||||
|
||||
RENDER(insert_prepare());
|
||||
|
||||
for (it = tracks.begin(); it != tracks.end(); it++) {
|
||||
plist.push_back(*it);
|
||||
RENDER( insert(*it, plist.size()) );
|
||||
};
|
||||
|
||||
if (plist.size() == tracks.size())
|
||||
cur = plist.begin();
|
||||
|
||||
RENDER(insert_done());
|
||||
}
|
||||
|
||||
}; /* namespace: libsaria */
|
||||
|
|
|
@ -95,6 +95,17 @@ namespace libsaria
|
|||
}
|
||||
}*/
|
||||
|
||||
Track *Playlist::pick_sequential()
|
||||
{
|
||||
if (get_size() == 0)
|
||||
return NULL;
|
||||
|
||||
if (flags & PL_NO_DRAIN)
|
||||
incr_iter();
|
||||
|
||||
return picked_next();
|
||||
}
|
||||
|
||||
Track *Playlist::pick_random()
|
||||
{
|
||||
unsigned int n, size = get_size();
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#include <libsaria/playlist.h>
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
Queue::Queue(string name, unsigned int flags) : Playlist(name, flags)
|
||||
{
|
||||
}
|
||||
|
||||
Queue::~Queue()
|
||||
{
|
||||
}
|
||||
|
||||
void Queue::add_tracks(list<Track *> &tracks)
|
||||
{
|
||||
add_to_end(tracks);
|
||||
}
|
||||
|
||||
Track *Queue::next()
|
||||
{
|
||||
return pick_sequential();
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
|
@ -59,10 +59,10 @@ namespace libsaria
|
|||
|
||||
switch (type) {
|
||||
case PLIST_SET:
|
||||
plist = new Set("Set_" + get_next_name(), PL_NONE);
|
||||
plist = new Set("Set [" + get_next_name() + "]", PL_NONE);
|
||||
break;
|
||||
case PLIST_QUEUE:
|
||||
return;
|
||||
plist = new Queue("Queue [" + get_next_name() + "]", PL_NONE);
|
||||
};
|
||||
|
||||
if (on_new_playlist)
|
||||
|
|
Loading…
Reference in New Issue