libsaria: Added playlist flags and improved next()
The improved next() function will increment the current iterator to the next visible song. If no songs are visible, then it moves to the next song on the list. The PL_DRAIN flags is then checked, and if draining is enabled then the current track is removed from the list before returning. This patch also switches over the library sequential next function to use the lib_playlist version. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
8b9457a8d0
commit
c8ad4371d6
|
@ -8,18 +8,33 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
enum PlaylistFlags {
|
||||
PL_NONE = (0),
|
||||
PL_DRAIN = (1 << 0),
|
||||
PL_RANDOM = (1 << 1),
|
||||
PL_SEQUENTIAL = (1 << 2),
|
||||
PL_FILTER = (1 << 3),
|
||||
};
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
class Playlist {
|
||||
private:
|
||||
unsigned int flags;
|
||||
string filename;
|
||||
list<Track *> plist;
|
||||
list<Track *>::iterator it;
|
||||
list<Track *>::iterator cur;
|
||||
|
||||
void init_common(string, unsigned int);
|
||||
|
||||
void incr_iter(list<Track *>::iterator &);
|
||||
void sequential_next();
|
||||
|
||||
public:
|
||||
Playlist();
|
||||
Playlist(string);
|
||||
Playlist(unsigned int);
|
||||
Playlist(string, unsigned int);
|
||||
~Playlist();
|
||||
|
||||
void do_load();
|
||||
|
|
|
@ -10,7 +10,7 @@ using namespace std;
|
|||
#include "library.h"
|
||||
|
||||
list<libsaria::LibraryPath> path_list;
|
||||
libsaria::Playlist lib_playlist;
|
||||
libsaria::Playlist lib_playlist(PL_RANDOM | PL_SEQUENTIAL);
|
||||
static map<sid_t, libsaria::Track *> lookup_map;
|
||||
|
||||
void library_map_track(libsaria::Track *track)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker.
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/index.h>
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/prefs.h>
|
||||
#include "../library.h"
|
||||
#include "list.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -39,22 +41,15 @@ static void random_next()
|
|||
}
|
||||
}
|
||||
|
||||
static void sequential_next()
|
||||
{
|
||||
sid_t songid;
|
||||
do {
|
||||
incr_iter();
|
||||
songid = (*current)->get_songid();
|
||||
} while(!libsaria::index::is_visible(songid));
|
||||
}
|
||||
|
||||
static string pick_next()
|
||||
{
|
||||
if (libsaria::prefs::get_bool("random") == true)
|
||||
libsaria::Track *cur;
|
||||
if (libsaria::prefs::get_bool("random") == true) {
|
||||
random_next();
|
||||
else
|
||||
sequential_next();
|
||||
return (*current)->get_filepath();
|
||||
return (*current)->get_filepath();
|
||||
}
|
||||
cur = lib_playlist.next();
|
||||
return cur->get_filepath();
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#include <libsaria/playlist.h>
|
||||
#include <libsaria/index.h>
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void Playlist::incr_iter(list<Track *>::iterator &it)
|
||||
{
|
||||
it++;
|
||||
if (it == plist.end())
|
||||
it = plist.begin();
|
||||
}
|
||||
|
||||
void Playlist::sequential_next()
|
||||
{
|
||||
sid_t songid;
|
||||
list<Track *>::iterator it = cur;
|
||||
|
||||
do {
|
||||
incr_iter(it);
|
||||
if (it == cur) {
|
||||
incr_iter(it);
|
||||
break;
|
||||
}
|
||||
songid = (*it)->get_songid();
|
||||
} while (!libsaria::index::is_visible(songid));
|
||||
|
||||
cur = it;
|
||||
}
|
||||
|
||||
Track *Playlist::next()
|
||||
{
|
||||
Track *track;
|
||||
|
||||
if (flags & PL_SEQUENTIAL)
|
||||
sequential_next();
|
||||
|
||||
track = (*cur);
|
||||
|
||||
if (flags & PL_DRAIN) {
|
||||
plist.erase(cur);
|
||||
cur = plist.end();
|
||||
save();
|
||||
}
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
|
@ -12,14 +12,22 @@ static bool compare_tracks(libsaria::Track *one, libsaria::Track *two)
|
|||
namespace libsaria
|
||||
{
|
||||
|
||||
Playlist::Playlist(string file)
|
||||
void Playlist::init_common(string file, unsigned int options)
|
||||
{
|
||||
filename = file;
|
||||
flags = options;
|
||||
cur = plist.end();
|
||||
}
|
||||
|
||||
Playlist::Playlist(string file, unsigned int options)
|
||||
{
|
||||
init_common(file, options);
|
||||
load();
|
||||
}
|
||||
|
||||
Playlist::Playlist()
|
||||
Playlist::Playlist(unsigned int options)
|
||||
{
|
||||
init_common("", options);
|
||||
}
|
||||
|
||||
Playlist::~Playlist()
|
||||
|
@ -63,12 +71,4 @@ namespace libsaria
|
|||
return plist.size();
|
||||
}
|
||||
|
||||
Track *Playlist::next()
|
||||
{
|
||||
Track *track = plist.front();
|
||||
plist.pop_front();
|
||||
save();
|
||||
return track;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ using namespace std;
|
|||
#include <libsaria/callback.h>
|
||||
#include <libsaria/playlist.h>
|
||||
|
||||
static libsaria::Playlist q_queue("queue.q");
|
||||
static libsaria::Playlist q_queue("queue.q", PL_DRAIN | PL_SEQUENTIAL);
|
||||
|
||||
static void refresh()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue