Robot Devastation
AudioManager.hpp
1 // Authors: see AUTHORS.md at project root.
2 // CopyPolicy: released under the terms of the LGPLv2.1, see LICENSE at project root.
3 // URL: https://github.com/asrob-uc3m/robotDevastation
4 
5 #ifndef __RD_AUDIO_MANAGER_HPP__
6 #define __RD_AUDIO_MANAGER_HPP__
7 
8 #include <string>
9 #include <map>
10 
11 namespace rd{
12 
29 {
30  public:
31  //------------------------------ Construction & destruction ---------------------------------------------------//
37  static AudioManager * getAudioManager();
38 
44  static AudioManager * getAudioManager(const std::string & id);
45 
47  static bool destroyAudioManager();
48 
49  virtual ~AudioManager();
50 
51 
52  //------------------------------ Manager Startup & Halting ----------------------------------------------------//
58  virtual bool start() = 0;
59 
61  virtual bool stop() = 0;
62 
64  virtual bool isStopped() const = 0;
65 
66  //------------------------------ Configuration ----------------------------------------------------------------//
68  virtual bool configure(const std::string & parameter, const std::string & value);
69 
70 
71  //------------------------------- Audio Manager functions -----------------------------------------------------//
80  virtual bool load( const std::string& music_filepath, const std::string& id, const int& type) = 0;
81 
88  virtual bool play(const std::string& id, int loop = 1) = 0;
89 
94  virtual bool stopMusic() = 0;
95 
97  static const int MUSIC;
99  static const int FX;
100 
101  protected:
106  static bool Register( AudioManager * manager, const std::string & id);
107 
108 
109  private:
112 
114  static std::string currentId;
115 
117  static std::map< std::string, AudioManager * > audioManagerRegistry;
118 
119 };
120 
121 }
122 
123 #endif //-- __RD_AUDIO_MANAGER_HPP__
rd::AudioManager
Music and sound effects manager.
Definition: AudioManager.hpp:28
rd::AudioManager::MUSIC
static const int MUSIC
Identifier for music tracks.
Definition: AudioManager.hpp:97
rd
The main, catch-all namespace for Robot Devastation.
Definition: groups.dox:4
rd::AudioManager::start
virtual bool start()=0
Start the AudioManager.
rd::AudioManager::configure
virtual bool configure(const std::string &parameter, const std::string &value)
Configures a parameter with a value.
Definition: AudioManager.cpp:98
rd::AudioManager::load
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.
rd::AudioManager::play
virtual bool play(const std::string &id, int loop=1)=0
Plays a music/sound effect file previously loaded.
rd::AudioManager::audioManagerRegistry
static std::map< std::string, AudioManager * > audioManagerRegistry
Stores all the AudioManager that have been registered.
Definition: AudioManager.hpp:117
rd::AudioManager::currentId
static std::string currentId
Stores the id of the current unique instance used.
Definition: AudioManager.hpp:114
rd::AudioManager::stop
virtual bool stop()=0
Stops the AudioManager.
rd::AudioManager::isStopped
virtual bool isStopped() const =0
True if the manager is not active.
rd::AudioManager::stopMusic
virtual bool stopMusic()=0
Stops the music being played currently.
rd::AudioManager::getAudioManager
static AudioManager * getAudioManager()
Get a reference to the AudioManager.
Definition: AudioManager.cpp:20
rd::AudioManager::audioManagerInstance
static AudioManager * audioManagerInstance
Stores the unique instance of the AudioManager.
Definition: AudioManager.hpp:111
rd::AudioManager::FX
static const int FX
Identifier for sound effect tracks.
Definition: AudioManager.hpp:99
rd::AudioManager::destroyAudioManager
static bool destroyAudioManager()
Deallocate all the registered AudioManager.
Definition: AudioManager.cpp:57
rd::AudioManager::Register
static bool Register(AudioManager *manager, const std::string &id)
This function allows subclasses to install their unique instances in the singleton register to be sel...
Definition: AudioManager.cpp:103