Set queue length on startup
Queues are read from disk *before* libraries are read, meaning we can't calculate the length right away. But if we don't calculate the length, then the first time a track is removed from a queue the length will be set to (0 - track_length). This is wrong. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
2eca396042
commit
8e9bc79e51
|
@ -31,6 +31,7 @@ Gtk::Window *ocarina_init(int *argc, char ***argv)
|
|||
deck::init();
|
||||
library::init();
|
||||
playlist::init();
|
||||
deck::init2();
|
||||
|
||||
share_file("ocarina6.glade");
|
||||
post_init_tabs();
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace deck
|
|||
{
|
||||
|
||||
void init();
|
||||
void init2();
|
||||
void read();
|
||||
void write();
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
void del_track(unsigned int);
|
||||
void track_updated(unsigned int);
|
||||
unsigned int size();
|
||||
void recalculate_length();
|
||||
|
||||
void add_sort(sort_t, bool ascending = true);
|
||||
void reset_sort(sort_t, bool ascending = true);
|
||||
|
|
|
@ -45,6 +45,15 @@ void deck :: init()
|
|||
get_callbacks()->on_queue_changed = write;
|
||||
}
|
||||
|
||||
void deck :: init2()
|
||||
{
|
||||
std::list<Playqueue>::iterator it;
|
||||
|
||||
library_playqueue.recalculate_length();
|
||||
for (it = playqueue_deck.begin(); it != playqueue_deck.end(); it++)
|
||||
it->recalculate_length();
|
||||
}
|
||||
|
||||
void deck :: read()
|
||||
{
|
||||
unsigned int num;
|
||||
|
|
|
@ -272,6 +272,17 @@ unsigned int Playqueue :: size()
|
|||
return tracks.size();
|
||||
}
|
||||
|
||||
void Playqueue :: recalculate_length()
|
||||
{
|
||||
library :: Song song;
|
||||
|
||||
length = 0;
|
||||
for (unsigned int i = 0; i < size(); i++) {
|
||||
library::lookup(tracks[i], &song);
|
||||
length += song.track->length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Sorting function */
|
||||
class SortTracks {
|
||||
|
|
Loading…
Reference in New Issue