SuperTuxKart
Loading...
Searching...
No Matches
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>
31using irr::core::stringw;
32
33class Music;
34class XMLNode;
35
43{
44private:
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
71 static const int LOOP_FOREVER=-1;
72 mutable std::mutex m_music_mutex;
73 Music *m_normal_music,
74 *m_fast_music;
78 SOUND_FAST}
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.
89private:
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 // ------------------------------------------------------------------------
105 // ------------------------------------------------------------------------
106
107public:
108 LEAK_CHECK()
109
110#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
111#pragma warning(disable:4290)
112#endif
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
Wrapper around an instance of the Music interface Adds information like composer, song title,...
Definition: music_information.hpp:43
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
@ SOUND_FASTER
change pitch of normal music
Definition: music_information.hpp:77
@ SOUND_NORMAL
normal music is played
Definition: music_information.hpp:75
@ SOUND_FADING
normal music fading out, faster fading in
Definition: music_information.hpp:76
void startMusic()
Starts the music.
Definition: music_information.cpp:170
const stringw & getComposer() const
Returns the composer of the music.
Definition: music_information.hpp:120
void setMusicWaiting()
Sets the music to be waiting, i.e.
Definition: music_information.hpp:104
bool m_music_waiting
If music is loaded but hasn't been started yet (MusicManager::startMusic() was told not to start righ...
Definition: music_information.hpp:54
bool preStart()
Return false if it should not be started, done in sfx thread.
Definition: music_information.cpp:147
const std::string & getNormalFilename() const
Returns the filename of the normal speed music.
Definition: music_information.hpp:126
float m_max_pitch
Maximum pitch for faster music.
Definition: music_information.hpp:70
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
float m_faster_time
Either time for fading faster music in, or time to change pitch.
Definition: music_information.hpp:68
const stringw & getTitle() const
Returns the title of the music.
Definition: music_information.hpp:123
const std::string & getFastFilename() const
If available, returns the file name of the faster/last-lap music.
Definition: music_information.hpp:129
void setTemporaryVolume(float volume)
Overwrites the current volume with a temporary value (used e.g.
Definition: music_information.cpp:367
enum MusicInformation::@2 m_mode
< playing faster music or max pitch reached
Abstract interface for classes that can handle music playback.
Definition: music.hpp:30
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Manager of all sound effects.
Definition: sfx_manager.hpp:55
utility class used to parse XML files
Definition: xml_node.hpp:48