deck: Add callbacks for new playqueue creation

Used by the gui to set the playqueue on the correct page.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2014-01-30 22:31:36 -05:00 committed by Anna Schumaker
parent 1e4faeaff0
commit 32841901db
3 changed files with 23 additions and 3 deletions

View File

@ -15,6 +15,10 @@ struct Callbacks {
void (*on_track_loaded)(library :: Song &);
void (*on_pause_count_changed)(bool, unsigned int);
/* Deck callbacks */
void (*on_pq_created)(Playqueue *, unsigned int);
void (*on_pq_removed)(Playqueue *);
/* Library callbacks */
void (*on_library_add)(unsigned int, library :: Library *);
void (*on_library_update)(unsigned int, library :: Library *);

View File

@ -9,6 +9,7 @@ static void no_op(unsigned int) {}
static void no_op(bool, unsigned int) {}
static void no_op(unsigned int id, library :: Library *path) {}
static void no_op(Playqueue *, unsigned int) {}
static void no_op(Playqueue *) {}
static void no_op(library :: Song &) {}
@ -18,6 +19,9 @@ static struct Callbacks callbacks = {
.on_track_loaded = no_op,
.on_pause_count_changed = no_op,
.on_pq_created = no_op,
.on_pq_removed = no_op,
.on_library_add = no_op,
.on_library_update = no_op,
.on_library_track_add = no_op,

View File

@ -71,8 +71,12 @@ void deck :: read()
playqueue_deck.resize(num);
for (it = playqueue_deck.begin(); it != playqueue_deck.end(); it++)
num = 0;
for (it = playqueue_deck.begin(); it != playqueue_deck.end(); it++) {
it->read(deck_file);
get_callbacks()->on_pq_created(&(*it), num);
num++;
}
deck_file.close();
}
@ -101,8 +105,11 @@ void deck :: write()
Playqueue *deck :: create()
{
Playqueue *pq;
playqueue_deck.push_back(Playqueue(PQ_ENABLED));
return &playqueue_deck.back();
pq = &playqueue_deck.back();
get_callbacks()->on_pq_created(pq, playqueue_deck.size() - 1);
return pq;
}
void deck :: remove(unsigned int id)
@ -110,7 +117,9 @@ void deck :: remove(unsigned int id)
std::list<Playqueue>::iterator it = playqueue_deck.begin();
for (unsigned int i = 0; i < id; i++)
it++;
get_callbacks()->on_pq_removed(&(*it));
playqueue_deck.erase(it);
write();
}
Playqueue *deck :: get(unsigned int id)
@ -147,8 +156,11 @@ unsigned int deck :: next()
for (it = playqueue_deck.begin(); it != playqueue_deck.end(); it++) {
if (it->get_flags() & PQ_ENABLED) {
id = it->next();
if (it->size() == 0)
if (it->size() == 0) {
playqueue_deck.erase(it);
get_callbacks()->on_pq_removed(&(*it));
}
write();
return id;
}
}