145 lines
2.8 KiB
C++
145 lines
2.8 KiB
C++
|
|
#include <list>
|
|
#include <string>
|
|
using namespace std;
|
|
|
|
#include <libsaria/audio.h>
|
|
#include <libsaria/model.h>
|
|
#include <libsaria/callback.h>
|
|
#include <libsaria/library.h>
|
|
#include "library.h"
|
|
|
|
static list<LibraryPath> path_list;
|
|
|
|
list<LibraryPath> *get_library_paths()
|
|
{
|
|
return &path_list;
|
|
}
|
|
|
|
LibraryPath *get_library_path(string dir)
|
|
{
|
|
list<LibraryPath>::iterator it;
|
|
for (it = path_list.begin(); it != path_list.end(); it++) {
|
|
if (it->get_path() == dir)
|
|
return &(*it);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void LibraryPath::for_each(libsaria::SourceModel *model)
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
|
|
for (it = file_list.begin(); it != file_list.end(); it++) {
|
|
Track track = Track(&(*it));
|
|
model->insert(track);
|
|
}
|
|
}
|
|
|
|
string LibraryPath::get_path()
|
|
{
|
|
return path;
|
|
}
|
|
|
|
void LibraryPath::get_info(void (*info_func)(struct libsaria::library::PathInfo &))
|
|
{
|
|
struct libsaria::library::PathInfo info;
|
|
info.path = path;
|
|
info.size = size();
|
|
info_func(info);
|
|
}
|
|
|
|
list<TrackTag>::iterator LibraryPath::find_id(ino_t &id)
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
for (it = file_list.begin(); it != file_list.end(); it++) {
|
|
if (it->get_inode() == id)
|
|
break;
|
|
}
|
|
return it;
|
|
}
|
|
|
|
bool LibraryPath::get_info_id(ino_t &id, void (*func)(Track &))
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
it = find_id(id);
|
|
if (it != file_list.end()) {
|
|
Track track = Track(&(*it));
|
|
func(track);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool LibraryPath::play_id(ino_t &id)
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
it = find_id(id);
|
|
if (it == file_list.end())
|
|
return false;
|
|
libsaria::audio::load(it->get_filepath());
|
|
return true;
|
|
}
|
|
|
|
namespace libsaria
|
|
{
|
|
|
|
void library::for_each(SourceModel *model)
|
|
{
|
|
list<LibraryPath>::iterator it;
|
|
for (it = path_list.begin(); it != path_list.end(); it++)
|
|
it->for_each(model);
|
|
}
|
|
|
|
void library::for_each_path(void (*info_func)(struct library::PathInfo &))
|
|
{
|
|
list<LibraryPath>::iterator it;
|
|
for (it = path_list.begin(); it != path_list.end(); it++)
|
|
it->get_info(info_func);
|
|
}
|
|
|
|
void library::update()
|
|
{
|
|
list<LibraryPath>::iterator it;
|
|
for (it = path_list.begin(); it != path_list.end(); it++)
|
|
it->update();
|
|
}
|
|
|
|
void library::play_id(ino_t &id)
|
|
{
|
|
list<LibraryPath>::iterator it;
|
|
for (it = path_list.begin(); it != path_list.end(); it++) {
|
|
if (it->play_id(id) == true)
|
|
break;
|
|
}
|
|
}
|
|
|
|
bool library::get_info(ino_t &id, void (*func)(Track &))
|
|
{
|
|
bool found = false;
|
|
list<LibraryPath>::iterator it;
|
|
for (it = path_list.begin(); it != path_list.end(); it++) {
|
|
if (it->get_info_id(id, func) == true) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
unsigned int library::size()
|
|
{
|
|
unsigned int size = 0;
|
|
list<LibraryPath>::iterator it;
|
|
for (it = path_list.begin(); it != path_list.end(); it++)
|
|
size += it->size();
|
|
return size;
|
|
}
|
|
|
|
void library::refresh()
|
|
{
|
|
trigger_callback(LIBRARY_REFRESH);
|
|
}
|
|
|
|
}; /* namespace: libsaria */
|