From d1d722a16395d8ef9a8074692f525f32cd2bf86a Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 16 Dec 2015 08:16:46 -0500 Subject: [PATCH] core/audio: Move audio_stop() out of the audio namespace Signed-off-by: Anna Schumaker --- core/audio.cpp | 12 ++++++------ gui/gst.cpp | 7 ++++++- include/core/audio.h | 8 +++----- include/gui/ocarina.h | 1 + tests/core/audio.cpp | 36 +++++++++++------------------------- 5 files changed, 27 insertions(+), 37 deletions(-) diff --git a/core/audio.cpp b/core/audio.cpp index fcc8075c..9776bbdf 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -162,6 +162,12 @@ bool audio_pause() return __audio_change_state(GST_STATE_PAUSED); } +bool audio_stop() +{ + audio_pause(); + return audio_seek(0); +} + bool audio_seek(gint64 offset) { if (!audio_track) @@ -172,12 +178,6 @@ bool audio_seek(gint64 offset) offset); } -void audio :: stop() -{ - audio_pause(); - audio_seek(0); -} - gint64 audio_position() { gint64 position; diff --git a/gui/gst.cpp b/gui/gst.cpp index 6aa42e53..da6b39df 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -178,6 +178,11 @@ void gst :: pause() } } +void gst :: stop() { + if (audio_stop()) + on_pause(); +} + void gst :: next() { audio :: next(); @@ -218,7 +223,7 @@ void gst :: init_pre() 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)); - o_stop->signal_clicked().connect(sigc::ptr_fun(audio :: stop)); + o_stop->signal_clicked().connect(sigc::ptr_fun(gst :: stop)); o_count->signal_changed().connect(sigc::ptr_fun(on_pause_count)); o_enabled->signal_toggled().connect(sigc::ptr_fun(on_pause_enabled)); diff --git a/include/core/audio.h b/include/core/audio.h index 30928cc4..afc6c26b 100644 --- a/include/core/audio.h +++ b/include/core/audio.h @@ -52,11 +52,6 @@ public: namespace audio { - /** - * Stop playback and seek to the beginning of the track. - */ - void stop(); - void next(); /**< Find and load the next track that should be played. */ void prev(); /**< Call the deck :: previous() function and load the result. */ @@ -112,6 +107,9 @@ bool audio_play(); /* Called to pause playback. */ bool audio_pause(); +/* Called to stop playback. */ +bool audio_stop(); + /* Called to seek playback to a specific offset, in nanoseconds. */ bool audio_seek(gint64); diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h index 299bbe8e..271c35b7 100644 --- a/include/gui/ocarina.h +++ b/include/gui/ocarina.h @@ -45,6 +45,7 @@ namespace gst { void play(); void pause(); + void stop(); void next(); void toggle(); void init_pre(); diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index 217236a6..92699019 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -68,6 +68,7 @@ static void test_init() test_equal(audio_load(NULL), false); test_equal(audio_play(), false); test_equal(audio_pause(), false); + test_equal(audio_stop(), false); test_equal(audio_seek(7), false); test_equal(audio_position(), 0); test_equal(audio_duration(), 0); @@ -107,7 +108,15 @@ static void test_playback() test_equal(test_audio_seek(5 * GST_SECOND), true); test_equal(audio_position(), 5 * GST_SECOND); - test_equal(test_audio_seek(0), true); + test_equal(audio_stop(), true); + test_equal(audio_position(), 0); + + test_equal(test_audio_seek(42 * GST_SECOND), true); + test_equal(audio_position(), 42 * GST_SECOND); + + test_equal(audio_play(), true); + test_equal(audio_stop(), true); + test_equal(audio_pause(), false); test_equal(audio_position(), 0); /* Check duration again now that track is fully loaded. */ @@ -135,7 +144,7 @@ void test_pre_init() driver->playing = true; audio_pause(); test_equal(driver->playing, true); - audio :: stop(); + audio_stop(); test_equal(driver->playing, true); driver->playing = false; @@ -166,28 +175,6 @@ void test_init2() test_not_equal(track, TRACK_NULL); } -void test_playback_controls() -{ - TestDriver *driver = (TestDriver *)audio :: get_driver(); - - driver->playing = audio_play(); - test_equal(driver->playing, true); - - driver->playing = audio_pause(); - test_equal(driver->playing, false); - - audio_seek(4242); - test_equal(audio_position(), (long)4242); - - audio_play(); - audio :: stop(); - test_equal(driver->playing, false); - - audio_seek(4242); - test_equal(audio_position(), (long)4242); - test_equal(audio_duration(), (long)424242); -} - void test_track_controls() { struct track *track = NULL; @@ -262,6 +249,5 @@ DECLARE_UNIT_TESTS( UNIT_TEST("Audio Deinitialization", test_deinit), UNIT_TEST("Test Audio Pre-Init", test_pre_init), UNIT_TEST("Test Audio Init 2", test_init2), - UNIT_TEST("Test Audio Playback Controls", test_playback_controls), UNIT_TEST("Test Audio Automatic Pausing", test_autopause), );