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

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-15 14:17:17 -05:00
parent e5c3d8f02e
commit 16c4c23a42
6 changed files with 45 additions and 29 deletions

View File

@ -28,6 +28,21 @@ static void __audio_save()
file_close(&audio_file);
}
static GstState __audio_cur_state()
{
GstState cur;
gst_element_get_state(audio_player, &cur, NULL, GST_CLOCK_TIME_NONE);
return cur;
}
static bool __audio_change_state(GstState state)
{
GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
if (__audio_cur_state() != state)
ret = gst_element_set_state(audio_player, state);
return ret != GST_STATE_CHANGE_FAILURE;
}
static bool __audio_load(struct track *track, GstState state)
{
gchar *path, *uri;
@ -41,7 +56,7 @@ static bool __audio_load(struct track *track, GstState state)
gst_element_set_state(audio_player, GST_STATE_NULL);
g_object_set(G_OBJECT(audio_player), "uri", uri, NULL);
gst_element_set_state(audio_player, state);
__audio_change_state(state);
audio_ops->on_load(track, state);
__audio_save();
@ -133,10 +148,11 @@ bool audio_load(struct track *track)
return false;
}
void audio :: play()
bool audio_play()
{
if (audio_track)
cur_driver->play();
if (!audio_track)
return false;
return __audio_change_state(GST_STATE_PLAYING);
}
void audio :: pause()

View File

@ -76,14 +76,6 @@ static void on_load(struct track *track, GstState state)
class GSTDriver : public AudioDriver
{
public:
void play()
{
if (gst_change_state(GST_STATE_PLAYING)) {
o_play->hide();
o_pause->show();
}
}
void pause()
{
if (gst_change_state(GST_STATE_PAUSED)) {
@ -166,7 +158,7 @@ static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data)
if (parse_gst_error(message) < 0)
break;
audio :: next();
audio :: play();
gst :: play();
break;
case GST_MESSAGE_EOS:
gst_driver->eos();
@ -210,10 +202,18 @@ static bool on_timeout()
void gst :: play()
{
if (audio_play()) {
o_play->hide();
o_pause->show();
}
}
void gst :: next()
{
audio :: next();
audio :: play();
gst :: play();
}
void gst :: toggle()
@ -221,7 +221,7 @@ void gst :: toggle()
if (gst_driver->is_playing())
audio :: pause();
else
audio :: play();
gst :: play();
}
void gst :: init_pre()
@ -247,7 +247,7 @@ void gst :: init_pre()
o_next->signal_clicked().connect(sigc::ptr_fun(next));
o_pause->signal_clicked().connect(sigc::ptr_fun(audio :: pause));
o_play->signal_clicked().connect(sigc::ptr_fun(audio :: play));
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));

View File

@ -9,6 +9,7 @@ extern "C" {
#include <core/string.h>
}
#include <gui/queue/model.h>
#include <gui/ocarina.h>
#include <stdlib.h>
@ -58,7 +59,7 @@ void QueueModel::on_path_selected(const Gtk::TreePath &path)
{
audio_load(track_get(path_to_id(path)));
queue_selected(_queue, path[0]);
audio :: play();
gst :: play();
}
unsigned int QueueModel :: iter_to_id(const Gtk::TreeIter &iter) const

View File

@ -31,11 +31,6 @@ public:
virtual ~AudioDriver(); /**< AudioDriver destructor. */
/**
* Called to begin playback on the currently loaded track.
*/
virtual void play() = 0;
/**
* Called to pause playback on the currently loaded track.
*/
@ -83,7 +78,6 @@ public:
namespace audio
{
void play(); /**< Begin playback. */
void pause(); /**< Pause playback. */
/**
@ -157,5 +151,8 @@ void audio_deinit();
/* Called to load a track for playback. */
bool audio_load(struct track *);
/* Called to begin playback. */
bool audio_play();
GstElement *audio_get_player();
#endif /* OCARINA_CORE_AUDIO_H */

View File

@ -43,6 +43,7 @@ void post_init_queue_tabs();
/* gst.cpp */
namespace gst
{
void play();
void next();
void toggle();
void init_pre();

View File

@ -25,7 +25,6 @@ public:
TestDriver() : playing(false), cur_pos(0), cur_duration(0) {}
~TestDriver() {};
void play() { playing = true; }
void pause() { playing = false; }
bool is_playing() { return playing; }
@ -62,7 +61,9 @@ 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 :: current_track(), NULL);
test_equal(load_count, 0);
collection_add("tests/Music/Hyrule Symphony");
while (idle_run_task()) {};
@ -103,7 +104,7 @@ void test_pre_init()
test_equal(audio :: current_track(), TRACK_NULL);
audio :: play();
audio_play();
test_equal(driver->playing, false);
driver->playing = true;
@ -150,7 +151,7 @@ void test_playback_controls()
{
TestDriver *driver = (TestDriver *)audio :: get_driver();
audio :: play();
driver->playing = audio_play();
test_equal(driver->playing, true);
audio :: pause();
@ -160,7 +161,7 @@ void test_playback_controls()
test_equal(driver->cur_pos, (long)4242);
test_equal(audio :: position(), (long)4242);
audio :: play();
audio_play();
audio :: stop();
test_equal(driver->playing, false);
test_equal(driver->cur_pos, (long)0);
@ -183,7 +184,7 @@ void test_track_controls()
test_not_equal(audio :: current_track()->tr_dbe.dbe_index, (unsigned)2);
test_equal(driver->is_playing(), false);
audio :: play();
audio_play();
audio :: next();
test_equal(driver->is_playing(), true);
@ -210,7 +211,7 @@ void test_autopause()
{
TestDriver *driver = (TestDriver *)audio :: get_driver();
audio :: play();
audio_play();
test_equal(audio :: pause_enabled(), false);
test_equal(audio :: pause_count(), (unsigned)0);