SuperTuxKart
music_manager.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2006-2015 Patrick Ammann <pammann@aro.ch>
4 // Copyright (C) 2008-2015 Patrick Ammann <pammann@aro.ch>, Joerg Henrichs
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 3
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 #ifndef HEADER_MUSICMANAGER_HPP
21 #define HEADER_MUSICMANAGER_HPP
22 
23 #include "audio/music.hpp"
24 #include "audio/music_information.hpp"
25 #include "utils/no_copy.hpp"
26 
27 #include <atomic>
28 #include <map>
29 #include <string>
30 #include <vector>
31 
32 class Vec3;
33 
38 class MusicManager : public NoCopy
39 {
40 friend class MusicInformation;
41 private:
42  std::atomic<MusicInformation*> m_current_music;
43 
48 
50  std::map<std::string, MusicInformation*>
52  float m_master_gain;
53 
54  void loadMusicInformation();
55  void loadMusicFromOneDir(const std::string& dir);
56 
57 public:
58  MusicManager();
59  virtual ~MusicManager();
60  MusicInformation* getMusicInformation(const std::string& filename);
61  void addMusicToTracks();
62 
63  void startMusic();
65  bool start_right_now=true);
66  void stopMusic();
67  void pauseMusic();
68  void resumeMusic();
69  void switchToFastMusic();
70  void setMasterMusicVolume(float gain);
71  void resetTemporaryVolume();
72  void setTemporaryVolume(float gain);
73  // ------------------------------------------------------------------------
75  float getMasterMusicVolume() const { return m_master_gain; }
76  // ------------------------------------------------------------------------
78  bool initialized() const { return m_initialized; }
79  // ------------------------------------------------------------------------
81  MusicInformation* getCurrentMusic() { return m_current_music; }
82  // ------------------------------------------------------------------------
85  {
86  stopMusic();
87  m_current_music = NULL;
88  }
89 };
90 
91 extern MusicManager* music_manager;
92 
93 #endif // HEADER_SOUNDMANAGER_HPP
94 
MusicInformation * getCurrentMusic()
Returns the information object of the current music.
Definition: music_manager.hpp:81
Wrapper around an instance of the Music interface Adds information like composer, song title...
Definition: music_information.hpp:42
A wrapper around bullets btVector3 to include conventient conversion functions (e.g.
Definition: vec3.hpp:34
void resetTemporaryVolume()
Queues a command for the sfx manager to reset a temporary volume change.
Definition: music_manager.cpp:252
void pauseMusic()
Insert a command into the sfx queue to pause the current music.
Definition: music_manager.cpp:212
void switchToFastMusic()
Switches to fast (last lap ) music (if defined for the current music).
Definition: music_manager.cpp:230
void resumeMusic()
Inserts a resume current music event into the queue.
Definition: music_manager.cpp:221
void setMasterMusicVolume(float gain)
Sets the master music volume.
Definition: music_manager.cpp:263
bool initialized() const
Returns if the music system is initialised.
Definition: music_manager.hpp:78
void clearCurrentMusic()
Stops and removes the current music.
Definition: music_manager.hpp:84
Central place to request for musics to be loaded, played, stopped, etc...
Definition: music_manager.hpp:38
bool m_initialized
If the sound could not be initialized, e.g.
Definition: music_manager.hpp:47
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
void setTemporaryVolume(float gain)
Queues a command to temporarily change the volume.
Definition: music_manager.cpp:242
float getMasterMusicVolume() const
Returns the master volume.
Definition: music_manager.hpp:75
void startMusic()
Special shortcut vor overworld (which skips other phases where the music would normally be started...
Definition: music_manager.cpp:165
std::map< std::string, MusicInformation * > m_all_music
Stores all music information files (read from the .music files).
Definition: music_manager.hpp:51
MusicInformation * getMusicInformation(const std::string &filename)
Definition: music_manager.cpp:284
void stopMusic()
Queues a stop current music event for the audio thread.
Definition: music_manager.cpp:203