libsaria: Notify playlist renderers when new tracks are added
For sets, I keep a sorted list and merge-sort the new songs. I also created insert_prepare() and insert_done() functions to tell the UI that we are about to insert (this gives me a chance to call the freeze_child_notify() and thaw_child_notify() in GTK). Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
50f2f99074
commit
6bb3cd38a4
|
@ -12,6 +12,11 @@ enum PlaylistFlags {
|
|||
PL_STATIC = (1 << 1),
|
||||
};
|
||||
|
||||
#define RENDER(x) \
|
||||
if (renderer) { \
|
||||
renderer->x; \
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -26,6 +31,7 @@ namespace libsaria
|
|||
protected:
|
||||
string name;
|
||||
list<Track *> plist;
|
||||
PlaylistRenderer *renderer;
|
||||
/*bool del_renderer;
|
||||
unsigned int flags;
|
||||
string filename;
|
||||
|
@ -45,6 +51,7 @@ namespace libsaria
|
|||
Playlist(string, unsigned int);
|
||||
//Playlist(string, unsigned int);
|
||||
~Playlist();
|
||||
void set_renderer(PlaylistRenderer *);
|
||||
|
||||
string &get_name();
|
||||
unsigned int get_size();
|
||||
|
|
|
@ -17,6 +17,10 @@ namespace libsaria
|
|||
~PlaylistRenderer();
|
||||
|
||||
void set_playlist(Playlist *);
|
||||
|
||||
virtual void insert_prepare();
|
||||
virtual void insert(Track *, unsigned int);
|
||||
virtual void insert_done();
|
||||
};
|
||||
|
||||
/*class PlaylistRenderer {
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace libsaria
|
|||
string album;
|
||||
string comment;
|
||||
string genre;
|
||||
/* string lenstr;*/
|
||||
string lenstr;
|
||||
unsigned int year;
|
||||
unsigned int track;
|
||||
unsigned int count;
|
||||
|
@ -44,18 +44,18 @@ namespace libsaria
|
|||
Track(InFile &);
|
||||
~Track();
|
||||
void save(OutFile &);
|
||||
void do_cleanup();
|
||||
void do_cleanup();*/
|
||||
|
||||
string get_filepath();
|
||||
string &get_filepath();
|
||||
string get_title();
|
||||
string get_artist();
|
||||
string get_album();
|
||||
string get_comment();
|
||||
string get_genre();
|
||||
string get_lenstr();
|
||||
unsigned int get_year();
|
||||
unsigned int get_track();
|
||||
int get_length();
|
||||
string &get_artist();
|
||||
string &get_album();
|
||||
string &get_comment();
|
||||
string &get_genre();
|
||||
string &get_lenstr();
|
||||
unsigned int &get_year();
|
||||
unsigned int &get_track();
|
||||
/*int get_length();
|
||||
int get_bitrate();
|
||||
int get_channels();
|
||||
sid_t get_songid();*/
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#include <libsaria/playlist.h>
|
||||
#include <libsaria/renderer.h>
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/print.h>
|
||||
|
||||
|
@ -14,16 +15,28 @@ namespace libsaria
|
|||
|
||||
void Playlist::add_sorted(list<Track *> &tracks)
|
||||
{
|
||||
list<Track *>::iterator it, ins;
|
||||
list<Track *> copy;
|
||||
list<Track *>::iterator it, cur;
|
||||
unsigned int ins_index;
|
||||
|
||||
RENDER(insert_prepare());
|
||||
tracks.sort(compare_tracks);
|
||||
|
||||
ins = plist.begin();
|
||||
for (it = tracks.begin(); it != tracks.end(); it++) {
|
||||
while (((*it) < (*ins)) && (ins != plist.end()))
|
||||
ins++;
|
||||
plist.insert(ins, (*it));
|
||||
copy = tracks;
|
||||
plist.merge(copy, compare_tracks);
|
||||
|
||||
ins_index = 0;
|
||||
it = tracks.begin();
|
||||
for (cur = plist.begin(); cur != plist.end(); cur++) {
|
||||
if ((*cur) == (*it)) {
|
||||
RENDER( insert(*it, ins_index) );
|
||||
if (it++ == tracks.end())
|
||||
break;
|
||||
};
|
||||
ins_index++;
|
||||
}
|
||||
|
||||
RENDER(insert_done());
|
||||
}
|
||||
|
||||
}; /* namespace: libsaria */
|
||||
|
|
|
@ -44,6 +44,7 @@ namespace libsaria
|
|||
{
|
||||
name = n;
|
||||
flags = f;
|
||||
renderer = NULL;
|
||||
}
|
||||
|
||||
Playlist::~Playlist()
|
||||
|
@ -60,13 +61,12 @@ namespace libsaria
|
|||
return plist.size();
|
||||
}
|
||||
|
||||
/*void Playlist::set_renderer(PlaylistRenderer *render, bool del_render)
|
||||
void Playlist::set_renderer(PlaylistRenderer *r)
|
||||
{
|
||||
renderer = render;
|
||||
del_renderer = del_render;
|
||||
renderer = r;
|
||||
}
|
||||
|
||||
void Playlist::delete_renderer()
|
||||
/*void Playlist::delete_renderer()
|
||||
{
|
||||
if (del_renderer && renderer)
|
||||
delete renderer;
|
||||
|
|
|
@ -17,6 +17,19 @@ namespace libsaria
|
|||
void PlaylistRenderer::set_playlist(Playlist *p)
|
||||
{
|
||||
playlist = p;
|
||||
playlist->set_renderer(this);
|
||||
}
|
||||
|
||||
void PlaylistRenderer::insert_prepare()
|
||||
{
|
||||
}
|
||||
|
||||
void PlaylistRenderer::insert(Track *t, unsigned int index)
|
||||
{
|
||||
}
|
||||
|
||||
void PlaylistRenderer::insert_done()
|
||||
{
|
||||
}
|
||||
|
||||
/*void PlaylistRenderer::set_playlist(Playlist *plist, bool del_render)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
namespace libsaria
|
||||
{
|
||||
|
||||
/*string Track::get_filepath()
|
||||
string &Track::get_filepath()
|
||||
{
|
||||
return filepath;
|
||||
}
|
||||
|
@ -14,17 +14,17 @@ namespace libsaria
|
|||
return title;
|
||||
}
|
||||
|
||||
string Track::get_artist()
|
||||
string &Track::get_artist()
|
||||
{
|
||||
return artist;
|
||||
}
|
||||
|
||||
string Track::get_album()
|
||||
string &Track::get_album()
|
||||
{
|
||||
return album;
|
||||
}
|
||||
|
||||
string Track::get_comment()
|
||||
/*string Track::get_comment()
|
||||
{
|
||||
return comment;
|
||||
}
|
||||
|
@ -32,24 +32,24 @@ namespace libsaria
|
|||
string Track::get_genre()
|
||||
{
|
||||
return genre;
|
||||
}
|
||||
}*/
|
||||
|
||||
string Track::get_lenstr()
|
||||
string &Track::get_lenstr()
|
||||
{
|
||||
return lenstr;
|
||||
}
|
||||
|
||||
unsigned int Track::get_year()
|
||||
unsigned int &Track::get_year()
|
||||
{
|
||||
return year;
|
||||
}
|
||||
|
||||
unsigned int Track::get_track()
|
||||
unsigned int &Track::get_track()
|
||||
{
|
||||
return track;
|
||||
}
|
||||
|
||||
int Track::get_length()
|
||||
/* int Track::get_length()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright (c) 2011 Bryan Schumaker.
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/print.h>
|
||||
|
||||
/*
|
||||
* Return positive value if s1 > s2
|
||||
|
|
|
@ -6,7 +6,25 @@
|
|||
|
||||
#include <taglib/tag.h>
|
||||
#include <taglib/fileref.h>
|
||||
/*#include <sstream>*/
|
||||
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
static void make_lenstr(unsigned int length, string &res)
|
||||
{
|
||||
int minutes;
|
||||
int seconds;
|
||||
stringstream stream;
|
||||
|
||||
/* Convert length into mm:ss format */
|
||||
minutes = length / 60;
|
||||
seconds = length - (minutes * 60);
|
||||
stream << minutes << ":";
|
||||
if (seconds < 10)
|
||||
stream << "0";
|
||||
stream << seconds;
|
||||
res = stream.str();
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
@ -51,6 +69,7 @@ namespace libsaria
|
|||
|
||||
artist_lc = lowercase(artist);
|
||||
album_lc = lowercase(album);
|
||||
make_lenstr(length, lenstr);
|
||||
}
|
||||
|
||||
Track::~Track()
|
||||
|
|
Loading…
Reference in New Issue