1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#ifndef SOUNDMANAGER_H |
25 |
|
|
#define SOUNDMANAGER_H |
26 |
|
|
|
27 |
|
|
#include "enums/simpletypes/skiperror.h" |
28 |
|
|
|
29 |
|
|
#include "listeners/configlistener.h" |
30 |
|
|
|
31 |
|
|
#include "localconsts.h" |
32 |
|
|
|
33 |
|
|
PRAGMA48(GCC diagnostic push) |
34 |
|
|
PRAGMA48(GCC diagnostic ignored "-Wshadow") |
35 |
|
|
#include <SDL_mixer.h> |
36 |
|
|
PRAGMA48(GCC diagnostic pop) |
37 |
|
|
|
38 |
|
|
class SDLMusic; |
39 |
|
|
|
40 |
|
|
/** SoundManager |
41 |
|
|
* |
42 |
|
|
* \ingroup CORE |
43 |
|
|
*/ |
44 |
|
|
class SoundManager final : public ConfigListener |
45 |
|
|
{ |
46 |
|
|
public: |
47 |
|
|
SoundManager(); |
48 |
|
|
|
49 |
|
|
A_DELETE_COPY(SoundManager) |
50 |
|
|
|
51 |
|
|
~SoundManager() override final; |
52 |
|
|
|
53 |
|
|
void optionChanged(const std::string &value) override final; |
54 |
|
|
|
55 |
|
|
/** |
56 |
|
|
* Installs the sound engine. |
57 |
|
|
*/ |
58 |
|
|
void init(); |
59 |
|
|
|
60 |
|
|
void testAudio(); |
61 |
|
|
|
62 |
|
|
/** |
63 |
|
|
* Removes all sound functionalities. |
64 |
|
|
*/ |
65 |
|
|
void close(); |
66 |
|
|
|
67 |
|
|
/** |
68 |
|
|
* Starts background music. |
69 |
|
|
* |
70 |
|
|
* @param fileName The name of the music file. |
71 |
|
|
*/ |
72 |
|
|
void playMusic(const std::string &fileName, |
73 |
|
|
const SkipError skipError); |
74 |
|
|
|
75 |
|
|
/** |
76 |
|
|
* Stops currently running background music track. |
77 |
|
|
*/ |
78 |
|
|
void stopMusic(); |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* Fades in background music. |
82 |
|
|
* |
83 |
|
|
* @param fileName The name of the music file. |
84 |
|
|
* @param ms Duration of fade-in effect (ms) |
85 |
|
|
*/ |
86 |
|
|
// void fadeInMusic(const std::string &fileName, const int ms = 1000); |
87 |
|
|
|
88 |
|
|
/** |
89 |
|
|
* Fades out currently running background music track. |
90 |
|
|
* |
91 |
|
|
* @param ms Duration of fade-out effect (ms) |
92 |
|
|
*/ |
93 |
|
|
void fadeOutMusic(const int ms); |
94 |
|
|
|
95 |
|
|
/** |
96 |
|
|
* Fades out a background music and play a new one. |
97 |
|
|
* |
98 |
|
|
* @param fileName The name of the music file. |
99 |
|
|
* @param ms Duration of fade-out effect (ms) |
100 |
|
|
*/ |
101 |
|
|
void fadeOutAndPlayMusic(const std::string &fileName, |
102 |
|
|
const int ms); |
103 |
|
|
|
104 |
|
|
constexpr static int getMaxVolume() A_WARN_UNUSED |
105 |
|
|
{ return MIX_MAX_VOLUME; } |
106 |
|
|
|
107 |
|
|
void setMusicVolume(const int volume); |
108 |
|
|
|
109 |
|
|
void setSfxVolume(const int volume); |
110 |
|
|
|
111 |
|
|
/** |
112 |
|
|
* Plays an item. |
113 |
|
|
* |
114 |
|
|
* @param path The resource path to the sound file. |
115 |
|
|
*/ |
116 |
|
|
void playSfx(const std::string &path, |
117 |
|
|
const int x, |
118 |
|
|
const int y) const; |
119 |
|
|
|
120 |
|
|
/** |
121 |
|
|
* Plays an item for gui. |
122 |
|
|
* |
123 |
|
|
* @param path The resource path to the sound file. |
124 |
|
|
*/ |
125 |
|
|
void playGuiSfx(const std::string &path); |
126 |
|
|
|
127 |
|
|
void playGuiSound(const std::string &name); |
128 |
|
|
|
129 |
|
|
void changeAudio(); |
130 |
|
|
|
131 |
|
|
void volumeOff() const; |
132 |
|
|
|
133 |
|
|
void volumeRestore() const; |
134 |
|
|
|
135 |
|
|
std::string getCurrentMusicFile() const noexcept2 A_WARN_UNUSED |
136 |
|
|
{ return mCurrentMusicFile; } |
137 |
|
|
|
138 |
|
|
/** |
139 |
|
|
* The sound logic. |
140 |
|
|
* Currently used to check whether the music file can be freed after |
141 |
|
|
* a fade out, and whether new music has to be played. |
142 |
|
|
*/ |
143 |
|
|
void logic(); |
144 |
|
|
|
145 |
|
|
void shutdown(); |
146 |
|
|
|
147 |
|
|
void setChannels(const int channels) const; |
148 |
|
|
|
149 |
|
|
private: |
150 |
|
|
/** Logs various info about sound device. */ |
151 |
|
|
static void info(); |
152 |
|
|
|
153 |
|
|
/** Halts and frees currently playing music. */ |
154 |
|
|
void haltMusic(); |
155 |
|
|
|
156 |
|
|
/** |
157 |
|
|
* When calling fadeOutAndPlayMusic(), |
158 |
|
|
* the music file below will then be played |
159 |
|
|
*/ |
160 |
|
|
std::string mNextMusicFile; |
161 |
|
|
|
162 |
|
|
bool mInstalled; |
163 |
|
|
|
164 |
|
|
int mSfxVolume; |
165 |
|
|
int mMusicVolume; |
166 |
|
|
|
167 |
|
|
std::string mCurrentMusicFile; |
168 |
|
|
SDLMusic *mMusic; |
169 |
|
|
int mGuiChannel; |
170 |
|
|
bool mPlayBattle; |
171 |
|
|
bool mPlayGui; |
172 |
|
|
bool mPlayMusic; |
173 |
|
|
bool mFadeoutMusic; |
174 |
|
|
bool mCacheSounds; |
175 |
|
|
}; |
176 |
|
|
|
177 |
|
|
extern SoundManager soundManager; |
178 |
|
|
|
179 |
|
|
#endif // SOUNDMANAGER_H |