Public Member Functions | List of all members
ime::audio::AudioManager Class Reference

Manages audio playback. More...

#include <AudioManager.h>

Public Member Functions

 AudioManager ()
 Default constructor. More...
 
 AudioManager (const AudioManager &)=delete
 Copy constructor. More...
 
AudioManageroperator= (const AudioManager &)=delete
 Copy assignment operator. More...
 
 AudioManager (AudioManager &&) noexcept=default
 Move constructor. More...
 
AudioManageroperator= (AudioManager &&) noexcept=default
 Move assignment operator. More...
 
Audioplay (Type audioType, const std::string &filename)
 Play an audio file. More...
 
void setVolume (Type audioType, float volume)
 Set the volume for an audio type. More...
 
float getVolumeFor (Type audioType) const
 Get the volume of an audio type. More...
 
void setMasterVolume (float volume)
 Set the maximum volume for all audio types. More...
 
void adjustMasterVolume (float offset)
 Offset the master volume. More...
 
float getMasterVolume () const
 Get the master volume. More...
 
void playAll ()
 Play all paused audio files. More...
 
void pauseAll ()
 Pause all playing audio files. More...
 
void stopAll ()
 Stop all playing audio files. More...
 
void setMute (bool isMuted)
 Mute or unmute all audio. More...
 
void onMute (Callback< bool > callback)
 Add an event listener to a mute event. More...
 
void onVolumeChanged (Callback< float > callback)
 Add an event listener to a master volume change event. More...
 
void removePlayedAudio ()
 

Detailed Description

Manages audio playback.

Definition at line 47 of file AudioManager.h.

Constructor & Destructor Documentation

◆ AudioManager() [1/3]

ime::audio::AudioManager::AudioManager ( )

Default constructor.

◆ AudioManager() [2/3]

ime::audio::AudioManager::AudioManager ( const AudioManager )
delete

Copy constructor.

◆ AudioManager() [3/3]

ime::audio::AudioManager::AudioManager ( AudioManager &&  )
defaultnoexcept

Move constructor.

Member Function Documentation

◆ adjustMasterVolume()

void ime::audio::AudioManager::adjustMasterVolume ( float  offset)

Offset the master volume.

Parameters
offsetThe value to offset the volume by

A positive offset increases the master volume whilst a negative offset decreases it. Note that the master volume cannot be lower that zero (min) or higher than 100 (max)

See also
setMasterVolume

◆ getMasterVolume()

float ime::audio::AudioManager::getMasterVolume ( ) const

Get the master volume.

Returns
The master volume
See also
setMasterVolume

◆ getVolumeFor()

float ime::audio::AudioManager::getVolumeFor ( Type  audioType) const

Get the volume of an audio type.

Parameters
audioTypeThe audio type to get the volume for
Returns
The current volume for audio files of the specified type

◆ onMute()

void ime::audio::AudioManager::onMute ( Callback< bool >  callback)

Add an event listener to a mute event.

Parameters
callbackFunction to be executed audio is muted or unmuted

◆ onVolumeChanged()

void ime::audio::AudioManager::onVolumeChanged ( Callback< float >  callback)

Add an event listener to a master volume change event.

Parameters
callbackFunction to be executed when the master volume changes

◆ operator=() [1/2]

AudioManager & ime::audio::AudioManager::operator= ( AudioManager &&  )
defaultnoexcept

Move assignment operator.

◆ operator=() [2/2]

AudioManager & ime::audio::AudioManager::operator= ( const AudioManager )
delete

Copy assignment operator.

◆ pauseAll()

void ime::audio::AudioManager::pauseAll ( )

Pause all playing audio files.

See also
playAll and stopAll

◆ play()

Audio * ime::audio::AudioManager::play ( Type  audioType,
const std::string &  filename 
)

Play an audio file.

Parameters
audioTypeType of the audio file to play
filenameThe filename of the audio to play
Exceptions
FileNotFoundExceptionif the audio file cannot be found on the disk
Returns
Pointer to the audio file after it starts playing

The audio files are played in a separate thread. This means that, the main thread is not blocked and other audio file may be played simultaneously.

Note that the returned pointer may be used to manipulate properties of the audio file such as volume, pitch, loop state etc. However, it must not be kept alive as it will be invalidated when the audio file stops playing. Trying to access the audio file after it has stopped playing is undefined behavior

◆ playAll()

void ime::audio::AudioManager::playAll ( )

Play all paused audio files.

See also
pauseAll and stopAll

◆ setMasterVolume()

void ime::audio::AudioManager::setMasterVolume ( float  volume)

Set the maximum volume for all audio types.

Parameters
volumeThe new maximum volume

By default, the maximum volume for all audio types is 100 (max)

See also
adjustMasterVolume

◆ setMute()

void ime::audio::AudioManager::setMute ( bool  isMuted)

Mute or unmute all audio.

Parameters
isMutedTrue to mute all audio, otherwise false

◆ setVolume()

void ime::audio::AudioManager::setVolume ( Type  audioType,
float  volume 
)

Set the volume for an audio type.

Parameters
audioTypeThe audio type to set the volume for
volumeVolume to set, in the range 0 <= volume <= 100 where 0 is mute and 100 is maximum volume

The default volume is 100 (max) for all audio types

◆ stopAll()

void ime::audio::AudioManager::stopAll ( )

Stop all playing audio files.

Warning
When an audio file is stopped (explicitly or when it reaches the end of its playback), it automatically gets removed from the audio manager. This invalidates all pointers to the audio instance

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