libsaria: Turn the play_list into a list of pointers
Pointers to a TrackTag structure are easier to pass around than the TrackTag structure, so this should speed up sorting. Also it removes duplicated memory between the LibraryPaths and the play_list.
This commit is contained in:
parent
095ade27ad
commit
858fa1821f
|
@ -6,25 +6,32 @@ using namespace std;
|
|||
#include <libsaria/print.h>
|
||||
#include "library.h"
|
||||
|
||||
static list<TrackTag> play_list;
|
||||
static list<TrackTag>::iterator cur_track = play_list.end();
|
||||
static list<TrackTag *> play_list;
|
||||
static list<TrackTag *>::iterator cur_track = play_list.end();
|
||||
|
||||
bool compare_tracktags(TrackTag one, TrackTag two)
|
||||
bool compare_tracktags(TrackTag *one, TrackTag *two)
|
||||
{
|
||||
if (one.get_artist() < two.get_artist())
|
||||
if (one->get_artist() < two->get_artist())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool find_id(ino_t &inode, list<TrackTag>::iterator &it)
|
||||
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)
|
||||
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
|
||||
{
|
||||
|
||||
|
@ -32,42 +39,36 @@ namespace libsaria
|
|||
{
|
||||
list<LibraryPath> *path_list = get_path_list();
|
||||
list<LibraryPath>::iterator it;
|
||||
list<TrackTag> *tag_list;
|
||||
list<TrackTag>::iterator i;
|
||||
|
||||
play_list.clear();
|
||||
|
||||
for (it = path_list->begin(); it != path_list->end(); it++) {
|
||||
tag_list = it->get_list();
|
||||
play_list.insert(play_list.end(), tag_list->begin(), tag_list->end());
|
||||
}
|
||||
|
||||
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;
|
||||
list<TrackTag *>::iterator it;
|
||||
for (it = play_list.begin(); it != play_list.end(); it++) {
|
||||
Track track = Track(&(*it));
|
||||
Track track = Track(*it);
|
||||
model->insert(track);
|
||||
}
|
||||
}
|
||||
|
||||
void library::play_id(ino_t &id)
|
||||
{
|
||||
list<TrackTag>::iterator it;
|
||||
list<TrackTag *>::iterator it;
|
||||
if (find_id(id, it)) {
|
||||
cur_track = it;
|
||||
libsaria::audio::load(it->get_filepath());
|
||||
libsaria::audio::load((*it)->get_filepath());
|
||||
}
|
||||
}
|
||||
|
||||
bool library::get_info(ino_t &id, void (*func)(Track &))
|
||||
{
|
||||
list<TrackTag>::iterator it;
|
||||
list<TrackTag *>::iterator it;
|
||||
if (find_id(id, it)) {
|
||||
Track tag(&(*it));
|
||||
Track tag(*it);
|
||||
func(tag);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue