core/audio: Move audio_next() out of the audio namespace
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
7765c2bf57
commit
3f25369444
|
@ -207,13 +207,14 @@ int64_t audio_duration()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio :: next()
|
struct track *audio_next()
|
||||||
{
|
{
|
||||||
struct track *track = tempq_next();
|
struct track *track = tempq_next();
|
||||||
if (!track)
|
if (!track)
|
||||||
track = queue_next(collection_get_queue());
|
track = queue_next(collection_get_queue());
|
||||||
if (__audio_load(track, audio_cur_state()))
|
if (__audio_load(track, audio_cur_state()))
|
||||||
history_add(audio_track);
|
history_add(audio_track);
|
||||||
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio :: prev()
|
void audio :: prev()
|
||||||
|
|
|
@ -104,7 +104,7 @@ static gboolean on_gst_message(GstBus *bus, GstMessage *message, gpointer data)
|
||||||
case GST_MESSAGE_ERROR:
|
case GST_MESSAGE_ERROR:
|
||||||
if (parse_gst_error(message) < 0)
|
if (parse_gst_error(message) < 0)
|
||||||
break;
|
break;
|
||||||
audio :: next();
|
audio_next();
|
||||||
gst :: play();
|
gst :: play();
|
||||||
break;
|
break;
|
||||||
case GST_MESSAGE_EOS:
|
case GST_MESSAGE_EOS:
|
||||||
|
@ -171,7 +171,7 @@ void gst :: stop() {
|
||||||
|
|
||||||
void gst :: next()
|
void gst :: next()
|
||||||
{
|
{
|
||||||
audio :: next();
|
audio_next();
|
||||||
gst :: play();
|
gst :: play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ static void on_ban()
|
||||||
struct track *track = audio_cur_track();
|
struct track *track = audio_cur_track();
|
||||||
if (o_ban->get_active()) {
|
if (o_ban->get_active()) {
|
||||||
if (collection_ban(track))
|
if (collection_ban(track))
|
||||||
audio :: next();
|
audio_next();
|
||||||
} else
|
} else
|
||||||
collection_unban(track);
|
collection_unban(track);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ public:
|
||||||
namespace audio
|
namespace audio
|
||||||
{
|
{
|
||||||
|
|
||||||
void next(); /**< Find and load the next track that should be played. */
|
|
||||||
void prev(); /**< Call the deck :: previous() function and load the result. */
|
void prev(); /**< Call the deck :: previous() function and load the result. */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,5 +108,9 @@ gint64 audio_position();
|
||||||
/* Called to find the duration of the current track. */
|
/* Called to find the duration of the current track. */
|
||||||
gint64 audio_duration();
|
gint64 audio_duration();
|
||||||
|
|
||||||
|
|
||||||
|
/* Called to load the next track. */
|
||||||
|
struct track *audio_next();
|
||||||
|
|
||||||
GstElement *audio_get_player();
|
GstElement *audio_get_player();
|
||||||
#endif /* OCARINA_CORE_AUDIO_H */
|
#endif /* OCARINA_CORE_AUDIO_H */
|
||||||
|
|
|
@ -6,6 +6,7 @@ extern "C" {
|
||||||
#include <core/collection.h>
|
#include <core/collection.h>
|
||||||
#include <core/history.h>
|
#include <core/history.h>
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
|
#include <core/tempq.h>
|
||||||
}
|
}
|
||||||
#include <core/core.h>
|
#include <core/core.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
@ -58,10 +59,12 @@ static void test_init()
|
||||||
test_equal(audio_get_player(), NULL);
|
test_equal(audio_get_player(), NULL);
|
||||||
test_equal(audio_cur_track(), NULL);
|
test_equal(audio_cur_track(), NULL);
|
||||||
test_equal(audio_cur_state(), GST_STATE_NULL);
|
test_equal(audio_cur_state(), GST_STATE_NULL);
|
||||||
|
test_equal(audio_next(), NULL);
|
||||||
|
|
||||||
core :: init(NULL, NULL, &test_init_data);
|
core :: init(NULL, NULL, &test_init_data);
|
||||||
|
|
||||||
test_equal(audio_load(NULL), false);
|
test_equal(audio_load(NULL), false);
|
||||||
|
test_equal(audio_next(), NULL);
|
||||||
test_equal(audio_play(), false);
|
test_equal(audio_play(), false);
|
||||||
test_equal(audio_pause(), false);
|
test_equal(audio_pause(), false);
|
||||||
test_equal(audio_stop(), false);
|
test_equal(audio_stop(), false);
|
||||||
|
@ -124,6 +127,36 @@ static void test_playback()
|
||||||
test_equal(audio_duration(), track_get(0)->tr_length * GST_SECOND);
|
test_equal(audio_duration(), track_get(0)->tr_length * GST_SECOND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_next()
|
||||||
|
{
|
||||||
|
struct queue *history_q = history_get_queue();
|
||||||
|
struct queue *temp_q = tempq_alloc(NULL, 0);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* First, let's test getting tracks from a temporary queue. */
|
||||||
|
queue_add(temp_q, track_get(2));
|
||||||
|
queue_add(temp_q, track_get(1));
|
||||||
|
queue_add(temp_q, track_get(0));
|
||||||
|
|
||||||
|
for (i = 2; i >= 0; i--) {
|
||||||
|
test_loop_equal(queue_size(temp_q), i + 1, i);
|
||||||
|
test_loop_equal(audio_next()->tr_dbe.dbe_index, i, i);
|
||||||
|
test_loop_equal(queue_at(history_q, 0), track_get(i), i);
|
||||||
|
test_loop_equal(audio_cur_state(), GST_STATE_PAUSED, i);
|
||||||
|
test_loop_equal(audio_cur_track(), track_get(i), i);
|
||||||
|
} test_loop_passed();
|
||||||
|
test_equal(tempq_get(0), NULL);
|
||||||
|
|
||||||
|
test_equal(audio_play(), true);
|
||||||
|
/* Tracks should now be picked from the collection. */
|
||||||
|
for (i = 1; i <= 3; i++) {
|
||||||
|
test_loop_equal(audio_next()->tr_track, i, i);
|
||||||
|
test_loop_equal(queue_at(history_q, 0)->tr_track, i, i);
|
||||||
|
test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i);
|
||||||
|
test_loop_equal(audio_cur_track()->tr_track, i, i);
|
||||||
|
} test_loop_passed();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_deinit()
|
static void test_deinit()
|
||||||
{
|
{
|
||||||
core :: deinit();
|
core :: deinit();
|
||||||
|
@ -154,7 +187,7 @@ void test_pre_init()
|
||||||
|
|
||||||
test_equal(audio_duration(), (long)0);
|
test_equal(audio_duration(), (long)0);
|
||||||
|
|
||||||
audio :: next();
|
audio_next();
|
||||||
test_equal(audio_cur_track(), TRACK_NULL);
|
test_equal(audio_cur_track(), TRACK_NULL);
|
||||||
|
|
||||||
audio :: prev();
|
audio :: prev();
|
||||||
|
@ -184,12 +217,12 @@ void test_track_controls()
|
||||||
queue_unset_flag(collection_get_queue(), Q_RANDOM);
|
queue_unset_flag(collection_get_queue(), Q_RANDOM);
|
||||||
|
|
||||||
driver->playing = audio_pause();
|
driver->playing = audio_pause();
|
||||||
audio :: next();
|
audio_next();
|
||||||
test_not_equal(audio_cur_track()->tr_dbe.dbe_index, (unsigned)2);
|
test_not_equal(audio_cur_track()->tr_dbe.dbe_index, (unsigned)2);
|
||||||
test_equal(driver->is_playing(), false);
|
test_equal(driver->is_playing(), false);
|
||||||
|
|
||||||
audio_play();
|
audio_play();
|
||||||
audio :: next();
|
audio_next();
|
||||||
test_equal(driver->is_playing(), true);
|
test_equal(driver->is_playing(), true);
|
||||||
|
|
||||||
audio_load(track);
|
audio_load(track);
|
||||||
|
@ -247,6 +280,7 @@ void test_autopause()
|
||||||
DECLARE_UNIT_TESTS(
|
DECLARE_UNIT_TESTS(
|
||||||
UNIT_TEST("Audio Initialization", test_init),
|
UNIT_TEST("Audio Initialization", test_init),
|
||||||
UNIT_TEST("Audio Playback", test_playback),
|
UNIT_TEST("Audio Playback", test_playback),
|
||||||
|
UNIT_TEST("Audio Next", test_next),
|
||||||
UNIT_TEST("Audio Deinitialization", test_deinit),
|
UNIT_TEST("Audio Deinitialization", test_deinit),
|
||||||
UNIT_TEST("Test Audio Pre-Init", test_pre_init),
|
UNIT_TEST("Test Audio Pre-Init", test_pre_init),
|
||||||
UNIT_TEST("Test Audio Init 2", test_init2),
|
UNIT_TEST("Test Audio Init 2", test_init2),
|
||||||
|
|
Loading…
Reference in New Issue