libsaria: Introduce bare Index class
Right now I just add and remove songs from the index as they are added and removed from the playlist. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
2fb2f97a43
commit
556aad3344
|
@ -1,24 +1,41 @@
|
|||
#ifndef LIBSARIA_INDEX_H
|
||||
#define LIBSARIA_INDEX_H
|
||||
|
||||
#include <libsaria/track.h>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
namespace index
|
||||
class Track;
|
||||
|
||||
class Index {
|
||||
private:
|
||||
map<string, set<Track *> > global_index;
|
||||
|
||||
public:
|
||||
Index();
|
||||
~Index();
|
||||
|
||||
void add_track(Track *);
|
||||
void remove_track(Track *);
|
||||
};
|
||||
|
||||
/* namespace index
|
||||
{
|
||||
|
||||
void add_track(libsaria::Track *);
|
||||
void filter(string &);
|
||||
void refresh();
|
||||
// bool is_visible(sid_t &);
|
||||
bool is_visible(sid_t &);
|
||||
bool is_filtered();
|
||||
unsigned int size();
|
||||
// sid_t rand_id();
|
||||
sid_t rand_id();
|
||||
void print_stats();
|
||||
|
||||
}; /* Namespace: index */
|
||||
}; *//* Namespace: index */
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
#endif /* LIBSARIA_INDEX_H */
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef LIBSARIA_PLAYLIST_H
|
||||
#define LIBSARIA_PLAYLIST_H
|
||||
|
||||
#include <libsaria/index.h>
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
@ -37,10 +39,12 @@ namespace libsaria
|
|||
unsigned int length;
|
||||
PlaylistType type;
|
||||
list<Track *>::iterator cur;
|
||||
Index index;
|
||||
|
||||
void incr_iter();
|
||||
Track *picked_next();
|
||||
unsigned int find_cur_index();
|
||||
void add_track(Track *, unsigned int);
|
||||
void do_remove_tracks(list<Track *> &);
|
||||
void remove_track_it(list<Track *>::iterator &it, unsigned int);
|
||||
|
||||
|
|
|
@ -85,20 +85,36 @@ static void index_tag(sid_t &songid, const string &tag,
|
|||
namespace libsaria
|
||||
{
|
||||
|
||||
void index::add_track(libsaria::Track *track)
|
||||
Index::Index()
|
||||
{
|
||||
/* sid_t songid = track->get_songid();
|
||||
}
|
||||
|
||||
Index::~Index()
|
||||
{
|
||||
}
|
||||
|
||||
void Index::add_track(Track *track)
|
||||
{
|
||||
}
|
||||
|
||||
void Index::remove_track(Track *track)
|
||||
{
|
||||
}
|
||||
|
||||
/* void index::add_track(libsaria::Track *track)
|
||||
{
|
||||
sid_t songid = track->get_songid();
|
||||
index_tag(songid, track->get_artist(), &artist_index);
|
||||
index_tag(songid, track->get_album(), &album_index);
|
||||
index_tag(songid, track->get_title(), &title_index);*/
|
||||
index_tag(songid, track->get_title(), &title_index);
|
||||
}
|
||||
|
||||
void index::print_stats()
|
||||
{
|
||||
// println("Index cache hits: %u size: %u", hits, substr_cache.size());
|
||||
println("Index cache hits: %u size: %u", hits, substr_cache.size());
|
||||
}
|
||||
|
||||
/*( sid_t index::rand_id()
|
||||
sid_t index::rand_id()
|
||||
{
|
||||
set<sid_t>::iterator it = results.begin();
|
||||
unsigned int index = rand() % results.size();
|
||||
|
|
|
@ -13,11 +13,19 @@ static bool compare_tracks(libsaria::Track *one, libsaria::Track *two)
|
|||
namespace libsaria
|
||||
{
|
||||
|
||||
void Playlist::remove_track_it(list<Track *>::iterator &it, unsigned int index)
|
||||
void Playlist::add_track(Track *track, unsigned int ins_index)
|
||||
{
|
||||
length += track->get_length();
|
||||
index.add_track(track);
|
||||
RENDER( insert(track, ins_index) );
|
||||
}
|
||||
|
||||
void Playlist::remove_track_it(list<Track *>::iterator &it, unsigned int rm_index)
|
||||
{
|
||||
length -= (*it)->get_length();
|
||||
index.remove_track(*it);
|
||||
it = plist.erase(it);
|
||||
RENDER( remove_index(index) );
|
||||
RENDER( remove_index(rm_index) );
|
||||
}
|
||||
|
||||
void Playlist::do_remove_tracks(list<Track *> &tracks)
|
||||
|
@ -73,8 +81,7 @@ namespace libsaria
|
|||
it = tracks.begin();
|
||||
for (cur_it = plist.begin(); cur_it != plist.end(); cur_it++) {
|
||||
if ((*cur_it) == (*it)) {
|
||||
length += (*it)->get_length();
|
||||
RENDER( insert(*it, ins_index) );
|
||||
add_track(*it, ins_index);
|
||||
if (it++ == tracks.end())
|
||||
break;
|
||||
};
|
||||
|
@ -95,8 +102,7 @@ namespace libsaria
|
|||
|
||||
for (it = tracks.begin(); it != tracks.end(); it++) {
|
||||
plist.push_back(*it);
|
||||
length += (*it)->get_length();
|
||||
RENDER( insert(*it, plist.size()) );
|
||||
add_track(*it, plist.size());
|
||||
};
|
||||
|
||||
if (plist.size() == tracks.size())
|
||||
|
@ -113,8 +119,7 @@ namespace libsaria
|
|||
tracks.reverse();
|
||||
for (it = tracks.begin(); it != tracks.end(); it++) {
|
||||
plist.push_front(*it);
|
||||
length += (*it)->get_length();
|
||||
RENDER( insert(*it, 0) );
|
||||
add_track(*it, 0);
|
||||
}
|
||||
|
||||
RENDER(modify_done());
|
||||
|
|
Loading…
Reference in New Issue