2013-12-22 22:21:19 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <deck.h>
|
|
|
|
#include <print.h>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
static std::list<Playlist> playlist_deck;
|
|
|
|
|
|
|
|
Playlist *deck :: create()
|
|
|
|
{
|
|
|
|
playlist_deck.push_back(Playlist(PL_ENABLED));
|
|
|
|
return &playlist_deck.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
void deck :: remove(unsigned int id)
|
|
|
|
{
|
|
|
|
std::list<Playlist>::iterator it = playlist_deck.begin();
|
|
|
|
for (unsigned int i = 0; i < id; i++)
|
|
|
|
it++;
|
|
|
|
playlist_deck.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
Playlist *deck :: get(unsigned int id)
|
|
|
|
{
|
|
|
|
std::list<Playlist>::iterator it = playlist_deck.begin();
|
|
|
|
for (unsigned int i = 0; i < id; i++)
|
|
|
|
it++;
|
|
|
|
return &(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deck :: move(unsigned int old_pos, unsigned int new_pos)
|
|
|
|
{
|
|
|
|
std::list<Playlist>::iterator it_old = playlist_deck.begin();
|
|
|
|
std::list<Playlist>::iterator it_new = playlist_deck.begin();
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < playlist_deck.size(); i++) {
|
|
|
|
if (i < old_pos)
|
|
|
|
it_old++;
|
|
|
|
if (i < new_pos)
|
|
|
|
it_new++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_pos > old_pos)
|
|
|
|
it_new++;
|
|
|
|
|
|
|
|
playlist_deck.splice(it_new, playlist_deck, it_old);
|
|
|
|
}
|
|
|
|
|
2013-12-23 10:22:37 -05:00
|
|
|
unsigned int deck :: next()
|
|
|
|
{
|
|
|
|
unsigned int id = 0;
|
|
|
|
std::list<Playlist>::iterator it;
|
|
|
|
|
|
|
|
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++) {
|
|
|
|
if (it->get_flags() & PL_ENABLED) {
|
|
|
|
id = it->next();
|
|
|
|
if (it->size() == 0)
|
|
|
|
playlist_deck.erase(it);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw -1;
|
|
|
|
}
|
|
|
|
|
2013-12-22 22:21:19 -05:00
|
|
|
#ifdef CONFIG_DEBUG
|
|
|
|
void deck :: print_info()
|
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
std::list<Playlist>::iterator it;
|
|
|
|
|
|
|
|
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++) {
|
|
|
|
print("deck[%u] = Playlist { size = %u, flags = %u }\n",
|
|
|
|
i, it->size(), it->get_flags());
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DEBUG */
|