audio: Initialize GST from the gui layer

This means I no longer need to pass argc and argv parameters to core/,
so I can eventually work towards removing the Driver :: init() function.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-12-20 10:16:44 -05:00
parent e7a8ad54bd
commit fd2a251c14
10 changed files with 31 additions and 39 deletions

View File

@ -84,11 +84,11 @@ static void on_eos()
_load_track(deck :: next(), continue_playback());
}
void audio :: init(int *argc, char ***argv)
void audio :: init()
{
unsigned int id;
cur_driver->init(argc, argv, on_eos);
cur_driver->init(on_eos);
if (f_cur_track.exists()) {
f_cur_track.open(OPEN_READ);
f_cur_track >> id;

View File

@ -10,11 +10,11 @@
#include <core/tags/tags.h>
void core :: init(int *argc, char ***argv)
void core :: init()
{
tags :: init();
library :: init();
playlist :: init();
deck :: init();
audio :: init(argc, argv);
audio :: init();
}

View File

@ -27,7 +27,7 @@ public:
/**
* GStreamer audio driver constructor.
*/
GSTDriver();
GSTDriver(int *, char ***);
/**
* GStreamer audio driver destructor.
@ -36,11 +36,9 @@ public:
/**
* Called to initialize the GStreamer audio driver.
* @param argc Argc passed to the application's main() function.
* @param argv Argv passed to the applicaiton's main() function.
* @param eos_cb End-of-stream callback function.
*/
void init(int *, char ***, void (*)());
void init(void (*)());
/**
* Load a track into the gstreamer pipeline.
@ -113,7 +111,16 @@ static void parse_gst_error(GstMessage *error, const std::string filepath)
g_free(debug);
}
GSTDriver :: GSTDriver() {}
GSTDriver :: GSTDriver(int *argc, char ***argv)
: Driver()
{
GstBus *bus;
gst_init(argc, argv);
player = gst_element_factory_make("playbin", "ocarina_player");
bus = gst_pipeline_get_bus(GST_PIPELINE(player));
gst_bus_add_watch(bus, on_gst_message, this);
}
GSTDriver :: ~GSTDriver()
{
@ -133,16 +140,9 @@ bool GSTDriver :: change_state(GstState state)
}
}
void GSTDriver :: init(int *argc, char ***argv, void (*eos_cb)())
void GSTDriver :: init(void (*eos_cb)())
{
GstBus *bus;
on_eos = eos_cb;
gst_init(argc, argv);
player = gst_element_factory_make("playbin", "ocarina_player");
bus = gst_pipeline_get_bus(GST_PIPELINE(player));
gst_bus_add_watch(bus, on_gst_message, this);
}
void GSTDriver :: load(const std::string &filepath)
@ -211,9 +211,9 @@ void GSTDriver :: on_message(GstMessage *message)
}
void init_gst()
void init_gst(int *argc, char ***argv)
{
gst_driver = new GSTDriver();
gst_driver = new GSTDriver(argc, argv);
}
void quit_gst()

View File

@ -8,7 +8,7 @@
Gtk::Window *ocarina_init(int *argc, char ***argv)
{
init_gst();
init_gst(argc, argv);
lib :: init(argc, argv, "ocarina6.glade");
Gtk::Window *window = setup_gui();

View File

@ -17,11 +17,8 @@ namespace audio
/**
* Initializes the audio layer and currently configured audio driver.
*
* @param argc Pointer to the argc initially passed to core :: init().
* @param argv Pointer to the argv initially passed to core :: init().
*/
void init(int *, char ***);
void init();
void play(); /** Begin playback. */
void pause(); /** Pause playback. */

View File

@ -14,11 +14,8 @@ namespace core
/**
* Initializes all components of the core library, including reading
* databases from disk and setting up gstreamer.
*
* @param argc Pointer to the argc initially passed to main()
* @param argv Pointer to the argv initially passed to main()
*/
void init(int *, char ***);
void init();
}

View File

@ -27,11 +27,9 @@ public:
/**
* Initialize an audio driver.
*
* @param argc Argc passed to the application's main() function.
* @param argv Argv passed to the applicaiton's main() function.
* @param eos_cb End-of-stream callback function.
*/
virtual void init(int *argc, char ***argv, void (*eos_cb)()) = 0;
virtual void init(void (*eos_cb)()) = 0;
/**

View File

@ -25,7 +25,7 @@ void post_init_queue_tabs();
/* gst.cpp */
void init_gst();
void init_gst(int *, char ***);
void quit_gst();

View File

@ -30,7 +30,7 @@ void lib :: init(int *argc, char ***argv, const std::string &gtk_xml)
if (!builder->add_from_file(lib :: share_file(gtk_xml)))
exit(1);
core :: init(argc, argv);
core :: init();
}
const std::string lib :: share_file(const std::string &f)

View File

@ -22,7 +22,7 @@ public:
TestDriver() : playing(false), cur_pos(0), cur_duration(0) {}
~TestDriver() {};
void init(int *argc, char ***argv, void (*eos_cb)())
void init(void (*eos_cb)())
{
on_eos = eos_cb;
}
@ -70,7 +70,7 @@ void test_driver()
test_not_equal(audio :: get_driver(), (Driver *)NULL);
test_equal((Driver *)&driver, audio :: get_driver());
driver.init(0, NULL, on_eos);
driver.init(on_eos);
driver.load(file);
test_equal(driver.cur_file, file);
@ -134,19 +134,19 @@ void test_pre_init()
test_equal(audio :: current_track(), TRACK_NULL);
}
void test_init(int argc, char **argv)
void test_init()
{
Track *track;
test :: cp_data_dir();
audio :: init(&argc, &argv);
audio :: init();
track = audio :: current_track();
test_equal(track, TRACK_NULL);
tags :: init();
library :: init();
audio :: init(&argc, &argv);
audio :: init();
track = audio :: current_track();
test_not_equal(track, TRACK_NULL);
@ -254,7 +254,7 @@ int main(int argc, char **argv)
TestDriver driver;
run_test("Test Audio Pre-Init", test_pre_init);
run_test("Test Audio Init", test_init, argc, argv);
run_test("Test Audio Init", test_init);
run_test("Test Audio Playback Controls", test_playback_controls);
run_test("Test Audio Track Controls", test_track_controls);
run_test("Test Audio Automatic Pausing", test_autopause);