Robot Devastation
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Static Private Attributes | List of all members
rd::AudioManager Class Referenceabstract

Music and sound effects manager. More...

#include <AudioManager.hpp>

Inheritance diagram for rd::AudioManager:
rd::MockAudioManager rd::SDLAudioManager

Public Member Functions

virtual bool start ()=0
 Start the AudioManager. More...
 
virtual bool stop ()=0
 Stops the AudioManager.
 
virtual bool isStopped () const =0
 True if the manager is not active.
 
virtual bool configure (const std::string &parameter, const std::string &value)
 Configures a parameter with a value.
 
virtual bool load (const std::string &music_filepath, const std::string &id, const int &type)=0
 Loads an audio file, assigning it a string as identifier. More...
 
virtual bool play (const std::string &id, int loop=1)=0
 Plays a music/sound effect file previously loaded. More...
 
virtual bool stopMusic ()=0
 Stops the music being played currently. More...
 

Static Public Member Functions

static AudioManagergetAudioManager ()
 Get a reference to the AudioManager. More...
 
static AudioManagergetAudioManager (const std::string &id)
 Get a reference to the AudioManager. More...
 
static bool destroyAudioManager ()
 Deallocate all the registered AudioManager.
 

Static Public Attributes

static const int MUSIC = 0
 Identifier for music tracks.
 
static const int FX = 1
 Identifier for sound effect tracks.
 

Static Protected Member Functions

static bool Register (AudioManager *manager, const std::string &id)
 This function allows subclasses to install their unique instances in the singleton register to be selected later by the user.
 

Static Private Attributes

static AudioManageraudioManagerInstance = NULL
 Stores the unique instance of the AudioManager.
 
static std::string currentId = ""
 Stores the id of the current unique instance used.
 
static std::map< std::string, AudioManager * > audioManagerRegistry = std::map<std::string, rd::AudioManager *>()
 Stores all the AudioManager that have been registered.
 

Detailed Description

AudioManager can load several audio files and assign them a string for identification, so that they can be played later.

AudioManager is a singleton text (only one instance of this object can exist, that is is shared by all the users). To use this class, we first get the reference to the AudioManager with getAudioManager() and then we access the manager with that reference.

When the program finishes, the AudioManager can be deallocated using destroAudioManager().

Member Function Documentation

◆ getAudioManager() [1/2]

rd::AudioManager * rd::AudioManager::getAudioManager ( )
static
Returns
By default, if no id is specified, this will return a reference to the first AudioManager that it can find in the registry, or NULL if no AudioManager was registered.

◆ getAudioManager() [2/2]

rd::AudioManager * rd::AudioManager::getAudioManager ( const std::string &  id)
static
Returns
The AudioManager registered with the given id, NULL if the id is not found in the registry.

◆ load()

virtual bool rd::AudioManager::load ( const std::string &  music_filepath,
const std::string &  id,
const int &  type 
)
pure virtual
Parameters
music_filepathPath to the file to be loaded
idString that will identify the audio loaded
typeCan take a value of MUSIC or FX depending if the audio is to be loaded as game music or sound effect
Returns
True if sound was loaded successfully, false otherwise

Implemented in rd::MockAudioManager, and rd::SDLAudioManager.

◆ play()

virtual bool rd::AudioManager::play ( const std::string &  id,
int  loop = 1 
)
pure virtual
Parameters
idString that identifies the music / sound effect track
loopNumber of times the music is played. -1 means play the music forever.
Returns
True if sound was played successfully, false otherwise

Implemented in rd::MockAudioManager, and rd::SDLAudioManager.

◆ start()

virtual bool rd::AudioManager::start ( )
pure virtual

This function is supposed to be called after AudioManager configuration.

Implemented in rd::MockAudioManager, and rd::SDLAudioManager.

◆ stopMusic()

virtual bool rd::AudioManager::stopMusic ( )
pure virtual
Returns
False if the music could not be stopped

Implemented in rd::MockAudioManager, and rd::SDLAudioManager.


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