deck: Implement next()
I make sure to remove empty playlists from the deck and throw an error if there are no playable tracks on the deck. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
fecc10ab5e
commit
83a8b5ae1d
|
@ -47,6 +47,8 @@ Deck: (lib/deck.cpp)
|
||||||
If the playlist is empty after calling next(), remove it from
|
If the playlist is empty after calling next(), remove it from
|
||||||
the deck.
|
the deck.
|
||||||
|
|
||||||
|
If there are no playable IDs, throw -1.
|
||||||
|
|
||||||
void deck :: reset();
|
void deck :: reset();
|
||||||
This function only exists if CONFIG_DEBUG is enabled. Erase
|
This function only exists if CONFIG_DEBUG is enabled. Erase
|
||||||
all the playlist information and reset the deck list.
|
all the playlist information and reset the deck list.
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace deck
|
||||||
void remove(unsigned int);
|
void remove(unsigned int);
|
||||||
Playlist *get(unsigned int);
|
Playlist *get(unsigned int);
|
||||||
void move(unsigned int, unsigned int);
|
void move(unsigned int, unsigned int);
|
||||||
|
unsigned int next();
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG
|
#ifdef CONFIG_DEBUG
|
||||||
void print_info();
|
void print_info();
|
||||||
|
|
17
lib/deck.cpp
17
lib/deck.cpp
|
@ -48,6 +48,23 @@ void deck :: move(unsigned int old_pos, unsigned int new_pos)
|
||||||
playlist_deck.splice(it_new, playlist_deck, it_old);
|
playlist_deck.splice(it_new, playlist_deck, it_old);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG
|
#ifdef CONFIG_DEBUG
|
||||||
void deck :: print_info()
|
void deck :: print_info()
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,11 +68,35 @@ void test_3()
|
||||||
print("\n");
|
print("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Test the next() function for playlists */
|
||||||
|
void test_4()
|
||||||
|
{
|
||||||
|
print("Test 4:\n");
|
||||||
|
|
||||||
|
deck :: get(0)->unset_flag(PL_ENABLED);
|
||||||
|
deck :: get(1)->unset_flag(PL_ENABLED);
|
||||||
|
deck :: get(4)->unset_flag(PL_ENABLED);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < 37; i++) {
|
||||||
|
try {
|
||||||
|
print("Playing id: %u\n", deck :: next());
|
||||||
|
if (i == 11 || i == 25)
|
||||||
|
deck :: print_info();
|
||||||
|
} catch (int error) {
|
||||||
|
print("No playable tracks!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deck :: print_info();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
test_0();
|
test_0();
|
||||||
test_1();
|
test_1();
|
||||||
test_2();
|
test_2();
|
||||||
test_3();
|
test_3();
|
||||||
|
test_4();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,3 +55,61 @@ deck[2] = Playlist { size = 12, flags = 1 }
|
||||||
deck[3] = Playlist { size = 14, flags = 1 }
|
deck[3] = Playlist { size = 14, flags = 1 }
|
||||||
deck[4] = Playlist { size = 15, flags = 1 }
|
deck[4] = Playlist { size = 15, flags = 1 }
|
||||||
deck[5] = Playlist { size = 10, flags = 1 }
|
deck[5] = Playlist { size = 10, flags = 1 }
|
||||||
|
|
||||||
|
deck[0] = Playlist { size = 16, flags = 1 }
|
||||||
|
deck[1] = Playlist { size = 19, flags = 1 }
|
||||||
|
deck[2] = Playlist { size = 12, flags = 1 }
|
||||||
|
deck[3] = Playlist { size = 14, flags = 1 }
|
||||||
|
deck[4] = Playlist { size = 15, flags = 1 }
|
||||||
|
deck[5] = Playlist { size = 10, flags = 1 }
|
||||||
|
|
||||||
|
Test 4:
|
||||||
|
Playing id: 0
|
||||||
|
Playing id: 1
|
||||||
|
Playing id: 2
|
||||||
|
Playing id: 3
|
||||||
|
Playing id: 4
|
||||||
|
Playing id: 5
|
||||||
|
Playing id: 6
|
||||||
|
Playing id: 7
|
||||||
|
Playing id: 8
|
||||||
|
Playing id: 9
|
||||||
|
Playing id: 10
|
||||||
|
Playing id: 11
|
||||||
|
deck[0] = Playlist { size = 16, flags = 0 }
|
||||||
|
deck[1] = Playlist { size = 19, flags = 0 }
|
||||||
|
deck[2] = Playlist { size = 14, flags = 1 }
|
||||||
|
deck[3] = Playlist { size = 15, flags = 0 }
|
||||||
|
deck[4] = Playlist { size = 10, flags = 1 }
|
||||||
|
Playing id: 0
|
||||||
|
Playing id: 1
|
||||||
|
Playing id: 2
|
||||||
|
Playing id: 3
|
||||||
|
Playing id: 4
|
||||||
|
Playing id: 5
|
||||||
|
Playing id: 6
|
||||||
|
Playing id: 7
|
||||||
|
Playing id: 8
|
||||||
|
Playing id: 9
|
||||||
|
Playing id: 10
|
||||||
|
Playing id: 11
|
||||||
|
Playing id: 12
|
||||||
|
Playing id: 13
|
||||||
|
deck[0] = Playlist { size = 16, flags = 0 }
|
||||||
|
deck[1] = Playlist { size = 19, flags = 0 }
|
||||||
|
deck[2] = Playlist { size = 15, flags = 0 }
|
||||||
|
deck[3] = Playlist { size = 10, flags = 1 }
|
||||||
|
Playing id: 0
|
||||||
|
Playing id: 1
|
||||||
|
Playing id: 2
|
||||||
|
Playing id: 3
|
||||||
|
Playing id: 4
|
||||||
|
Playing id: 5
|
||||||
|
Playing id: 6
|
||||||
|
Playing id: 7
|
||||||
|
Playing id: 8
|
||||||
|
Playing id: 9
|
||||||
|
No playable tracks!
|
||||||
|
deck[0] = Playlist { size = 16, flags = 0 }
|
||||||
|
deck[1] = Playlist { size = 19, flags = 0 }
|
||||||
|
deck[2] = Playlist { size = 15, flags = 0 }
|
||||||
|
|
Loading…
Reference in New Issue