84 lines
1.6 KiB
C++
84 lines
1.6 KiB
C++
|
|
#include <list>
|
|
using namespace std;
|
|
|
|
#include <libsaria/audio.h>
|
|
#include <libsaria/print.h>
|
|
#include "library.h"
|
|
|
|
static list<TrackTag *> play_list;
|
|
static list<TrackTag *>::iterator cur_track = play_list.end();
|
|
|
|
bool compare_tracktags(TrackTag *one, TrackTag *two)
|
|
{
|
|
if (one->get_artist() < two->get_artist())
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
static bool find_id(ino_t &inode, list<TrackTag *>::iterator &it)
|
|
{
|
|
for (it = play_list.begin(); it != play_list.end(); it++) {
|
|
if ((*it)->get_inode() == inode)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static void insert_list(list<TrackTag> *tag_list)
|
|
{
|
|
list<TrackTag>::iterator it;
|
|
for (it = tag_list->begin(); it != tag_list->end(); it++)
|
|
play_list.push_back(&(*it));
|
|
}
|
|
|
|
namespace libsaria
|
|
{
|
|
|
|
void library::rebuild_list()
|
|
{
|
|
list<LibraryPath> *path_list = get_path_list();
|
|
list<LibraryPath>::iterator it;
|
|
|
|
play_list.clear();
|
|
for (it = path_list->begin(); it != path_list->end(); it++)
|
|
insert_list(it->get_list());
|
|
play_list.sort(compare_tracktags);
|
|
}
|
|
|
|
void library::for_each(SourceModel *model)
|
|
{
|
|
list<TrackTag *>::iterator it;
|
|
for (it = play_list.begin(); it != play_list.end(); it++) {
|
|
Track track = Track(*it);
|
|
model->insert(track);
|
|
}
|
|
}
|
|
|
|
void library::play_id(ino_t &id)
|
|
{
|
|
list<TrackTag *>::iterator it;
|
|
if (find_id(id, it)) {
|
|
cur_track = it;
|
|
libsaria::audio::load((*it)->get_filepath());
|
|
}
|
|
}
|
|
|
|
bool library::get_info(ino_t &id, void (*func)(Track &))
|
|
{
|
|
list<TrackTag *>::iterator it;
|
|
if (find_id(id, it)) {
|
|
Track tag(*it);
|
|
func(tag);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
unsigned int library::size()
|
|
{
|
|
return play_list.size();
|
|
}
|
|
|
|
}; /* Namespace: libsaria */
|