libsaria: Move deck::next() to deck.cpp
And extra variables / functions needed by next(). Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
3a486082af
commit
acb0334122
|
@ -25,7 +25,7 @@ namespace libsaria
|
|||
Playlist *new_playlist(list<Track *> &, unsigned int, bool);
|
||||
void delete_playlist(Playlist *);
|
||||
unsigned int move_playlist(Playlist *, unsigned int);
|
||||
unsigned int num_playlists();
|
||||
unsigned int size();
|
||||
|
||||
Playlist *get_playlist(unsigned int);
|
||||
unsigned int get_playlist_index(Playlist *);
|
||||
|
|
|
@ -1,13 +1,43 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker.
|
||||
#include <deck.h>
|
||||
#include <track.h>
|
||||
#include <library.h>
|
||||
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
static AutoPauseType pause_type;
|
||||
static unsigned short pause_count = 0;
|
||||
|
||||
static vector<libsaria::Playlist *> playlist_deck;
|
||||
static libsaria::Playlist recent_playlist(PL_STATIC | PL_NO_DRAIN | PL_UNIQUE);
|
||||
|
||||
static libsaria::Playlist *get_active_playlist()
|
||||
{
|
||||
for (unsigned int i = 0; i < playlist_deck.size(); i++) {
|
||||
if (!playlist_deck[i]->check_flag(PL_DISABLED))
|
||||
return playlist_deck[i];
|
||||
}
|
||||
return libsaria::library::get_playlist();
|
||||
}
|
||||
|
||||
static bool check_play()
|
||||
{
|
||||
switch(pause_type) {
|
||||
case PS_AFTER_N:
|
||||
if (pause_count == 0) {
|
||||
libsaria::deck::set_pause_type(PS_NONE, 0);
|
||||
return false;
|
||||
} else {
|
||||
pause_count--;
|
||||
libsaria::notify(PAUSE_COUNT, &pause_count);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void read_playlist(ifstream &stream)
|
||||
{
|
||||
libsaria::Playlist *plist = new libsaria::Playlist(0);
|
||||
|
@ -18,6 +48,15 @@ static void read_playlist(ifstream &stream)
|
|||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void deck::next()
|
||||
{
|
||||
Playlist *plist = get_active_playlist();
|
||||
Track *track = plist->next();
|
||||
if (track)
|
||||
track->load(check_play());
|
||||
}
|
||||
|
||||
void deck::prev()
|
||||
{
|
||||
Track *track = recent_playlist.next();
|
||||
|
@ -52,10 +91,33 @@ namespace libsaria
|
|||
return -1;
|
||||
}
|
||||
|
||||
unsigned int deck::size()
|
||||
{
|
||||
return playlist_deck.size();
|
||||
}
|
||||
|
||||
void deck::init()
|
||||
{
|
||||
app::mkdir("playlist");
|
||||
app::read_numdir("playlist", read_playlist);
|
||||
}
|
||||
|
||||
void deck::set_pause_type(AutoPauseType type, unsigned int count)
|
||||
{
|
||||
pause_type = type;
|
||||
pause_count = count;
|
||||
notify(PAUSE_TYPE, &pause_type);
|
||||
notify(PAUSE_COUNT, &count);
|
||||
}
|
||||
|
||||
AutoPauseType deck::get_pause_type()
|
||||
{
|
||||
return pause_type;
|
||||
}
|
||||
|
||||
unsigned short deck::get_pause_count()
|
||||
{
|
||||
return pause_count;
|
||||
}
|
||||
|
||||
}; /* Namespace: Libsaria */
|
||||
|
|
|
@ -11,11 +11,7 @@
|
|||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
static AutoPauseType pause_type;
|
||||
static unsigned short pause_count = 0;
|
||||
|
||||
static list<libsaria::Playlist *> playlist_deck;
|
||||
static libsaria::Playlist recent_plist(PL_STATIC | PL_NO_DRAIN);
|
||||
|
||||
static void renumber_playlists()
|
||||
{
|
||||
|
@ -26,36 +22,6 @@ static void renumber_playlists()
|
|||
(*it)->renumber(n++);
|
||||
}
|
||||
|
||||
static libsaria::Playlist *get_active_playlist()
|
||||
{
|
||||
list<libsaria::Playlist *>::iterator it;
|
||||
|
||||
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++) {
|
||||
if (!(*it)->check_flag(PL_DISABLED))
|
||||
return *it;
|
||||
}
|
||||
|
||||
return libsaria::library::get_playlist();
|
||||
}
|
||||
|
||||
static bool check_play()
|
||||
{
|
||||
switch(pause_type) {
|
||||
case PS_AFTER_N:
|
||||
if (pause_count == 0) {
|
||||
libsaria::deck::set_pause_type(PS_NONE, 0);
|
||||
return false;
|
||||
} else {
|
||||
pause_count--;
|
||||
libsaria::notify(PAUSE_COUNT, &pause_count);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
|
@ -76,17 +42,6 @@ namespace libsaria
|
|||
}
|
||||
}
|
||||
|
||||
void deck::next()
|
||||
{
|
||||
Playlist *plist = get_active_playlist();
|
||||
Track *track = plist->next();
|
||||
|
||||
if (track)
|
||||
track->load(check_play());
|
||||
|
||||
garbage_collect();
|
||||
}
|
||||
|
||||
Playlist *deck::new_playlist(list<Track *> &tracks, unsigned int flags, bool front)
|
||||
{
|
||||
Playlist *plist;
|
||||
|
@ -134,11 +89,6 @@ namespace libsaria
|
|||
return index;
|
||||
}
|
||||
|
||||
unsigned int deck::num_playlists()
|
||||
{
|
||||
return playlist_deck.size();
|
||||
}
|
||||
|
||||
void deck::track_removed(Track *track)
|
||||
{
|
||||
list<Playlist *>::iterator it;
|
||||
|
@ -146,22 +96,5 @@ namespace libsaria
|
|||
(*it)->remove_track(track);
|
||||
}
|
||||
|
||||
void deck::set_pause_type(AutoPauseType type, unsigned int count)
|
||||
{
|
||||
pause_type = type;
|
||||
pause_count = count;
|
||||
notify(PAUSE_TYPE, &pause_type);
|
||||
notify(PAUSE_COUNT, &count);
|
||||
}
|
||||
|
||||
AutoPauseType deck::get_pause_type()
|
||||
{
|
||||
return pause_type;
|
||||
}
|
||||
|
||||
unsigned short deck::get_pause_count()
|
||||
{
|
||||
return pause_count;
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -369,7 +369,7 @@ static void show_menu_widget(const string &name, unsigned int plist_num,
|
|||
|
||||
static void on_click(GtkTreeView *treeview, GdkEvent *event, gpointer data)
|
||||
{
|
||||
unsigned int deck_size = libsaria::deck::num_playlists();
|
||||
unsigned int deck_size = libsaria::deck::size();
|
||||
|
||||
if (event->button.button != 3)
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue