libsaria: Implement pause after N tracks
I keep a counter that is decremented after every call to next(). When it reaches zero, pause after loading the next song. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
cb29bcba48
commit
2cdfbde9be
|
@ -6,6 +6,11 @@
|
|||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
enum AutoPauseType {
|
||||
PS_NONE,
|
||||
PS_AFTER_N,
|
||||
};
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -20,6 +25,8 @@ namespace libsaria
|
|||
PlaylistRenderer *get_nth_renderer(unsigned int);
|
||||
void add_to_nth_plist(unsigned int, list<Track *> &);
|
||||
void tracks_removed(list<Track> &);
|
||||
void set_pause_type(AutoPauseType, unsigned int);
|
||||
AutoPauseType get_pause_type();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#include <libsaria/playlist.h>
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/deck.h>
|
||||
|
@ -12,6 +13,9 @@ static unsigned int max_playlists = 10;
|
|||
static unsigned int num_static = 0;
|
||||
static void (*on_new_playlist)(libsaria::Playlist *) = NULL;
|
||||
|
||||
static AutoPauseType pause_type;
|
||||
static unsigned int pause_count = 0;
|
||||
|
||||
static list<libsaria::Playlist *> playlist_deck;
|
||||
static libsaria::List recent_plist("Recent", PL_STATIC | PL_NO_DRAIN);
|
||||
|
||||
|
@ -45,6 +49,20 @@ libsaria::Playlist *find_nth_plist(unsigned int n)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void check_pause()
|
||||
{
|
||||
switch(pause_type) {
|
||||
case PS_AFTER_N:
|
||||
if (pause_count == 0) {
|
||||
libsaria::audio::pause();
|
||||
pause_type = PS_NONE;
|
||||
}
|
||||
pause_count--;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -69,6 +87,7 @@ namespace libsaria
|
|||
if (track) {
|
||||
track->play_now();
|
||||
list_recent_track(track);
|
||||
check_pause();
|
||||
}
|
||||
|
||||
if ((plist->get_size() == 0) && (plist->is_static() == false)) {
|
||||
|
@ -156,4 +175,15 @@ namespace libsaria
|
|||
(*it)->force_remove_tracks(track_ptrs);
|
||||
}
|
||||
|
||||
void deck::set_pause_type(AutoPauseType type, unsigned int count)
|
||||
{
|
||||
pause_type = type;
|
||||
pause_count = count;
|
||||
}
|
||||
|
||||
AutoPauseType deck::get_pause_type()
|
||||
{
|
||||
return pause_type;
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
Loading…
Reference in New Issue