This should set the gst pipeline to the correct state when the song is loaded, rather than pausing after telling it to play. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
158 lines
3.3 KiB
C++
158 lines
3.3 KiB
C++
// Copyright (c) 2011 Bryan Schumaker.
|
|
#include <libsaria/playlist.h>
|
|
#include <libsaria/library.h>
|
|
#include <libsaria/audio.h>
|
|
#include <libsaria/track.h>
|
|
#include <libsaria/prefs.h>
|
|
#include <libsaria/deck.h>
|
|
#include <libsaria/idle.h>
|
|
#include <libsaria/fs.h>
|
|
#include "library.h"
|
|
|
|
#include <list>
|
|
#include <string>
|
|
using namespace std;
|
|
|
|
static unsigned int next_id = 0;
|
|
static list<struct libsaria::library::Path> path_list;
|
|
static list<libsaria::library::Driver *> driver_list;
|
|
libsaria::Set lib_playlist("Library", PL_STATIC | PL_NO_DRAIN);
|
|
|
|
void notify_path_updated(libsaria::library::Path *path)
|
|
{
|
|
list<libsaria::library::Driver *>::iterator it;
|
|
for (it = driver_list.begin(); it != driver_list.end(); it++)
|
|
(*it)->path_updated(path);
|
|
}
|
|
|
|
void notify_path_deleted(libsaria::library::Path *path)
|
|
{
|
|
list<libsaria::library::Driver *>::iterator it;
|
|
for (it = driver_list.begin(); it != driver_list.end(); it++)
|
|
(*it)->path_removed(path);
|
|
}
|
|
|
|
libsaria::library::Path *push_path(libsaria::library::Path &path)
|
|
{
|
|
libsaria::library::Path *ptr;
|
|
list<libsaria::library::Driver *>::iterator it;
|
|
|
|
path_list.push_back(path);
|
|
ptr = &path_list.back();
|
|
|
|
/* Notify library drivers that a new path has been added */
|
|
for (it = driver_list.begin(); it != driver_list.end(); it++)
|
|
(*it)->path_added(ptr);
|
|
return ptr;
|
|
}
|
|
|
|
void pop_path(libsaria::library::Path *path)
|
|
{
|
|
list<libsaria::library::Path>::iterator it;
|
|
for (it = path_list.begin(); it != path_list.end(); it++) {
|
|
if ((*it).id == path->id) {
|
|
notify_path_deleted(path);
|
|
path_list.erase(it);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void restore_current()
|
|
{
|
|
unsigned int l_id = libsaria::prefs::get("libsaria.current.library");
|
|
unsigned int t_id = libsaria::prefs::get("libsaria.current.track");
|
|
libsaria::Track *track = libsaria::library::lookup(l_id, t_id);
|
|
if (track)
|
|
track->load(false);
|
|
}
|
|
|
|
namespace libsaria
|
|
{
|
|
|
|
void library::add_path(string dir)
|
|
{
|
|
struct Path path, *path_ptr;
|
|
|
|
path.visible = true;
|
|
path.data_state = CLEAN;
|
|
path.id = next_id++;
|
|
path.next_track = 0;
|
|
path.path = dir;
|
|
|
|
path_ptr = push_path(path);
|
|
do_update_path(path_ptr);
|
|
}
|
|
|
|
void library::delete_path(Path *path)
|
|
{
|
|
list<Track>::iterator it;
|
|
list<Path>::iterator p_it;
|
|
|
|
remove_file(path);
|
|
deck::tracks_removed(path->tracks);
|
|
pop_path(path);
|
|
}
|
|
|
|
void library::update_path(Path *path)
|
|
{
|
|
list<Path>::iterator it;
|
|
|
|
if (path) {
|
|
do_update_path(path);
|
|
return;
|
|
}
|
|
|
|
for (it = path_list.begin(); it != path_list.end(); it++)
|
|
do_update_path(&(*it));
|
|
}
|
|
|
|
Track *library::lookup(unsigned int libid, unsigned int trackid)
|
|
{
|
|
list<Path>::iterator p_it;
|
|
list<Track>::iterator t_it;
|
|
|
|
for (p_it = path_list.begin(); p_it != path_list.end(); p_it++) {
|
|
if (p_it->id == libid)
|
|
break;
|
|
}
|
|
if (p_it == path_list.end())
|
|
return NULL;
|
|
|
|
for (t_it = p_it->tracks.begin(); t_it != p_it->tracks.end(); t_it++) {
|
|
if (t_it->get_id() == trackid)
|
|
break;
|
|
}
|
|
if (t_it == p_it->tracks.end())
|
|
return NULL;
|
|
return &(*t_it);
|
|
}
|
|
|
|
Playlist *library::get_playlist()
|
|
{
|
|
return &lib_playlist;
|
|
}
|
|
|
|
library::Driver::Driver()
|
|
{
|
|
driver_list.push_back(this);
|
|
}
|
|
|
|
library::Driver::~Driver()
|
|
{
|
|
driver_list.remove(this);
|
|
}
|
|
|
|
void library::init()
|
|
{
|
|
IdleCallback *task;
|
|
|
|
app::mkdir("library");
|
|
next_id = schedule_load();
|
|
|
|
task = new IdleCallback(restore_current);
|
|
task->queue();
|
|
}
|
|
|
|
}; /* namespace: libsaria */
|