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 <map>
28 #include <string>
29 #include <vector>
30 
31 class Vec3;
32 
33 /**
34   * \brief Central place to request for musics to be loaded, played, stopped, etc...
35   * \ingroup audio
36   */
37 class MusicManager : public NoCopy
38 {
39 private:
40     MusicInformation        *m_current_music;
41 
42     /** If the sound could not be initialized, e.g. if the player doesn't has
43      *  a sound card, we want to avoid anything sound related so we crash the
44      *  game. */
45     bool              m_initialized;
46 
47     /** Stores all music information files (read from the .music files). */
48     std::map<std::string, MusicInformation*>
49                       m_all_music;
50     float             m_master_gain;
51 
52     void              loadMusicInformation();
53     void              loadMusicFromOneDir(const std::string& dir);
54 
55 public:
56                       MusicManager();
57     virtual          ~MusicManager();
58     MusicInformation* getMusicInformation(const std::string& filename);
59     void              addMusicToTracks();
60 
61     void              startMusic();
62     void              startMusic(MusicInformation* mi,
63                                  bool start_right_now=true);
64     void              stopMusic();
65     void              pauseMusic();
66     void              resumeMusic();
67     void              switchToFastMusic();
68     void              setMasterMusicVolume(float gain);
69     void              resetTemporaryVolume();
70     void              setTemporaryVolume(float gain);
71     // ------------------------------------------------------------------------
72     /** Returns the master volume. */
getMasterMusicVolume() const73     float getMasterMusicVolume() const { return m_master_gain; }
74     // ------------------------------------------------------------------------
75     /** Returns if the music system is initialised. */
initialized() const76     bool initialized() const { return m_initialized; }
77     // ------------------------------------------------------------------------
78     /** Returns the information object of the current music. */
getCurrentMusic()79     MusicInformation* getCurrentMusic() { return m_current_music; }
80     // ------------------------------------------------------------------------
81     /** Stops and removes the current music. */
clearCurrentMusic()82     void clearCurrentMusic() { m_current_music = NULL; }
83 };
84 
85 extern MusicManager* music_manager;
86 
87 #endif // HEADER_SOUNDMANAGER_HPP
88 
89