ManaPlus
setup_audio.cpp
Go to the documentation of this file.
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 
25 
26 #include "resources/map/map.h"
27 
28 #include "configuration.h"
29 #include "soundmanager.h"
30 
31 #include "gui/viewport.h"
32 
33 #include "gui/models/soundsmodel.h"
34 
37 #include "gui/widgets/scrollarea.h"
38 
39 #include "utils/delete2.h"
40 
41 #include "debug.h"
42 
43 Setup_Audio::Setup_Audio(const Widget2 *const widget) :
44  SetupTabScroll(widget),
45  mSoundModel(new SoundsModel),
46  mChannelsList(new SetupItemNames)
47 {
48  // TRANSLATORS: audio tab in settings
49  setName(_("Audio"));
50 
51  // Do the layout
52  LayoutHelper h(this);
53  ContainerPlacer place = h.getPlacer(0, 0);
54  place(0, 0, mScroll, 10, 10);
55 
56  // TRANSLATORS: settings option
57  new SetupItemLabel(_("Basic settings"), "", this,
59 
60  // TRANSLATORS: settings option
61  new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent",
63 
64  // TRANSLATORS: settings option
65  new SetupItemCheckBox(_("Enable music"), "",
66  "playMusic", this, "playMusicEvent",
68 
69  // TRANSLATORS: settings option
70  new SetupItemCheckBox(_("Enable game sfx"), "",
71  "playBattleSound", this, "playBattleSoundEvent",
73 
74  // TRANSLATORS: settings option
75  new SetupItemCheckBox(_("Enable gui sfx"), "",
76  "playGuiSound", this, "playGuiSoundEvent",
78 
79  // TRANSLATORS: settings option
80  new SetupItemSlider(_("Sfx volume"), "", "sfxVolume",
81  this, "sfxVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
82  150,
85 
86  // TRANSLATORS: settings option
87  new SetupItemSlider(_("Music volume"), "", "musicVolume",
88  this, "musicVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
89  150,
92 
93  // TRANSLATORS: settings option
94  new SetupItemCheckBox(_("Enable music fade out"), "",
95  "fadeoutmusic", this, "fadeoutmusicEvent",
97 
98  // TRANSLATORS: settings option
99  new SetupItemIntTextField(_("Audio frequency"), "",
100  "audioFrequency", this, "audioFrequencyEvent", 14000, 192000,
102 
103  // TRANSLATORS: audio type
104  mChannelsList->push_back(_("mono"));
105  // TRANSLATORS: audio type
106  mChannelsList->push_back(_("stereo"));
107  // TRANSLATORS: audio type
108  mChannelsList->push_back(_("surround"));
109  // TRANSLATORS: audio type
110  mChannelsList->push_back(_("surround+center+lfe"));
111  // TRANSLATORS: settings option
112  new SetupItemSlider2(_("Audio channels"), "", "audioChannels", this,
113  "audioChannels", 1, 4, 1, mChannelsList,
117 
118  // TRANSLATORS: settings option
119  new SetupItemIntTextField(_("Parallel number of sounds"), "",
120  "parallelAudioChannels", this, "parallelAudioChannelsEvent", 1, 1000,
122 
123 
124  // TRANSLATORS: settings group
125  new SetupItemLabel(_("Sound effects"), "", this,
127 
128  // TRANSLATORS: settings option
129  new SetupItemSound(_("Information dialog sound"), "",
130  "soundinfo", this, "soundinfoEvent", mSoundModel,
132 
133  // TRANSLATORS: settings option
134  new SetupItemSound(_("Request dialog sound"), "",
135  "soundrequest", this, "soundrequestEvent", mSoundModel,
137 
138  // TRANSLATORS: settings option
139  new SetupItemSound(_("Whisper message sound"), "",
140  "soundwhisper", this, "soundwhisperEvent", mSoundModel,
142 
143  // TRANSLATORS: settings option
144  new SetupItemSound(_("Guild message sound"), "",
145  "soundguild", this, "soundguildEvent", mSoundModel,
147 
148  // TRANSLATORS: settings option
149  new SetupItemSound(_("Party message sound"), "",
150  "soundparty", this, "soundpartyEvent", mSoundModel,
152 
153  // TRANSLATORS: settings option
154  new SetupItemSound(_("Clan message sound"), "",
155  "soundclan", this, "soundclanEvent", mSoundModel,
157 
158  // TRANSLATORS: settings option
159  new SetupItemSound(_("Highlight message sound"), "",
160  "soundhighlight", this, "soundhighlightEvent", mSoundModel,
162 
163  // TRANSLATORS: settings option
164  new SetupItemSound(_("Global message sound"), "",
165  "soundglobal", this, "soundglobalEvent", mSoundModel,
167 
168  // TRANSLATORS: settings option
169  new SetupItemSound(_("Error message sound"), "",
170  "sounderror", this, "sounderrorEvent", mSoundModel,
172 
173  // TRANSLATORS: settings option
174  new SetupItemSound(_("Trade request sound"), "",
175  "soundtrade", this, "soundtradeEvent", mSoundModel,
177 
178  // TRANSLATORS: settings option
179  new SetupItemSound(_("Show window sound"), "",
180  "soundshowwindow", this, "soundshowwindowEvent", mSoundModel,
182 
183  // TRANSLATORS: settings option
184  new SetupItemSound(_("Hide window sound"), "",
185  "soundhidewindow", this, "soundhidewindowEvent", mSoundModel,
187 
188  // TRANSLATORS: settings group
189  new SetupItemLabel(_("Other"), "", this,
191 
192 #ifdef USE_MUMBLE
193  // TRANSLATORS: settings option
194  new SetupItemCheckBox(_("Enable mumble voice chat"), "",
195  "enableMumble", this, "enableMumbleEvent",
197 #endif // USE_MUMBLE
198 
199  // TRANSLATORS: settings option
200  new SetupItemCheckBox(_("Download music"), "",
201  "download-music", this, "download-musicEvent",
203 
204  setDimension(Rect(0, 0, 550, 350));
205 }
206 
208 {
211 }
212 
214 {
216  if (config.getBoolValue("sound"))
217  {
218  soundManager.init();
219  if (config.getBoolValue("playMusic"))
220  {
221  if (viewport != nullptr)
222  { // in game
223  const Map *const map = viewport->getMap();
224  if (map != nullptr)
225  {
228  }
229  }
230  else
231  { // not in game
233  "loginMusic",
234  "keprohm.ogg"),
236  }
237  }
238  else
239  {
241  }
242  }
243  else
244  {
246  }
247 }
std::string getValue(const std::string &key, const std::string &deflt) const
bool getBoolValue(const std::string &key) const
ContainerPlacer getPlacer(const int x, const int y)
Definition: map.h:75
const std::string getMusicFile() const
Definition: map.cpp:835
Definition: rect.h:74
ScrollArea * mScroll
void setName(const std::string &name)
Definition: setuptab.h:68
SetupItemNames * mChannelsList
Definition: setup_audio.h:45
ListModel * mSoundModel
Definition: setup_audio.h:43
Setup_Audio(const Widget2 *const widget)
Definition: setup_audio.cpp:43
static int getMaxVolume()
Definition: soundmanager.h:104
void playMusic(const std::string &fileName, const SkipError skipError)
Map * getMap() const
Definition: viewport.h:135
void setDimension(const Rect &dimension)
Definition: widget.cpp:169
Configuration config
Configuration branding
#define new
Definition: debug_new.h:147
#define delete2(var)
Definition: delete2.h:25
const bool DoNotAlign_false
Definition: donotalign.h:30
Viewport * viewport
Definition: viewport.cpp:36
#define _(s)
Definition: gettext.h:35
const bool MainConfig_true
Definition: mainconfig.h:30
const bool OnTheFly_false
Definition: onthefly.h:30
const bool OnTheFly_true
Definition: onthefly.h:30
const bool Separator_true
Definition: separator.h:30
std::vector< std::string > SetupItemNames
Definition: setupitem.h:451
const bool SkipError_false
Definition: skiperror.h:30
const bool SkipError_true
Definition: skiperror.h:30
SoundManager soundManager