diff --git a/core/audio.cpp b/core/audio.cpp index 5df71434..16a19c54 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -4,7 +4,7 @@ */ #include #include -#include +#include #include #include @@ -16,23 +16,23 @@ static unsigned int _pause_count = 0; static Track *cur_track = NULL; static File f_cur_track("cur_track", 0); -static Driver *cur_driver = NULL; +static AudioDriver *cur_driver = NULL; static void _load_track(Track *, bool); static bool continue_playback(); -Driver :: Driver() +AudioDriver :: AudioDriver() { cur_driver = this; } -Driver :: ~Driver() +AudioDriver :: ~AudioDriver() { cur_driver = NULL; } -void Driver :: eos() +void AudioDriver :: eos() { if (cur_track) { cur_track->played(); @@ -191,7 +191,7 @@ unsigned int audio :: pause_count() return _pause_count; } -Driver *audio :: get_driver() +AudioDriver *audio :: get_driver() { return cur_driver; } diff --git a/gui/controls.cpp b/gui/controls.cpp index d007d3eb..aa0a9dfb 100644 --- a/gui/controls.cpp +++ b/gui/controls.cpp @@ -3,7 +3,6 @@ */ #include #include -#include #include static Gtk::Label *o_position; diff --git a/gui/gst.cpp b/gui/gst.cpp index 13735941..8e4641ac 100644 --- a/gui/gst.cpp +++ b/gui/gst.cpp @@ -6,7 +6,6 @@ * what options are supported. */ #include -#include #include #include @@ -30,7 +29,7 @@ static bool gst_change_state(GstState state) } -class GSTDriver : public Driver +class GSTDriver : public AudioDriver { public: void load(Track *track) diff --git a/gui/gui.cpp b/gui/gui.cpp index 3ec6fcaa..b29f0beb 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -3,7 +3,6 @@ */ #include #include -#include #include #include #include diff --git a/include/core/audio.h b/include/core/audio.h index 33102e33..4c0818d2 100644 --- a/include/core/audio.h +++ b/include/core/audio.h @@ -5,23 +5,89 @@ #ifndef OCARINA_CORE_AUDIO_H #define OCARINA_CORE_AUDIO_H -#include #include #include + +/** Use to convert nanoseconds to seconds */ +static const unsigned long O_SECOND = 1000000000; + + +/** + * The audio driver class gives us an interface for using multiple + * audio frameworks for audio playback. + */ +class AudioDriver { +protected: + void (*on_error) (); /**< Error handling callback function. */ + +public: + AudioDriver(); /**< Default AudioDriver constructor. */ + virtual ~AudioDriver(); /**< AudioDriver destructor. */ + + + /** + * Loads an audio file for playback. + * + * @param track The Track to load. + */ + virtual void load(Track *track) = 0; + + /** + * Called to begin playback on the currently loaded track. + */ + virtual void play() = 0; + + /** + * Called to pause playback on the currently loaded track. + */ + virtual void pause() = 0; + + /** + * Called to check if the audio library is currently playing a track. + * + * @return True if audio library is playing, false otherwise. + */ + virtual bool is_playing() = 0; + + + /** + * Seek to a specific position in the current track. + * + * @param offset Position from the beginning of the track where we will seek to, in nanoseconds. + */ + virtual void seek_to(long offset) = 0; + + /** + * Return the current position of the playback. + * + * @return The current playback position, in nanoseconds. + */ + virtual long position() = 0; + + /** + * Return the duration of the currently loaded track. + * + * @return The duration of the current track, in nanoseconds. + */ + virtual long duration() = 0; + + /** + * Called to handle reaching the end-of-stream. + */ + void eos(); +}; + + /** * Namespace for higher-level audio controls. */ namespace audio { - /** - * Initializes the audio layer and currently configured audio driver. - */ - void init(); - - void play(); /** Begin playback. */ - void pause(); /** Pause playback. */ + void init(); /**< Initializes the audio layer. */ + void play(); /**< Begin playback. */ + void pause(); /**< Pause playback. */ /** * Seek to a specific point in the track. @@ -31,7 +97,7 @@ namespace audio void seek_to(long); /** - * Stop playback (equivalent to pause(); seek_to(0);). + * Stop playback and seek to the beginning of the track. */ void stop(); @@ -50,8 +116,8 @@ namespace audio */ std::string position_str(); - void next(); /** Find and load the next track that should be played. */ - void prev(); /** Call the deck :: previous() function and load the result. */ + void next(); /**< Find and load the next track that should be played. */ + void prev(); /**< Call the deck :: previous() function and load the result. */ /** * Load a specific track for playback. @@ -92,7 +158,7 @@ namespace audio * * @return The current driver used by the application. */ - Driver *get_driver(); + AudioDriver *get_driver(); }; #endif /* OCARINA_CORE_AUDIO_H */ diff --git a/include/core/driver.h b/include/core/driver.h deleted file mode 100644 index 4dda521f..00000000 --- a/include/core/driver.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @file - * Copyright 2014 (c) Anna Schumaker. - */ -#ifndef OCARINA_CORE_DRIVER_H -#define OCARINA_CORE_DRIVER_H - -#include -#include - -/** Use to convert nanoseconds to seconds */ -static const unsigned long O_SECOND = 1000000000; - - -/** - * The audio driver class gives us an interface for using multiple - * audio frameworks for audio playback. - */ -class Driver { -protected: - void (*on_error) (); /**< Error handling callback function. */ - -public: - Driver(); /**< Default Driver constructor. */ - virtual ~Driver(); /**< Driver destructor. */ - - - /** - * Loads an audio file for playback. - * - * @param track The Track to load. - */ - virtual void load(Track *track) = 0; - - /** - * Called to begin playback on the currently loaded track. - */ - virtual void play() = 0; - - /** - * Called to pause playback on the currently loaded track. - */ - virtual void pause() = 0; - - /** - * Called to check if the audio library is currently playing a track. - * - * @return True if audio library is playing, false otherwise. - */ - virtual bool is_playing() = 0; - - - /** - * Seek to a specific position in the current track. - * - * @param offset Position from the beginning of the track where we will seek to, in nanoseconds. - */ - virtual void seek_to(long offset) = 0; - - /** - * Return the current position of the playback. - * - * @return The current playback position, in nanoseconds. - */ - virtual long position() = 0; - - /** - * Return the duration of the currently loaded track. - * - * @return The duration of the current track, in nanoseconds. - */ - virtual long duration() = 0; - - /** - * Called to handle reaching the end-of-stream. - */ - void eos(); -}; - -#endif /* OCARINA_CORE_DRIVER_H */ diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index de33c04c..0eb51cb4 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -2,7 +2,6 @@ * Copyright 2013 (c) Anna Schumaker. */ #include -#include #include #include #include @@ -10,7 +9,7 @@ Track *TRACK_NULL = NULL; -class TestDriver : public Driver +class TestDriver : public AudioDriver { public: bool playing;