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

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-16 12:21:59 -05:00
parent 3f25369444
commit d18d3dd214
6 changed files with 50 additions and 86 deletions

View File

@ -217,9 +217,11 @@ struct track *audio_next()
return track;
}
void audio :: prev()
struct track *audio_prev()
{
__audio_load(history_prev(), audio_cur_state());
struct track *track = history_prev();
__audio_load(track, audio_cur_state());
return track;
}
void audio :: pause_after(bool enabled, unsigned int n)

View File

@ -175,6 +175,11 @@ void gst :: next()
gst :: play();
}
void gst :: prev()
{
audio_prev();
}
void gst :: toggle()
{
if (audio_cur_state() == GST_STATE_PLAYING)
@ -205,7 +210,7 @@ void gst :: init_pre()
o_next->signal_clicked().connect(sigc::ptr_fun(next));
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_prev->signal_clicked().connect(sigc::ptr_fun(gst :: prev));
o_seek->signal_change_value().connect(sigc::ptr_fun(on_seek));
o_stop->signal_clicked().connect(sigc::ptr_fun(gst :: stop));

View File

@ -39,7 +39,7 @@ static bool on_window_key_pressed(GdkEventKey *event)
else if (key == "n")
gst :: next();
else if (key == "N")
audio :: prev();
audio_prev();
else if (key == "p")
notebook->set_current_page(tempq_count() + 2);
else

View File

@ -40,8 +40,6 @@ public:
namespace audio
{
void prev(); /**< Call the deck :: previous() function and load the result. */
/**
* Configure the automatic pausing feature.
*
@ -112,5 +110,8 @@ gint64 audio_duration();
/* Called to load the next track. */
struct track *audio_next();
/* Called to load the previous track. */
struct track *audio_prev();
GstElement *audio_get_player();
#endif /* OCARINA_CORE_AUDIO_H */

View File

@ -47,6 +47,7 @@ namespace gst
void pause();
void stop();
void next();
void prev();
void toggle();
void init_pre();
void init();

View File

@ -65,6 +65,7 @@ static void test_init()
test_equal(audio_load(NULL), false);
test_equal(audio_next(), NULL);
test_equal(audio_prev(), NULL);
test_equal(audio_play(), false);
test_equal(audio_pause(), false);
test_equal(audio_stop(), false);
@ -157,6 +158,38 @@ static void test_next()
} test_loop_passed();
}
static void test_prev()
{
struct queue *history_q = history_get_queue();
struct track *track = queue_at(history_q, 0);
test_equal(audio_prev()->tr_track, 2);
test_equal(queue_at(history_q, 0), track);
test_equal(audio_cur_state(), GST_STATE_PLAYING);
test_equal(audio_cur_track()->tr_track, 2);
test_equal(audio_prev()->tr_track, 1);
test_equal(queue_at(history_q, 0), track);
test_equal(audio_cur_state(), GST_STATE_PLAYING);
test_equal(audio_cur_track()->tr_track, 1);
test_equal(audio_pause(), true);
test_equal(audio_prev()->tr_dbe.dbe_index, 0);
test_equal(queue_at(history_q, 0), track);
test_equal(audio_cur_state(), GST_STATE_PAUSED);
test_equal(audio_cur_track()->tr_dbe.dbe_index, 0);
test_equal(audio_prev()->tr_dbe.dbe_index, 1);
test_equal(queue_at(history_q, 0), track);
test_equal(audio_cur_state(), GST_STATE_PAUSED);
test_equal(audio_cur_track()->tr_dbe.dbe_index, 1);
test_equal(audio_prev()->tr_dbe.dbe_index, 2);
test_equal(queue_at(history_q, 0), track);
test_equal(audio_cur_state(), GST_STATE_PAUSED);
test_equal(audio_cur_track()->tr_dbe.dbe_index, 2);
}
static void test_deinit()
{
core :: deinit();
@ -166,88 +199,11 @@ static void test_deinit()
}
void test_pre_init()
{
TestDriver *driver = (TestDriver *)audio :: get_driver();
test_equal(audio_cur_track(), TRACK_NULL);
audio_play();
test_equal(driver->playing, false);
driver->playing = true;
audio_pause();
test_equal(driver->playing, true);
audio_stop();
test_equal(driver->playing, true);
driver->playing = false;
audio_seek(4242);
test_equal(audio_position(), (long)0);
test_equal(audio_duration(), (long)0);
audio_next();
test_equal(audio_cur_track(), TRACK_NULL);
audio :: prev();
test_equal(audio_cur_track(), TRACK_NULL);
}
void test_init2()
{
struct track *track;
test_cp_data_dir();
audio_init(NULL, NULL, &test_audio_ops);
track = audio_cur_track();
test_equal(track, TRACK_NULL);
core :: init(NULL, NULL, &test_init_data);
track = audio_cur_track();
test_not_equal(track, TRACK_NULL);
}
void test_track_controls()
{
struct track *track = NULL;
TestDriver *driver = (TestDriver *)audio :: get_driver();
queue_unset_flag(collection_get_queue(), Q_RANDOM);
driver->playing = audio_pause();
audio_next();
test_not_equal(audio_cur_track()->tr_dbe.dbe_index, (unsigned)2);
test_equal(driver->is_playing(), false);
audio_play();
audio_next();
test_equal(driver->is_playing(), true);
audio_load(track);
test_not_equal(audio_cur_track(), track);
track = track_get(0);
audio_seek(4242);
audio_load(track);
test_equal(driver->is_playing(), true);
test_equal(audio_position(), (long)0);
audio_seek(4242);
audio_load(track);
test_equal(driver->is_playing(), true);
test_equal(audio_position(), (long)4242);
track = audio_cur_track();
driver->eos();
test_not_equal(audio_cur_track(), track);
}
void test_autopause()
{
TestDriver *driver = (TestDriver *)audio :: get_driver();
core :: init(NULL, NULL, &test_init_data);
audio_play();
test_equal(audio :: pause_enabled(), false);
test_equal(audio :: pause_count(), (unsigned)0);
@ -281,8 +237,7 @@ DECLARE_UNIT_TESTS(
UNIT_TEST("Audio Initialization", test_init),
UNIT_TEST("Audio Playback", test_playback),
UNIT_TEST("Audio Next", test_next),
UNIT_TEST("Audio Previous", test_prev),
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 Automatic Pausing", test_autopause),
);