SuperTuxKart
music_information.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2008-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_MUSIC_INFORMATION_HPP
20 #define HEADER_MUSIC_INFORMATION_HPP
21 
22 #include <mutex>
23 #include <string>
24 #include <stdexcept>
25 #include <vector>
26 
27 #include "utils/no_copy.hpp"
28 #include "utils/leak_check.hpp"
29 
30 #include <irrString.h>
31 using irr::core::stringw;
32 
33 class Music;
34 class XMLNode;
35 
42 class MusicInformation : public NoCopy
43 {
44 private:
45  stringw m_composer;
46  stringw m_title;
47  std::string m_normal_filename;
48  std::string m_fast_filename;
49  std::vector<std::string> m_all_tracks;
50  //int m_numLoops;
51 
55 
59 
60  float m_gain;
61 
62  float m_normal_loop_start;
63  float m_fast_loop_start;
64  float m_normal_loop_end;
65  float m_fast_loop_end;
66 
70  float m_max_pitch;
71  static const int LOOP_FOREVER=-1;
72  mutable std::mutex m_music_mutex;
73  Music *m_normal_music,
74  *m_fast_music;
75  enum {SOUND_NORMAL,
78  SOUND_FAST}
79  m_mode;
80  float m_time_since_faster;
81 
82  // The constructor is private so that the
83  // static create function must be used.
84  MusicInformation (const XMLNode *root, const std::string &filename);
85 
86  // Declare the following functions private, but allow the SFXManager
87  // to access them. This makes sure that only the sfx thread calls
88  // openal/vorbis etc, and so makes it is all thread safe.
89 private:
90  friend class SFXManager;
91  void update(float dt);
92  void startMusic();
93  void stopMusic();
94  void pauseMusic();
95  void resumeMusic();
96  void setDefaultVolume();
97  void switchToFastMusic();
98  void setTemporaryVolume(float volume);
99  // ------------------------------------------------------------------------
100  bool preStart();
101  // ------------------------------------------------------------------------
104  void setMusicWaiting() { m_music_waiting = true; }
105  // ------------------------------------------------------------------------
106 
107 public:
108  LEAK_CHECK()
109 
110 #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
111 #pragma warning(disable:4290)
112 #endif
113  ~MusicInformation ();
114  static MusicInformation *create(const std::string &filename);
115  void addMusicToTracks();
116  bool isPlaying() const;
117 
118  // ------------------------------------------------------------------------
120  const stringw& getComposer() const { return m_composer; }
121  // ------------------------------------------------------------------------
123  const stringw& getTitle() const { return m_title; }
124  // ------------------------------------------------------------------------
126  const std::string& getNormalFilename() const { return m_normal_filename; }
127  // ------------------------------------------------------------------------
129  const std::string& getFastFilename() const { return m_fast_filename; }
130  // ------------------------------------------------------------------------
131  float getMaxPitch() const { return m_max_pitch; }
132 
133 }; // MusicInformation
134 #endif
const std::string & getNormalFilename() const
Returns the filename of the normal speed music.
Definition: music_information.hpp:126
const stringw & getComposer() const
Returns the composer of the music.
Definition: music_information.hpp:120
static MusicInformation * create(const std::string &filename)
A simple factory to create music information files without raising an exception on error...
Definition: music_information.cpp:41
Wrapper around an instance of the Music interface Adds information like composer, song title...
Definition: music_information.hpp:42
const stringw & getTitle() const
Returns the title of the music.
Definition: music_information.hpp:123
bool m_enable_fast
If faster music is enabled at all (either separate file or using the pitch shift approach).
Definition: music_information.hpp:58
float m_faster_time
Either time for fading faster music in, or time to change pitch.
Definition: music_information.hpp:68
change pitch of normal music
Definition: music_information.hpp:77
enum MusicInformation::@2 m_mode
< playing faster music or max pitch reached
const std::string & getFastFilename() const
If available, returns the file name of the faster/last-lap music.
Definition: music_information.hpp:129
void update()
Make sure that the sfx thread is started at least once per frame.
Definition: sfx_manager.cpp:808
Manager of all sound effects.
Definition: sfx_manager.hpp:54
void startMusic()
Starts the music.
Definition: music_information.cpp:173
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
normal music is played
Definition: music_information.hpp:75
void setTemporaryVolume(float volume)
Overwrites the current volume with a temporary value (used e.g.
Definition: music_information.cpp:370
utility class used to parse XML files
Definition: xml_node.hpp:47
bool preStart()
Return false if it should not be started, done in sfx thread.
Definition: music_information.cpp:150
bool m_music_waiting
If music is loaded but hasn&#39;t been started yet (MusicManager::startMusic() was told not to start righ...
Definition: music_information.hpp:54
float m_max_pitch
Maximum pitch for faster music.
Definition: music_information.hpp:70
void setMusicWaiting()
Sets the music to be waiting, i.e.
Definition: music_information.hpp:104
normal music fading out, faster fading in
Definition: music_information.hpp:76
Abstract interface for classes that can handle music playback.
Definition: music.hpp:29