Public Member Functions | Protected Member Functions | List of all members
ime::audio::Audio Class Referenceabstract

Abstract base class for audio. More...

#include <Audio.h>

Inheritance diagram for ime::audio::Audio:
ime::EventEmitter ime::audio::Music ime::audio::SoundEffect

Public Member Functions

 Audio ()
 Default constructor. 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 (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...
 
virtual std::string getType ()=0
 Get the type of the audio. More...
 
virtual ~Audio ()=default
 Destructor. More...
 
template<typename... Args>
int addEventListener (const std::string &event, Callback< Args... > callback)
 Add an event listener (callback) to an event. More...
 
template<typename... Args>
int on (const std::string &event, Callback< Args... > callback)
 Add an event listener to an event. More...
 
template<typename ... Args>
int addOnceEventListener (const std::string &event, Callback< Args... > callback)
 Add an event listener to an event. More...
 
bool removeEventListener (const std::string &event, int id)
 Remove an event listener from an event. More...
 
bool removeAllEventListeners (const std::string &event)
 Remove all event listeners of an event. More...
 
template<typename... Args>
void emit (const std::string &event, Args...args)
 Fire an event. More...
 
bool hasEvent (const std::string &event) const
 Check if an event exists or not. More...
 
std::size_t getEventListenerCount (const std::string &event) const
 Get the number of event listeners currently registered to an event. More...
 
std::size_t getEventsCount () const
 Get the current number of created events. More...
 
bool hasEventListener (const std::string &event, int id) const
 Check if an event has a certain event listener. More...
 

Protected Member Functions

template<typename... Args>
void emit (const std::string &event, Args...args)
 Prevent external publishing of events. More...
 

Detailed Description

Abstract base class for audio.

Definition at line 47 of file Audio.h.

Constructor & Destructor Documentation

◆ Audio()

ime::audio::Audio::Audio ( )

Default constructor.

◆ ~Audio()

virtual ime::audio::Audio::~Audio ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addEventListener()

template<typename... Args>
int ime::EventEmitter::addEventListener ( const std::string &  event,
Callback< Args... >  callback 
)
inherited

Add an event listener (callback) to an event.

Parameters
eventEvent to add event listener to
callbackFunction to execute when the event is fired
Returns
The event listener's identification number

Every event listener has a unique identification number. This number must be remembered in order to remove the event listener.

Note
If the same callback function is added multiple times, It will be treated as a unique event listener and hence given an identification number

◆ addOnceEventListener()

template<typename ... Args>
int ime::EventEmitter::addOnceEventListener ( const std::string &  event,
Callback< Args... >  callback 
)
inherited

Add an event listener to an event.

Parameters
eventEvent to add event listener to
callbackFunction to execute when the event is fired
Returns
The event listener's identification number

The event listener will be invoked once and subsequently removed from the event. This means that the callback will only execute when an event is fired for the first time. To execute a callback each time the an event is fired

See also
addEventListener

◆ adjustVolume()

void ime::audio::Audio::adjustVolume ( float  offset)

Turn the volume up/down by a given offset.

Parameters
offsetValue 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

See also
setMute

◆ emit() [1/2]

template<typename... Args>
void ime::EventEmitter::emit ( typename...  Args)
protected

Prevent external publishing of events.

Only the class knows the conditions under which an event may be fired. Therefore, events must not be raised externally as this may result in events being raised at the wong time, resulting in undesired and incorrect behavior

◆ emit() [2/2]

template<typename... Args>
void ime::EventEmitter::emit ( const std::string &  event,
Args...  args 
)
inherited

Fire an event.

Parameters
eventName of the event to fire
argsArguments to be passed to event listeners

◆ getDuration()

virtual Time ime::audio::Audio::getDuration ( ) const
pure virtual

Get the total duration of the audio.

Returns
The total duration of the audio

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ getEventListenerCount()

std::size_t ime::EventEmitter::getEventListenerCount ( const std::string &  event) const
inherited

Get the number of event listeners currently registered to an event.

Parameters
eventEvent to get number of event listeners for
Returns
The number of event listeners registered to an event or 0 if no such event exists

◆ getEventsCount()

std::size_t ime::EventEmitter::getEventsCount ( ) const
inherited

Get the current number of created events.

Returns
Current umber of events

◆ getPitch()

virtual float ime::audio::Audio::getPitch ( ) const
pure virtual

Get the pitch of the audio.

Returns
The pitch of the audio

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ getPlayingPosition()

virtual Time ime::audio::Audio::getPlayingPosition ( ) const
pure virtual

Get the current playing position of the audio.

Returns
Current playing position of the audio

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ getSource()

virtual const std::string& ime::audio::Audio::getSource ( ) const
pure virtual

Get audio source.

Returns
Filename of the actual audio file

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ getStatus()

virtual Status ime::audio::Audio::getStatus ( ) const
pure virtual

Get the current status of the audio (stopped, paused, playing)

Returns
Current status of the audio

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ getType()

virtual std::string ime::audio::Audio::getType ( )
pure virtual

Get the type of the audio.

Returns
The type of the audio

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ getVolume()

virtual float ime::audio::Audio::getVolume ( ) const
pure virtual

Get the volume of the audio.

Returns
Volume of the audio, in the range [0, 100]

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ hasEvent()

bool ime::EventEmitter::hasEvent ( const std::string &  event) const
inherited

Check if an event exists or not.

Parameters
eventName of the event to check
Returns
True if event exists or false if the event does not exist

◆ hasEventListener()

bool ime::EventEmitter::hasEventListener ( const std::string &  event,
int  id 
) const
inherited

Check if an event has a certain event listener.

Parameters
eventName of the event
idIdentification number of the listener to be checked
Returns
True if the specified event has an event listener with the specified id, otherwise false

◆ isLooped()

virtual bool ime::audio::Audio::isLooped ( ) const
pure virtual

Check if audio is looped or not.

Returns
True if audio is looped, otherwise false

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ isMuted()

bool ime::audio::Audio::isMuted ( ) const

Check if audio is muted or not.

Returns
True if audio is muted or false if audio is not muted

◆ on()

template<typename... Args>
int ime::EventEmitter::on ( const std::string &  event,
Callback< Args... >  callback 
)
inherited

Add an event listener to an event.

Parameters
eventEvent to add event listener to
callbackFunction to execute when the event is fired
Returns
The event listener's identification number

This function does the same thing as the addEventListener() function. It just provides a slightly more readable syntax:

returnButton.on("click", showMainMenu); as opposed to
returnButton.addEventListener("click", showMainMenu);

◆ pause()

virtual void ime::audio::Audio::pause ( )
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::SoundEffect, and ime::audio::Music.

◆ play()

virtual void ime::audio::Audio::play ( )
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::SoundEffect, and ime::audio::Music.

◆ removeAllEventListeners()

bool ime::EventEmitter::removeAllEventListeners ( const std::string &  event)
inherited

Remove all event listeners of an event.

Parameters
eventEvent to remove all listeners from
Returns
True if all listeners were removed, false if no such event exists

◆ removeEventListener()

bool ime::EventEmitter::removeEventListener ( const std::string &  event,
int  id 
)
inherited

Remove an event listener from an event.

Parameters
eventEvent to remove listener from
idIdentification number of the event listener to be removed
Returns
True if the event listener was removed from athe specified event or false if the specified event does exist or it does not have a listener with the given id

◆ restart()

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

◆ seek()

virtual void ime::audio::Audio::seek ( Time  position)
pure virtual

Change the current playing position of the audio.

Parameters
positionNew 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::SoundEffect, and ime::audio::Music.

◆ setLoop()

virtual void ime::audio::Audio::setLoop ( bool  isLooped)
pure virtual

Set whether or not the audio should loop after reaching the end.

Parameters
isLoopedTrue to play in loop, false to play once

Implemented in ime::audio::SoundEffect, and ime::audio::Music.

◆ setMute()

void ime::audio::Audio::setMute ( bool  mute)

Set whether or not the audio should be audible.

Parameters
muteTrue 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

◆ setPitch()

virtual void ime::audio::Audio::setPitch ( float  pitch)
pure virtual

Set the pitch of the audio.

Parameters
pitchThe 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::SoundEffect, and ime::audio::Music.

◆ setSource()

virtual void ime::audio::Audio::setSource ( const std::string &  filename)
pure virtual

Set audio source to be manipulated.

Parameters
filenameFilename 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::SoundEffect, and ime::audio::Music.

◆ setVolume()

virtual void ime::audio::Audio::setVolume ( float  volume)
pure virtual

Set the volume of the audio.

Parameters
volumeVolume 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::SoundEffect, and ime::audio::Music.

◆ stop()

virtual void ime::audio::Audio::stop ( )
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::SoundEffect, and ime::audio::Music.


The documentation for this class was generated from the following file: