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  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
24 
25 #include "resources/map/map.h"
26 
27 #include "configuration.h"
28 #include "soundmanager.h"
29 
30 #include "gui/viewport.h"
31 
32 #include "gui/models/soundsmodel.h"
33 
36 #include "gui/widgets/scrollarea.h"
37 
38 #include "utils/delete2.h"
39 
40 #include "debug.h"
41 
42 Setup_Audio::Setup_Audio(const Widget2 *const widget) :
43  SetupTabScroll(widget),
44  mSoundModel(new SoundsModel),
45  mChannelsList(new SetupItemNames)
46 {
47  // TRANSLATORS: audio tab in settings
48  setName(_("Audio"));
49 
50  // Do the layout
51  LayoutHelper h(this);
53  place(0, 0, mScroll, 10, 10);
54 
55  // TRANSLATORS: settings option
56  new SetupItemLabel(_("Basic settings"), "", this,
58 
59  // TRANSLATORS: settings option
60  new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent",
62 
63  // TRANSLATORS: settings option
64  new SetupItemCheckBox(_("Enable music"), "",
65  "playMusic", this, "playMusicEvent",
67 
68  // TRANSLATORS: settings option
69  new SetupItemCheckBox(_("Enable game sfx"), "",
70  "playBattleSound", this, "playBattleSoundEvent",
72 
73  // TRANSLATORS: settings option
74  new SetupItemCheckBox(_("Enable gui sfx"), "",
75  "playGuiSound", this, "playGuiSoundEvent",
77 
78  // TRANSLATORS: settings option
79  new SetupItemSlider(_("Sfx volume"), "", "sfxVolume",
80  this, "sfxVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
81  150,
84 
85  // TRANSLATORS: settings option
86  new SetupItemSlider(_("Music volume"), "", "musicVolume",
87  this, "musicVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
88  150,
91 
92  // TRANSLATORS: settings option
93  new SetupItemCheckBox(_("Enable music fade out"), "",
94  "fadeoutmusic", this, "fadeoutmusicEvent",
96 
97  // TRANSLATORS: settings option
98  new SetupItemIntTextField(_("Audio frequency"), "",
99  "audioFrequency", this, "audioFrequencyEvent", 14000, 192000,
101 
102  // TRANSLATORS: audio type
103  mChannelsList->push_back(_("mono"));
104  // TRANSLATORS: audio type
105  mChannelsList->push_back(_("stereo"));
106  // TRANSLATORS: audio type
107  mChannelsList->push_back(_("surround"));
108  // TRANSLATORS: audio type
109  mChannelsList->push_back(_("surround+center+lfe"));
110  // TRANSLATORS: settings option
111  new SetupItemSlider2(_("Audio channels"), "", "audioChannels", this,
112  "audioChannels", 1, 4, 1, mChannelsList,
116 
117  // TRANSLATORS: settings option
118  new SetupItemIntTextField(_("Parallel number of sounds"), "",
119  "parallelAudioChannels", this, "parallelAudioChannelsEvent", 1, 1000,
121 
122 
123  // TRANSLATORS: settings group
124  new SetupItemLabel(_("Sound effects"), "", this,
126 
127  // TRANSLATORS: settings option
128  new SetupItemSound(_("Information dialog sound"), "",
129  "soundinfo", this, "soundinfoEvent", mSoundModel,
131 
132  // TRANSLATORS: settings option
133  new SetupItemSound(_("Request dialog sound"), "",
134  "soundrequest", this, "soundrequestEvent", mSoundModel,
136 
137  // TRANSLATORS: settings option
138  new SetupItemSound(_("Whisper message sound"), "",
139  "soundwhisper", this, "soundwhisperEvent", mSoundModel,
141 
142  // TRANSLATORS: settings option
143  new SetupItemSound(_("Guild message sound"), "",
144  "soundguild", this, "soundguildEvent", mSoundModel,
146 
147  // TRANSLATORS: settings option
148  new SetupItemSound(_("Party message sound"), "",
149  "soundparty", this, "soundpartyEvent", mSoundModel,
151 
152  // TRANSLATORS: settings option
153  new SetupItemSound(_("Clan message sound"), "",
154  "soundclan", this, "soundclanEvent", mSoundModel,
156 
157  // TRANSLATORS: settings option
158  new SetupItemSound(_("Highlight message sound"), "",
159  "soundhighlight", this, "soundhighlightEvent", mSoundModel,
161 
162  // TRANSLATORS: settings option
163  new SetupItemSound(_("Global message sound"), "",
164  "soundglobal", this, "soundglobalEvent", mSoundModel,
166 
167  // TRANSLATORS: settings option
168  new SetupItemSound(_("Error message sound"), "",
169  "sounderror", this, "sounderrorEvent", mSoundModel,
171 
172  // TRANSLATORS: settings option
173  new SetupItemSound(_("Trade request sound"), "",
174  "soundtrade", this, "soundtradeEvent", mSoundModel,
176 
177  // TRANSLATORS: settings option
178  new SetupItemSound(_("Show window sound"), "",
179  "soundshowwindow", this, "soundshowwindowEvent", mSoundModel,
181 
182  // TRANSLATORS: settings option
183  new SetupItemSound(_("Hide window sound"), "",
184  "soundhidewindow", this, "soundhidewindowEvent", mSoundModel,
186 
187  // TRANSLATORS: settings group
188  new SetupItemLabel(_("Other"), "", this,
190 
191 #ifdef USE_MUMBLE
192  // TRANSLATORS: settings option
193  new SetupItemCheckBox(_("Enable mumble voice chat"), "",
194  "enableMumble", this, "enableMumbleEvent",
196 #endif // USE_MUMBLE
197 
198  // TRANSLATORS: settings option
199  new SetupItemCheckBox(_("Download music"), "",
200  "download-music", this, "download-musicEvent",
202 
203  setDimension(Rect(0, 0, 550, 350));
204 }
205 
207 {
210 }
211 
213 {
215  if (config.getBoolValue("sound"))
216  {
217  soundManager.init();
218  if (config.getBoolValue("playMusic"))
219  {
220  if (viewport != nullptr)
221  { // in game
222  const Map *const map = viewport->getMap();
223  if (map != nullptr)
224  {
227  }
228  }
229  else
230  { // not in game
232  "loginMusic",
233  "keprohm.ogg"),
235  }
236  }
237  else
238  {
240  }
241  }
242  else
243  {
245  }
246 }
ConfigurationObject::getValue
std::string getValue(const std::string &key, const std::string &deflt) const
Definition: configuration.cpp:268
SoundManager::stopMusic
void stopMusic()
Definition: soundmanager.cpp:373
SetupItemIntTextField
Definition: setupitem.h:240
SkipError_true
const bool SkipError_true
Definition: skiperror.h:29
Setup_Audio::apply
void apply()
Definition: setup_audio.cpp:212
Widget::setDimension
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
SoundManager::init
void init()
Definition: soundmanager.cpp:126
SetupTabScroll::apply
void apply()
Definition: setuptabscroll.cpp:106
OnTheFly_true
const bool OnTheFly_true
Definition: onthefly.h:29
Widget2
Definition: widget2.h:35
delete2.h
containerplacer.h
SetupTab::setName
void setName(const std::string &name)
Definition: setuptab.h:67
SkipError_false
const bool SkipError_false
Definition: skiperror.h:29
Setup_Audio::mSoundModel
ListModel * mSoundModel
Definition: setup_audio.h:42
Separator_true
const bool Separator_true
Definition: separator.h:29
SoundsModel
Definition: soundsmodel.h:33
delete2
#define delete2(var)
Definition: delete2.h:24
SetupItemCheckBox
Definition: setupitem.h:153
SetupTabScroll::mScroll
ScrollArea * mScroll
Definition: setuptabscroll.h:75
setup_audio.h
ContainerPlacer
Definition: containerplacer.h:35
soundsmodel.h
LayoutHelper
Definition: layouthelper.h:38
LayoutHelper::getPlacer
ContainerPlacer getPlacer(const int x, const int y)
Definition: layouthelper.cpp:59
SoundManager::playMusic
void playMusic(const std::string &fileName, const SkipError skipError)
Definition: soundmanager.cpp:351
branding
Configuration branding
Definition: configuration.cpp:54
SetupItemSlider
Definition: setupitem.h:395
SetupItemSound
Definition: setupitem.h:564
SoundManager::close
void close()
Definition: soundmanager.cpp:530
SetupTabScroll
Definition: setuptabscroll.h:32
soundmanager.h
SoundManager::getMaxVolume
static int getMaxVolume()
Definition: soundmanager.h:103
Setup_Audio::~Setup_Audio
~Setup_Audio()
Definition: setup_audio.cpp:206
viewport
Viewport * viewport
Definition: viewport.cpp:35
layouthelper.h
config
Configuration config
Definition: configuration.cpp:51
Viewport::getMap
Map * getMap() const
Definition: viewport.h:134
Setup_Audio::Setup_Audio
Setup_Audio(const Widget2 *const widget)
Definition: setup_audio.cpp:42
Rect
Definition: rect.h:72
OnTheFly_false
const bool OnTheFly_false
Definition: onthefly.h:29
SetupItemSlider2
Definition: setupitem.h:454
MainConfig_true
const bool MainConfig_true
Definition: mainconfig.h:29
configuration.h
Map
Definition: map.h:71
Window::place
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1383
new
#define new
Definition: debug_new.h:147
Setup_Audio::mChannelsList
SetupItemNames * mChannelsList
Definition: setup_audio.h:44
SetupItemNames
std::vector< std::string > SetupItemNames
Definition: setupitem.h:450
scrollarea.h
Map::getMusicFile
const std::string getMusicFile() const
Definition: map.cpp:834
_
#define _(s)
Definition: gettext.h:34
SetupItemLabel
Definition: setupitem.h:284
soundManager
SoundManager soundManager
Definition: soundmanager.cpp:54
debug.h
DoNotAlign_false
const bool DoNotAlign_false
Definition: donotalign.h:29
Configuration::getBoolValue
bool getBoolValue(const std::string &key) const
Definition: configuration.cpp:596