ocarina/include/core/audio.h

126 lines
2.6 KiB
C++

/**
* 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 {
/* Called when a track is loaded. */
void (*on_load)(struct track *, GstState);
};
/**
* 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. */
/**
* 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;
/**
* Called to handle reaching the end-of-stream.
*/
void eos();
};
/**
* Namespace for higher-level audio controls.
*/
namespace audio
{
/**
* Stop playback and seek to the beginning of the track.
*/
void stop();
void next(); /**< Find and load the next track that should be played. */
void prev(); /**< Call the deck :: previous() function and load the result. */
/**
* @return A pointer to the currently playing track object.
*/
struct track *current_track();
/**
* Configure the automatic pausing feature.
*
* @param enabled Set to true to enable pausing, false to disable.
* @param n Number of tracks to play before pausing.
*/
void pause_after(bool, unsigned int);
/**
* Call to find the current automatic pausing state.
*
* @return True if automatic pausing is enabled, false otherwise.
*/
bool pause_enabled();
/**
* Call to find the number of tracks remaining before pausing.
*
* @return The number of tracks before pausing.
*/
unsigned int pause_count();
/**
* Called to access an audio driver.
*
* @return The current driver used by the application.
*/
AudioDriver *get_driver();
};
/* Called to initialize the audio manager. */
void audio_init(int *, char ***, struct audio_ops *);
/* Called to deinitialize the audio manager. */
void audio_deinit();
/* Called to load a track for playback. */
bool audio_load(struct track *);
/* Called to begin playback. */
bool audio_play();
/* Called to pause playback. */
bool audio_pause();
/* Called to seek playback to a specific offset, in nanoseconds. */
bool audio_seek(gint64);
/* Called to find the current playback position, in nanoseconds. */
gint64 audio_position();
/* Called to find the duration of the current track. */
gint64 audio_duration();
GstElement *audio_get_player();
#endif /* OCARINA_CORE_AUDIO_H */