core/audio: Move audio_pause() out of the audio namespace

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-15 14:34:13 -05:00
parent 16c4c23a42
commit 9097bd0ffc
5 changed files with 38 additions and 39 deletions

View File

@ -155,10 +155,11 @@ bool audio_play()
return __audio_change_state(GST_STATE_PLAYING);
}
void audio :: pause()
bool audio_pause()
{
if (audio_track)
cur_driver->pause();
if (!audio_track)
return false;
return __audio_change_state(GST_STATE_PAUSED);
}
void audio :: seek_to(int64_t pos)
@ -169,7 +170,7 @@ void audio :: seek_to(int64_t pos)
void audio :: stop()
{
pause();
audio_pause();
seek_to(0);
}

View File

@ -34,18 +34,6 @@ static Gtk::Label *o_title;
static Glib::RefPtr<Gtk::Adjustment> o_progress;
static bool gst_change_state(GstState state)
{
GstStateChangeReturn ret = gst_element_set_state(audio_get_player(), state);
switch (ret) {
case GST_STATE_CHANGE_SUCCESS:
case GST_STATE_CHANGE_ASYNC:
return true;
default:
return false;
}
}
static void set_markup(Gtk::Label *label, const std::string &size,
const std::string &text)
{
@ -53,6 +41,12 @@ static void set_markup(Gtk::Label *label, const std::string &size,
Glib::Markup::escape_text(text) + "</span>");
}
static void on_pause()
{
o_play->show();
o_pause->hide();
}
static void on_load(struct track *track, GstState state)
{
gchar *str = g_strdup_printf("From: %s", track->tr_album->al_name);
@ -70,20 +64,15 @@ static void on_load(struct track *track, GstState state)
g_free(str);
plist :: track_loaded(track);
if (state != GST_STATE_PLAYING)
on_pause();
}
class GSTDriver : public AudioDriver
{
public:
void pause()
{
if (gst_change_state(GST_STATE_PAUSED)) {
o_play->show();
o_pause->hide();
}
}
bool is_playing()
{
GstState state;
@ -210,6 +199,13 @@ void gst :: play()
}
}
void gst :: pause()
{
if (audio_pause()) {
on_pause();
}
}
void gst :: next()
{
audio :: next();
@ -219,7 +215,7 @@ void gst :: next()
void gst :: toggle()
{
if (gst_driver->is_playing())
audio :: pause();
gst :: pause();
else
gst :: play();
}
@ -246,7 +242,7 @@ void gst :: init_pre()
o_progress = gui :: get_object<Gtk::Adjustment>("o_progress");
o_next->signal_clicked().connect(sigc::ptr_fun(next));
o_pause->signal_clicked().connect(sigc::ptr_fun(audio :: pause));
o_pause->signal_clicked().connect(sigc::ptr_fun(gst :: pause));
o_play->signal_clicked().connect(sigc::ptr_fun(gst :: play));
o_prev->signal_clicked().connect(sigc::ptr_fun(audio :: prev));
o_seek->signal_change_value().connect(sigc::ptr_fun(on_seek));

View File

@ -31,11 +31,6 @@ public:
virtual ~AudioDriver(); /**< AudioDriver destructor. */
/**
* Called to pause playback on the currently loaded track.
*/
virtual void pause() = 0;
/**
* Called to check if the audio library is currently playing a track.
*
@ -78,8 +73,6 @@ public:
namespace audio
{
void pause(); /**< Pause playback. */
/**
* Seek to a specific point in the track.
*
@ -154,5 +147,8 @@ bool audio_load(struct track *);
/* Called to begin playback. */
bool audio_play();
/* Called to pause playback. */
bool audio_pause();
GstElement *audio_get_player();
#endif /* OCARINA_CORE_AUDIO_H */

View File

@ -44,6 +44,7 @@ void post_init_queue_tabs();
namespace gst
{
void play();
void pause();
void next();
void toggle();
void init_pre();

View File

@ -25,8 +25,6 @@ public:
TestDriver() : playing(false), cur_pos(0), cur_duration(0) {}
~TestDriver() {};
void pause() { playing = false; }
bool is_playing() { return playing; }
void seek_to(int64_t offset) { cur_pos = offset; }
@ -61,7 +59,8 @@ static void test_init()
core :: init(NULL, NULL, &test_init_data);
test_equal(audio_load(NULL), false);
test_equal(audio_play(), false);
test_equal(audio_play(), false);
test_equal(audio_pause(), false);
test_equal(audio :: current_track(), NULL);
test_equal(load_count, 0);
@ -87,6 +86,12 @@ static void test_playback()
test_equal(audio_load(track_get(0)), false);
test_equal(load_count, 1);
test_equal(queue_size(history_get_queue()), 1);
test_equal(audio_play(), true);
test_equal(audio_play(), false);
test_equal(audio_pause(), true);
test_equal(audio_pause(), false);
}
static void test_deinit()
@ -108,7 +113,7 @@ void test_pre_init()
test_equal(driver->playing, false);
driver->playing = true;
audio :: pause();
audio_pause();
test_equal(driver->playing, true);
audio :: stop();
test_equal(driver->playing, true);
@ -154,7 +159,7 @@ void test_playback_controls()
driver->playing = audio_play();
test_equal(driver->playing, true);
audio :: pause();
driver->playing = audio_pause();
test_equal(driver->playing, false);
audio :: seek_to(4242);
@ -179,7 +184,7 @@ void test_track_controls()
TestDriver *driver = (TestDriver *)audio :: get_driver();
queue_unset_flag(collection_get_queue(), Q_RANDOM);
audio :: pause();
driver->playing = audio_pause();
audio :: next();
test_not_equal(audio :: current_track()->tr_dbe.dbe_index, (unsigned)2);
test_equal(driver->is_playing(), false);