libsaria: Create a parallel queue as a Playlist

My goal is to slowly phase in use of a Playlist class.  This patch
begins this effort by creating the Playlist class and changing the queue
code to load queue.q as a playlist in addition to the queue's hardcoded
list.

Signed-off-by: Bryan Schumake <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-02-18 10:01:30 -05:00 committed by Bryan Schumaker
parent c452af1ce7
commit 2fa54e76ac
5 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,28 @@
// Copyright (c) 2012 Bryan Schumaker.
#ifndef LIBSARIA_PLAYLIST_H
#define LIBSARIA_PLAYLIST_H
#include <libsaria/path.h>
#include <list>
#include <string>
using namespace std;
namespace libsaria
{
class Playlist {
private:
string filename;
list<sid_t> plist;
public:
Playlist(string);
~Playlist();
void load();
};
}; /* Namespace: libsaria */
#endif /* LIBSARIA_PLAYLIST_H */

View File

@ -0,0 +1,30 @@
// Copyright (c) 2012 Bryan Schumaker.
#include <libsaria/playlist.h>
namespace libsaria
{
void Playlist::load()
{
unsigned int size;
sid_t songid;
InFile in(filename);
if (!in.good())
return;
in >> size;
for (unsigned int i = 0; i < size; i++) {
in >> songid;
plist.push_back(songid);
}
}
}; /* Namespace: libsaria */
void load_playlist(void *plist)
{
libsaria::Playlist *playlist = (libsaria::Playlist *)plist;
playlist->load();
}

View File

@ -0,0 +1,20 @@
// Copyright (c) 2012 Bryan Schumaker.
#include <libsaria/files.h>
#include <libsaria/playlist.h>
#include "playlist.h"
namespace libsaria
{
Playlist::Playlist(string file)
{
filename = file;
LoadTask *task = new LoadTask(load_playlist, this);
task->queue();
}
Playlist::~Playlist()
{
}
}

View File

@ -0,0 +1,7 @@
// Copyright (c) 2012 Bryan Schumaker.
#ifndef LIBSARIA_PLAYLIST_INTERNAL_H
#define LIBSARIA_PLAYLIST_INTERNAL_H
void load_playlist(void *);
#endif /* LIBSARIA_PLAYLIST_INTERNAL_H */

View File

@ -5,9 +5,11 @@ using namespace std;
#include <libsaria/queue.h>
#include <libsaria/library.h>
#include <libsaria/callback.h>
#include <libsaria/playlist.h>
#include "queue.h"
list<sid_t> playqueue;
libsaria::Playlist queue("queue.q");
static void save_and_refresh()
{