From 9097bd0ffc2cac3f7dbbfb422552f6978e82adbd Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 15 Dec 2015 14:34:13 -0500 Subject: [PATCH] core/audio: Move audio_pause() out of the audio namespace Signed-off-by: Anna Schumaker --- core/audio.cpp | 9 +++++---- gui/gst.cpp | 40 ++++++++++++++++++---------------------- include/core/audio.h | 10 +++------- include/gui/ocarina.h | 1 + tests/core/audio.cpp | 17 +++++++++++------ 5 files changed, 38 insertions(+), 39 deletions(-) diff --git a/core/audio.cpp b/core/audio.cpp index 561a6b25..e7f14de4 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -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); } diff --git a/gui/gst.cpp b/gui/gst.cpp index 629f7944..01ec7ca1 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -34,18 +34,6 @@ static Gtk::Label *o_title; static Glib::RefPtr 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) + ""); } +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("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)); diff --git a/include/core/audio.h b/include/core/audio.h index fb4008ac..1887ec4e 100644 --- a/include/core/audio.h +++ b/include/core/audio.h @@ -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 */ diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h index 0f6306c7..299bbe8e 100644 --- a/include/gui/ocarina.h +++ b/include/gui/ocarina.h @@ -44,6 +44,7 @@ void post_init_queue_tabs(); namespace gst { void play(); + void pause(); void next(); void toggle(); void init_pre(); diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index dd1c9b39..afeb5b42 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -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);