deck: Add a library playqueue
When no songs are on the deck a track will be played from the library. Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
25ee2e945c
commit
74da7beba1
|
@ -13,14 +13,23 @@ Deck: (lib/deck.cpp)
|
|||
The playqueue deck is used to hold the temporary playqueues created by
|
||||
the user.
|
||||
|
||||
This module also controls the library playqueue, which should be updated
|
||||
using the on_library_track_add() and on_library_track_del() callback
|
||||
functions. The library playqueue will always have PQ_ENABLED and
|
||||
PQ_REPEAT set. This playlist will default to PQ_RANDOM unset.
|
||||
|
||||
- Deck:
|
||||
list<Playqueue> deck;
|
||||
Playqueue library_pq;
|
||||
|
||||
File << deck.size() << endl;
|
||||
File << library_pq.random << deck.size() << endl;
|
||||
File << deck[0] << endl;
|
||||
File << deck[N] << endl;
|
||||
|
||||
- API
|
||||
void deck :: init();
|
||||
Set up callbacks used by the library.
|
||||
|
||||
void deck :: read(File &);
|
||||
void deck :: write(File &);
|
||||
Read or write the playqueue file. This will be called
|
||||
|
@ -47,6 +56,9 @@ Deck: (lib/deck.cpp)
|
|||
If the playqueue is empty after calling next(), remove it from
|
||||
the deck.
|
||||
|
||||
If there are no playqueues on the deck, play a song from the
|
||||
library playqueue.
|
||||
|
||||
If there are no playable IDs, throw -EEXIST.
|
||||
|
||||
void deck :: reset();
|
||||
|
@ -56,3 +68,6 @@ Deck: (lib/deck.cpp)
|
|||
void deck :: print_info();
|
||||
This function only exists if CONFIG_TEST is enabled. Print
|
||||
out helpful stats about the current state of the playqueue deck.
|
||||
|
||||
Playqueue *deck :: get_library_pq();
|
||||
Return the library playqueue.
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
namespace deck
|
||||
{
|
||||
|
||||
void init();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
|
||||
|
@ -17,6 +18,7 @@ namespace deck
|
|||
Playqueue *get(unsigned int);
|
||||
void move(unsigned int, unsigned int);
|
||||
unsigned int next();
|
||||
Playqueue *get_library_pq();
|
||||
|
||||
#ifdef CONFIG_TEST
|
||||
void reset();
|
||||
|
|
34
lib/deck.cpp
34
lib/deck.cpp
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <callback.h>
|
||||
#include <deck.h>
|
||||
#include <error.h>
|
||||
#include <print.h>
|
||||
|
@ -8,13 +9,36 @@
|
|||
#include <list>
|
||||
|
||||
static std::list<Playqueue> playqueue_deck;
|
||||
static Playqueue library_playqueue(PQ_ENABLED);
|
||||
|
||||
static void add_library_track(unsigned int id)
|
||||
{
|
||||
library_playqueue.add(id);
|
||||
}
|
||||
|
||||
static void del_library_track(unsigned int id)
|
||||
{
|
||||
library_playqueue.del_track(id);
|
||||
}
|
||||
|
||||
void deck :: init()
|
||||
{
|
||||
library_playqueue.set_flag(PQ_REPEAT);
|
||||
get_callbacks()->on_library_track_add = add_library_track;
|
||||
get_callbacks()->on_library_track_del = del_library_track;
|
||||
}
|
||||
|
||||
void deck :: read(File &f)
|
||||
{
|
||||
unsigned int num;
|
||||
bool random;
|
||||
std::list<Playqueue>::iterator it;
|
||||
|
||||
f >> num;
|
||||
f >> random >> num;
|
||||
|
||||
if (random)
|
||||
library_playqueue.set_flag(PQ_RANDOM);
|
||||
|
||||
playqueue_deck.resize(num);
|
||||
|
||||
for (it = playqueue_deck.begin(); it != playqueue_deck.end(); it++)
|
||||
|
@ -25,6 +49,7 @@ void deck :: write(File &f)
|
|||
{
|
||||
std::list<Playqueue>::iterator it;
|
||||
|
||||
f << (library_playqueue.get_flags() & PQ_RANDOM) << " ";
|
||||
f << playqueue_deck.size() << std :: endl;
|
||||
for (it = playqueue_deck.begin(); it != playqueue_deck.end(); it++) {
|
||||
it->write(f);
|
||||
|
@ -86,7 +111,12 @@ unsigned int deck :: next()
|
|||
}
|
||||
}
|
||||
|
||||
throw -E_EXIST;
|
||||
return library_playqueue.next();
|
||||
}
|
||||
|
||||
Playqueue *deck :: get_library_pq()
|
||||
{
|
||||
return &library_playqueue;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TEST
|
||||
|
|
|
@ -79,15 +79,10 @@ void test_4()
|
|||
deck :: get(1)->unset_flag(PQ_ENABLED);
|
||||
deck :: get(4)->unset_flag(PQ_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;
|
||||
}
|
||||
for (unsigned int i = 0; i < 40; i++) {
|
||||
print("Playing id: %u\n", deck :: next());
|
||||
if (i == 11 || i == 25)
|
||||
deck :: print_info();
|
||||
}
|
||||
|
||||
deck :: print_info();
|
||||
|
@ -124,10 +119,12 @@ void test_5()
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
deck :: init();
|
||||
library :: init();
|
||||
library :: reset();
|
||||
library :: add_path("/tmp/library/0");
|
||||
while (idle :: run_task());
|
||||
print("Library size: %u\n", deck :: get_library_pq()->size());
|
||||
|
||||
test_0();
|
||||
test_1();
|
||||
|
@ -135,5 +132,10 @@ int main(int argc, char **argv)
|
|||
test_3();
|
||||
test_4();
|
||||
test_5();
|
||||
|
||||
library :: del_path(0);
|
||||
while (idle :: run_task());
|
||||
print("Library size: %u\n", deck :: get_library_pq()->size());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
Library size: 150
|
||||
Test 0:
|
||||
deck[0] = Playqueue { size = 10, flags = 1 }
|
||||
deck[1] = Playqueue { size = 11, flags = 1 }
|
||||
|
@ -109,7 +110,10 @@ Playing id: 6
|
|||
Playing id: 7
|
||||
Playing id: 8
|
||||
Playing id: 9
|
||||
No playable tracks!
|
||||
Playing id: 0
|
||||
Playing id: 1
|
||||
Playing id: 2
|
||||
Playing id: 3
|
||||
deck[0] = Playqueue { size = 16, flags = 0 }
|
||||
deck[1] = Playqueue { size = 19, flags = 0 }
|
||||
deck[2] = Playqueue { size = 15, flags = 0 }
|
||||
|
@ -121,3 +125,4 @@ Reading back playqueue deck
|
|||
deck[0] = Playqueue { size = 16, flags = 0 }
|
||||
deck[1] = Playqueue { size = 19, flags = 1 }
|
||||
deck[2] = Playqueue { size = 15, flags = 3 }
|
||||
Library size: 0
|
||||
|
|
Loading…
Reference in New Issue