driver: Pass Tracks to the load() function

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-12-20 12:00:57 -05:00
parent 9aaa8649ce
commit d7113cb124
4 changed files with 8 additions and 44 deletions

View File

@ -57,7 +57,7 @@ static void _load_track(Track *track, bool start_playback)
if (!track)
return;
cur_driver->load(track->path());
cur_driver->load(track);
get_callbacks()->on_track_loaded(track);
if (start_playback)
audio :: play();

View File

@ -30,9 +30,9 @@ static bool gst_change_state(GstState state)
class GSTDriver : public Driver
{
public:
void load(const std::string &filepath)
void load(Track *track)
{
gchar *uri = gst_filename_to_uri(filepath.c_str(), NULL);
gchar *uri = gst_filename_to_uri(track->path().c_str(), NULL);
gst_change_state(GST_STATE_NULL);
g_object_set(G_OBJECT(gst_player), "uri", uri, NULL);

View File

@ -5,6 +5,7 @@
#ifndef OCARINA_CORE_DRIVER_H
#define OCARINA_CORE_DRIVER_H
#include <core/tags/track.h>
#include <string>
/** Use to convert nanoseconds to seconds */
@ -27,9 +28,9 @@ public:
/**
* Loads an audio file for playback.
*
* @param file Filepath of the track to load.
* @param track The Track to load.
*/
virtual void load(const std::string &file) = 0;
virtual void load(Track *track) = 0;
/**
* Called to begin playback on the currently loaded track.

View File

@ -21,9 +21,9 @@ public:
TestDriver() : playing(false), cur_pos(0), cur_duration(0) {}
~TestDriver() {};
void load(const std::string &file)
void load(Track *track)
{
cur_file = file;
cur_file = track->path();
playing = false;
cur_pos = 0;
}
@ -48,41 +48,6 @@ public:
};
void test_driver()
{
test_equal(audio :: get_driver(), (Driver *)NULL);
TestDriver driver;
const std::string file = "/home/Zelda/Music/Wind Waker/1 - Outset Isle.ogg";
test_not_equal(audio :: get_driver(), (Driver *)NULL);
test_equal((Driver *)&driver, audio :: get_driver());
driver.load(file);
test_equal(driver.cur_file, file);
test_equal(driver.play(), true);
test_equal(driver.playing, true);
test_equal(driver.is_playing(), true);
test_equal(driver.pause(), true);
test_equal(driver.playing, false);
test_equal(driver.is_playing(), false);
driver.seek_to(4242);
test_equal(driver.cur_pos, (long)4242);
test_equal(driver.position(), (long)4242);
driver.cur_duration = 424242;
test_equal(driver.duration(), (long)424242);
driver.play();
driver.seek_to(4242);
driver.load(file);
test_equal(driver.is_playing(), false);
test_equal(driver.position(), (long)0);
}
void test_pre_init()
{
TestDriver *driver = (TestDriver *)audio :: get_driver();
@ -233,8 +198,6 @@ void test_autopause()
int main(int argc, char **argv)
{
run_test("Test Audio Driver", test_driver);
TestDriver driver;
run_test("Test Audio Pre-Init", test_pre_init);
run_test("Test Audio Init", test_init);