Robot Devastation
MockAudioManager.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_MOCK_AUDIO_MANAGER_HPP__
6 #define __RD_MOCK_AUDIO_MANAGER_HPP__
7 
8 #include <string>
9 #include <map>
10 #include <mutex>
11 
12 #include <yarp/os/PeriodicThread.h>
13 
14 #include "AudioManager.hpp"
15 
16 namespace rd{
17 
25  public yarp::os::PeriodicThread
26 {
27  public:
28  //---------------- Mock interface -------------------------------------------------------------------------//
30  bool isPlaying(const std::string& id) const;
31 
32 
33  //---------------- Audio-related Stuff ----------------------------------------------------------------------//
34  bool load( const std::string& music_filepath, const std::string& id, const int& type);
35  bool play(const std::string &id, int loop);
36  bool stopMusic();
37 
38 
39  //---------------- Manager Stuff ----------------------------------------------------------------------//
40  virtual bool start();
41  virtual bool stop();
42  virtual bool isStopped() const;
43 
49  static bool RegisterManager();
50 
52  virtual ~MockAudioManager();
53 
55  static const std::string id;
56 
58  static const int AUDIO_DURATION = 30;
59 
61  static const int UPDATE_PERIOD = 100;
62 
63  private:
71 
73  MockAudioManager & operator=(const MockAudioManager &);
74 
76  void run();
77 
80 
82  mutable std::mutex durations_mutex;
83  std::map<std::string, int> durations;
84 
86  mutable std::mutex loop_times_mutex;
87  std::map<std::string, int> loop_times;
88 
89  bool stopped;
90 };
91 
92 }
93 
94 #endif //-- __RD_MOCK_AUDIO_MANAGER_HPP__
rd::AudioManager
Music and sound effects manager.
Definition: AudioManager.hpp:28
rd::MockAudioManager::stop
virtual bool stop()
Stops the AudioManager.
Definition: MockAudioManager.cpp:147
rd::MockAudioManager::run
void run()
Method called periodically from the PeriodicThread class. It simply calls the update() method.
Definition: MockAudioManager.cpp:21
rd
The main, catch-all namespace for Robot Devastation.
Definition: groups.dox:4
rd::MockAudioManager::isPlaying
bool isPlaying(const std::string &id) const
Whether the sound with the given id is being played or not.
Definition: MockAudioManager.cpp:52
rd::MockAudioManager::stopMusic
bool stopMusic()
Stops the music being played currently.
Definition: MockAudioManager.cpp:122
rd::MockAudioManager
Mock music and sound effects manager for testing purposes.
Definition: MockAudioManager.hpp:24
rd::MockAudioManager::~MockAudioManager
virtual ~MockAudioManager()
Destructor. Used to reset the local static reference after destroying this manager.
Definition: MockAudioManager.cpp:171
rd::MockAudioManager::MockAudioManager
MockAudioManager()
Constructor.
Definition: MockAudioManager.cpp:16
rd::MockAudioManager::isStopped
virtual bool isStopped() const
True if the manager is not active.
Definition: MockAudioManager.cpp:156
rd::MockAudioManager::loop_times_mutex
std::mutex loop_times_mutex
Dictionary for loop times.
Definition: MockAudioManager.hpp:86
rd::MockAudioManager::uniqueInstance
static MockAudioManager * uniqueInstance
Stores the unique instance of the AudioManager.
Definition: MockAudioManager.hpp:79
rd::MockAudioManager::RegisterManager
static bool RegisterManager()
Register this manager in the AudioManager registry so that can be used.
Definition: MockAudioManager.cpp:161
rd::MockAudioManager::play
bool play(const std::string &id, int loop)
Plays a music/sound effect file previously loaded.
Definition: MockAudioManager.cpp:100
rd::MockAudioManager::start
virtual bool start()
Start the AudioManager.
Definition: MockAudioManager.cpp:141
rd::MockAudioManager::UPDATE_PERIOD
static const int UPDATE_PERIOD
Thread update period (ms)
Definition: MockAudioManager.hpp:61
rd::MockAudioManager::load
bool load(const std::string &music_filepath, const std::string &id, const int &type)
Loads an audio file, assigning it a string as identifier.
Definition: MockAudioManager.cpp:78
rd::MockAudioManager::id
static const std::string id
String that identifies this manager.
Definition: MockAudioManager.hpp:55
rd::MockAudioManager::AUDIO_DURATION
static const int AUDIO_DURATION
Default duration (s)
Definition: MockAudioManager.hpp:58
rd::MockAudioManager::durations_mutex
std::mutex durations_mutex
Dictionary for sound durations:
Definition: MockAudioManager.hpp:82