core/audio: Convert file to C

I also convert core/core.c so the audio test can be converted at the
same time.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-17 10:32:01 -05:00
parent a59a71eb38
commit 2586348921
14 changed files with 61 additions and 74 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
res = Glob("*.cpp") + Glob("*.c")
res = Glob("*.c")
res += SConscript("tags/Sconscript")
res += SConscript("containers/Sconscript")
Return("res")

View File

@ -1,14 +1,10 @@
/**
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/audio.h>
extern "C" {
#include <core/collection.h>
#include <core/history.h>
#include <core/tempq.h>
#include <core/string.h>
}
static struct file audio_file;
static struct track *audio_track = NULL;
@ -17,6 +13,7 @@ static struct audio_ops *audio_ops = NULL;
static int audio_pause_count = -1;
static guint audio_bus = 0;
static void __audio_save()
{
file_open(&audio_file, OPEN_WRITE);

View File

@ -1,16 +1,14 @@
/**
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/audio.h>
#include <core/core.h>
extern "C" {
#include <core/collection.h>
#include <core/filter.h>
#include <core/history.h>
#include <core/playlist.h>
#include <core/tags/tags.h>
#include <core/tempq.h>
}
void core_init(int *argc, char ***argv, struct core_init_data *init)

View File

@ -2,5 +2,5 @@
Import("env")
env.UsePackage("taglib_c")
res = Glob("*.cpp") + Glob("*.c")
res = Glob("*.c")
Return("res")

View File

@ -5,9 +5,8 @@
* through argv. Use the command `gst-inspect-1.0 --help-gst` to find
* what options are supported.
*/
#include <core/audio.h>
extern "C" {
#include <core/collection.h>
#include <core/audio.h>
#include <core/string.h>
}
#include <gui/ocarina.h>

View File

@ -1,8 +1,8 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/core.h>
extern "C" {
#include <core/core.h>
#include <core/idle.h>
}
#include <gui/ocarina.h>

View File

@ -1,8 +1,8 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/audio.h>
extern "C" {
#include <core/audio.h>
#include <core/collection.h>
#include <core/playlist.h>
}

View File

@ -4,8 +4,8 @@
* See the example at:
* https://git.gnome.org/browse/gtkmm-documentation/tree/examples/others/treemodelcustom
*/
#include <core/audio.h>
extern "C" {
#include <core/audio.h>
#include <core/string.h>
}
#include <gui/queue/model.h>

View File

@ -1,8 +1,8 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/audio.h>
extern "C" {
#include <core/audio.h>
#include <core/tempq.h>
#include <core/version.h>
}

View File

@ -1,15 +1,10 @@
/**
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#ifndef OCARINA_CORE_AUDIO_H
#define OCARINA_CORE_AUDIO_H
extern "C" {
#include <core/tags/track.h>
}
#include <gst/gst.h>
#include <string>
#include <stdint.h>
struct audio_ops {

View File

@ -1,9 +1,8 @@
/**
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#ifndef OCARINA_CORE_CORE_H
#define OCARINA_CORE_CORE_H
#include <core/queue.h>

View File

@ -15,6 +15,7 @@
#ifndef __cplusplus
static inline gchar *stos(const char *s) { return g_strdup(s); }
static inline gchar *utos(unsigned int u) { return g_strdup_printf("%u", u); }
static inline gchar *ltos(long int l) { return g_strdup_printf("%lu", l); }
static inline gchar *itos(int i) { return g_strdup_printf("%i", i); }
static inline gchar *ftos(float f) { return g_strdup_printf("%f", f); }
static inline gchar *btos(bool b) { return g_strdup(b ? "true" : "false"); }
@ -26,6 +27,7 @@ static inline gchar *ptos(void *p) { return g_strdup_printf("%p", p); }
const char *: stos, \
bool: btos, \
unsigned int: utos, \
long int: ltos, \
int: itos, \
float:ftos, \
void *:ptos \

View File

@ -8,11 +8,7 @@ core_objs = []
def CoreTest(name):
global core_objs
test = name.split("/")[-1]
source = "%s.c" % test
if os.path.exists("%s.cpp" % test):
source = "%s.cpp" % test
source = "%s.c" % name.split("/")[-1]
test = os.path.abspath(source)
core = os.path.sep.join([x for x in test.split("/") if x != "tests"])
if os.path.exists(core):
@ -43,7 +39,7 @@ res += [ CoreTest("collection") ]
res += [ CoreTest("history") ]
res += [ CoreTest("tempq") ]
core_objs += [ env.Object("../../core/core.cpp") ]
core_objs += [ env.Object("../../core/core.c") ]
res += [ CoreTest("audio") ]
Return("res")

View File

@ -2,14 +2,12 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/audio.h>
extern "C" {
#include <core/collection.h>
#include <core/history.h>
#include <core/idle.h>
#include <core/tempq.h>
}
#include <core/core.h>
#include "test.h"
#include <tests/test.h>
static unsigned int load_count = 0;
static int pause_count = 0;
@ -63,72 +61,72 @@ static struct core_init_data test_init_data = {
static void test_init()
{
test_equal(audio_get_player(), NULL);
test_equal(audio_cur_track(), NULL);
test_equal((void *)audio_get_player(), NULL);
test_equal((void *)audio_cur_track(), NULL);
test_equal(audio_cur_state(), GST_STATE_NULL);
test_equal(audio_next(), NULL);
test_equal((void *)audio_next(), NULL);
core_init(NULL, NULL, &test_init_data);
test_equal(audio_load(NULL), false);
test_equal(audio_next(), NULL);
test_equal(audio_prev(), NULL);
test_equal(audio_load(NULL), (bool)false);
test_equal((void *)audio_next(), NULL);
test_equal((void *)audio_prev(), NULL);
test_send_error();
test_equal(audio_play(), false);
test_equal(audio_pause(), false);
test_equal(audio_stop(), false);
test_equal(audio_seek(7), false);
test_equal(audio_play(), (bool)false);
test_equal(audio_pause(), (bool)false);
test_equal(audio_stop(), (bool)false);
test_equal(audio_seek(7), (bool)false);
test_equal(audio_position(), 0);
test_equal(audio_duration(), 0);
test_equal(audio_cur_track(), NULL);
test_equal((void *)audio_cur_track(), NULL);
test_equal(audio_cur_state(), GST_STATE_NULL);
test_equal(load_count, 0);
collection_add("tests/Music/Hyrule Symphony");
while (idle_run_task()) {};
test_equal(audio_cur_track(), NULL);
test_not_equal(audio_get_player(), NULL);
test_equal((void *)audio_cur_track(), NULL);
test_not_equal((void *)audio_get_player(), NULL);
}
static void test_playback()
{
test_equal(audio_load(track_get(0)), true);
test_equal(audio_load(track_get(0)), (bool)true);
test_equal(load_count, 1);
test_equal(audio_cur_track(), track_get(0));
test_equal((void *)audio_cur_track(), (void *)track_get(0));
test_equal(audio_cur_state(), GST_STATE_NULL);
test_equal(queue_size(history_get_queue()), 1);
test_equal(audio_duration(), track_get(0)->tr_length * GST_SECOND);
test_equal(audio_load(NULL), false);
test_equal(audio_load(NULL), (bool)false);
test_equal(load_count, 1);
test_equal(audio_cur_track(), track_get(0));
test_equal((void *)audio_cur_track(), (void *)track_get(0));
test_equal(queue_size(history_get_queue()), 1);
test_equal(audio_load(track_get(0)), false);
test_equal(audio_load(track_get(0)), (bool)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_play(), (bool)true);
test_equal(audio_play(), (bool)false);
test_equal(audio_cur_state(), GST_STATE_PLAYING);
test_equal(audio_pause(), true);
test_equal(audio_pause(), false);
test_equal(audio_pause(), (bool)true);
test_equal(audio_pause(), (bool)false);
test_equal(audio_cur_state(), GST_STATE_PAUSED);
test_equal(test_audio_seek(5 * GST_SECOND), true);
test_equal(test_audio_seek(5 * GST_SECOND), (bool)true);
test_equal(audio_position(), 5 * GST_SECOND);
test_equal(audio_stop(), true);
test_equal(audio_stop(), (bool)true);
test_equal(audio_position(), 0);
test_equal(audio_cur_state(), GST_STATE_PAUSED);
test_equal(test_audio_seek(42 * GST_SECOND), true);
test_equal(test_audio_seek(42 * GST_SECOND), (bool)true);
test_equal(audio_position(), 42 * GST_SECOND);
test_equal(audio_play(), true);
test_equal(audio_stop(), true);
test_equal(audio_play(), (bool)true);
test_equal(audio_stop(), (bool)true);
test_equal(audio_cur_state(), GST_STATE_PAUSED);
test_equal(audio_position(), 0);
@ -153,14 +151,16 @@ static void test_next()
test_loop_equal(audio_next()->tr_dbe.dbe_index, i, i);
} else /* Simulate an error. */
test_send_error();
test_loop_equal(queue_at(history_q, 0), track_get(i), i);
test_loop_equal((void *)queue_at(history_q, 0),
(void *)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_equal((void *)audio_cur_track(),
(void *)track_get(i), i);
} test_loop_passed();
test_equal(tempq_get(0), NULL);
test_equal((void *)tempq_get(0), NULL);
/* Tracks should now be picked from the collection. */
test_equal(audio_play(), true);
test_equal(audio_play(), (bool)true);
for (i = 1; i <= 3; i++) {
if (i < 3) {
test_loop_equal(audio_next()->tr_track, i, i);
@ -178,28 +178,28 @@ static void test_prev()
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((void *)queue_at(history_q, 0), (void *)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((void *)queue_at(history_q, 0), (void *)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_pause(), (bool)true);
test_equal(audio_prev()->tr_dbe.dbe_index, 0);
test_equal(queue_at(history_q, 0), track);
test_equal((void *)queue_at(history_q, 0), (void *)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((void *)queue_at(history_q, 0), (void *)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((void *)queue_at(history_q, 0), (void *)track);
test_equal(audio_cur_state(), GST_STATE_PAUSED);
test_equal(audio_cur_track()->tr_dbe.dbe_index, 2);
}
@ -209,7 +209,7 @@ void test_autopause()
struct queue *history_q = history_get_queue();
int i;
test_equal(audio_play(), true);
test_equal(audio_play(), (bool)true);
test_equal(pause_count, 0);
audio_pause_after(3);
@ -226,7 +226,8 @@ void test_autopause()
audio_eos();
test_loop_equal(pause_count, i, i);
test_loop_equal(audio_cur_state(), GST_STATE_PLAYING, i);
test_loop_equal(queue_at(history_q, 0), audio_cur_track(), i);
test_loop_equal((void *)queue_at(history_q, 0),
(void *)audio_cur_track(), i);
} test_loop_passed();
audio_eos();
@ -237,8 +238,8 @@ void test_autopause()
static void test_deinit()
{
core_deinit();
test_equal(audio_cur_track(), NULL);
test_equal(audio_get_player(), NULL);
test_equal((void *)audio_cur_track(), NULL);
test_equal((void *)audio_get_player(), NULL);
}