Abstract base class for audio. More...
#include <Audio.h>
Public Types | |
using | Ptr = std::unique_ptr< Object > |
Unique object pointer. More... | |
Public Member Functions | |
Audio () | |
Default constructor. More... | |
std::string | getClassType () const override |
Get the name of this class. More... | |
virtual void | setSource (const std::string &filename)=0 |
Set audio source to be manipulated. More... | |
virtual const std::string & | getSource () const =0 |
Get audio source. More... | |
virtual void | setVolume (float volume)=0 |
Set the volume of the audio. More... | |
void | adjustVolume (float offset) |
Turn the volume up/down by a given offset. More... | |
virtual float | getVolume () const =0 |
Get the volume of the audio. More... | |
void | setMute (bool mute) |
Set whether or not the audio should be audible. More... | |
bool | isMuted () const |
Check if audio is muted or not. More... | |
virtual void | setPitch (float pitch)=0 |
Set the pitch of the audio. More... | |
virtual float | getPitch () const =0 |
Get the pitch of the audio. More... | |
virtual void | setLoop (bool isLooped)=0 |
Set whether or not the audio should loop after reaching the end. More... | |
virtual bool | isLooped () const =0 |
Check if audio is looped or not. More... | |
virtual void | seek (const Time &position)=0 |
Change the current playing position of the audio. More... | |
virtual Time | getPlayingPosition () const =0 |
Get the current playing position of the audio. More... | |
virtual void | play ()=0 |
Play audio. More... | |
virtual void | pause ()=0 |
Pause audio. More... | |
virtual void | stop ()=0 |
Stop playing the audio. More... | |
void | restart () |
Reset the playing position to the beginning. More... | |
virtual Time | getDuration () const =0 |
Get the total duration of the audio. More... | |
virtual Status | getStatus () const =0 |
Get the current status of the audio (stopped, paused, playing) More... | |
~Audio () override | |
Destructor. More... | |
void | setTag (const std::string &tag) |
Assign the object an alias. More... | |
const std::string & | getTag () const |
Get the tag assigned to the object. More... | |
unsigned int | getObjectId () const |
Get the unique id of the object. More... | |
virtual std::string | getClassName () const =0 |
Get the name of the objects concrete class. More... | |
int | onPropertyChange (const std::string &property, const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to a specific property change event. More... | |
int | onPropertyChange (const Callback< Property > &callback, bool oneTime=false) |
Add an event listener to any property change event. More... | |
void | suspendedEventListener (int id, bool suspend) |
Pause or resume execution of an event listener. More... | |
bool | isEventListenerSuspended (int id) const |
Check if an event listener is suspended or not. More... | |
bool | removeEventListener (const std::string &event, int id) |
Remove an event listener from an event. More... | |
bool | removeEventListener (int id) |
Remove an event listener. More... | |
int | onDestruction (const Callback<> &callback) |
Add a destruction listener. More... | |
bool | isSameObjectAs (const Object &other) const |
Check if another object is the same instance as this object. More... | |
Protected Member Functions | |
void | emitChange (const Property &property) |
Dispatch a property change event. More... | |
void | emitDestruction () |
Emit a destruction event. More... | |
Protected Attributes | |
EventEmitter | eventEmitter_ |
Event dispatcher. More... | |
|
inherited |
ime::audio::Audio::Audio | ( | ) |
Default constructor.
|
override |
Destructor.
void ime::audio::Audio::adjustVolume | ( | float | offset | ) |
Turn the volume up/down by a given offset.
offset | Value to increase/decrease the volume by |
This function adds on to the current volume. A positive offset increases the volume while a negative offset decreases the volume. This function will unmmute the audio if its muted
|
protectedinherited |
Dispatch a property change event.
property | The property that changed |
This function will invoke all the event listeners of the specified property
|
protectedinherited |
Emit a destruction event.
|
pure virtualinherited |
Get the name of the objects concrete class.
This function is implemented by all internal classes that inherit from this class (either directly or indirectly). Example:
Implemented in ime::audio::Music, ime::audio::SoundEffect, ime::GameObject, ime::GridObject, ime::CyclicGridMover, ime::GridMover, ime::KeyboardGridMover, ime::RandomGridMover, ime::TargetGridMover, ime::AABB, ime::BoxCollider, ime::CircleCollider, ime::EdgeCollider, ime::PolygonCollider, ime::DistanceJoint, ime::RigidBody, ime::RenderLayer, ime::RenderLayerContainer, ime::Scene, ime::Camera, ime::CircleShape, ime::ConvexShape, ime::RectangleShape, ime::Sprite, ime::SpriteSheet, and ime::Tile.
|
overridevirtual |
Get the name of this class.
Note that this function is only implemented by child classes of Object which also serve as a base class for other classes
Reimplemented from ime::Object.
|
pure virtual |
Get the total duration of the audio.
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
inherited |
Get the unique id of the object.
Note that each instance of ime::Object has a unique id
|
pure virtual |
Get the pitch of the audio.
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
pure virtual |
Get the current playing position of the audio.
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
pure virtual |
Get audio source.
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
pure virtual |
Get the current status of the audio (stopped, paused, playing)
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
inherited |
|
pure virtual |
Get the volume of the audio.
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
inherited |
Check if an event listener is suspended or not.
id | The identification number of the listener to be checked |
This function also returns false if the specified event listener does not exist
|
pure virtual |
Check if audio is looped or not.
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
bool ime::audio::Audio::isMuted | ( | ) | const |
Check if audio is muted or not.
|
inherited |
Check if another object is the same instance as this object.
other | The object to compare against this object |
|
inherited |
Add a destruction listener.
callback | Function to be executed when the object is destroyed |
The destruction listener is called when the object reaches the end of its lifetime. Note that an object may have multiple destruction listeners registered to it
|
inherited |
Add an event listener to any property change event.
callback | The function to be executed when any property changes |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
When unsubscribing the any property change event handler, you must pass "propertyChange" as the name of the event
|
inherited |
Add an event listener to a specific property change event.
property | The name of the property to add an event listener to |
oneTime | True to execute the callback one-time or false to execute it every time the event is triggered |
callback | The function to be executed when the property changes |
A property change event is triggered by any function that begins with set, where the the text after set is the name of the property. For example, the setTag() function, modifies the tag property of the object, thus will generate a "tag" change event each time it is called
Note that multiple event listeners may be registered to the same property change event. In addition, when adding a property change event listener, the name of the property must be in lowercase.
|
pure virtual |
Pause audio.
This function pauses the stream if it was playing, otherwise (audio already paused or stopped) it has no effect
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
pure virtual |
Play audio.
This function starts the audio if it was stopped, resumes it if it was paused, and restarts it from the beginning if it was already playing. This function uses its own thread so that it doesn't block the rest of the program while the audio is played
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
inherited |
Remove an event listener from an event.
event | The name of the event to remove an event listener from |
id | The unique id of the event listener to be removed |
|
inherited |
Remove an event listener.
id | The id of the event listener to be removed |
void ime::audio::Audio::restart | ( | ) |
Reset the playing position to the beginning.
This function will reset the playing position without stopping the audio (unlike stop function), which would require play to be called to get the audio to play again
|
pure virtual |
Change the current playing position of the audio.
position | New playing position of the audio |
The playing position can be changed when the audio is either paused or playing. Changing the playing position when the audio is stopped has no effect, since playing the audio would reset its position
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
pure virtual |
Set whether or not the audio should loop after reaching the end.
isLooped | True to play in loop, false to play once |
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
void ime::audio::Audio::setMute | ( | bool | mute | ) |
Set whether or not the audio should be audible.
mute | True to make audio inaudible, or false to make audio audible |
When set to true the audio will not be audible but will continue to play if currently playing
|
pure virtual |
Set the pitch of the audio.
pitch | The new pitch of the audio |
The pitch represents the perceived fundamental frequency of a sound; thus you can make a sound more acute or grave by changing its pitch. Changing the pitch also changes the playing speed of the audio.
The default value for the pitch is 1
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
pure virtual |
Set audio source to be manipulated.
filename | Filename of an audio file |
The filename must refer to an actual audio file on the disk. This audio file is the one to be played, pitched and done all sorts of things
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
inherited |
Assign the object an alias.
tag | The alias of the object |
This function is useful if you want to refer to the object by a tag instead of its object id. Unlike an object id, multiple objects may have the same tag
By default, the tag is an empty string
|
pure virtual |
Set the volume of the audio.
volume | Volume to set |
The volume is a value between 0 (mute) and 100 (full volume).
The default value for the volume is 100
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
pure virtual |
Stop playing the audio.
This function stops the audio if it was playing or paused, and does nothing if it was already stopped. It also resets the playing position
Implemented in ime::audio::Music, and ime::audio::SoundEffect.
|
inherited |
Pause or resume execution of an event listener.
id | The event listeners unique identification number |
suspend | True to suspend/pause or false to unsuspend/resume |
|
protectedinherited |