GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/setup_audio.cpp Lines: 72 86 83.7 %
Date: 2018-07-14 Branches: 170 360 47.2 %

Line Branch Exec Source
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-2018  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
23
#include "gui/widgets/tabs/setup_audio.h"
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
34
#include "gui/widgets/containerplacer.h"
35
#include "gui/widgets/layouthelper.h"
36
#include "gui/widgets/scrollarea.h"
37
38
#include "utils/delete2.h"
39
40
#include "debug.h"
41
42
2
Setup_Audio::Setup_Audio(const Widget2 *const widget) :
43
    SetupTabScroll(widget),
44

2
    mSoundModel(new SoundsModel),
45
6
    mChannelsList(new SetupItemNames)
46
{
47
    // TRANSLATORS: audio tab in settings
48
8
    setName(_("Audio"));
49
50
    // Do the layout
51
4
    LayoutHelper h(this);
52
2
    ContainerPlacer place = h.getPlacer(0, 0);
53
2
    place(0, 0, mScroll, 10, 10);
54
55
    // TRANSLATORS: settings option
56
2
    new SetupItemLabel(_("Basic settings"), "", this,
57


12
        Separator_true);
58
59
    // TRANSLATORS: settings option
60
2
    new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent",
61



24
        MainConfig_true);
62
63
    // TRANSLATORS: settings option
64
2
    new SetupItemCheckBox(_("Enable music"), "",
65
        "playMusic", this, "playMusicEvent",
66



24
        MainConfig_true);
67
68
    // TRANSLATORS: settings option
69
2
    new SetupItemCheckBox(_("Enable game sfx"), "",
70
        "playBattleSound", this, "playBattleSoundEvent",
71



24
        MainConfig_true);
72
73
    // TRANSLATORS: settings option
74
2
    new SetupItemCheckBox(_("Enable gui sfx"), "",
75
        "playGuiSound", this, "playGuiSoundEvent",
76



24
        MainConfig_true);
77
78
    // TRANSLATORS: settings option
79
2
    new SetupItemSlider(_("Sfx volume"), "", "sfxVolume",
80
        this, "sfxVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
81
        150,
82
        OnTheFly_true,
83



24
        MainConfig_true);
84
85
    // TRANSLATORS: settings option
86
2
    new SetupItemSlider(_("Music volume"), "", "musicVolume",
87
        this, "musicVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
88
        150,
89
        OnTheFly_true,
90



24
        MainConfig_true);
91
92
    // TRANSLATORS: settings option
93
2
    new SetupItemCheckBox(_("Enable music fade out"), "",
94
        "fadeoutmusic", this, "fadeoutmusicEvent",
95



24
        MainConfig_true);
96
97
    // TRANSLATORS: settings option
98
2
    new SetupItemIntTextField(_("Audio frequency"), "",
99
        "audioFrequency", this, "audioFrequencyEvent", 14000, 192000,
100



24
        MainConfig_true);
101
102
    // TRANSLATORS: audio type
103
8
    mChannelsList->push_back(_("mono"));
104
    // TRANSLATORS: audio type
105
8
    mChannelsList->push_back(_("stereo"));
106
    // TRANSLATORS: audio type
107
8
    mChannelsList->push_back(_("surround"));
108
    // TRANSLATORS: audio type
109
8
    mChannelsList->push_back(_("surround+center+lfe"));
110
    // TRANSLATORS: settings option
111
2
    new SetupItemSlider2(_("Audio channels"), "", "audioChannels", this,
112
        "audioChannels", 1, 4, 1, mChannelsList,
113
        OnTheFly_false,
114
        MainConfig_true,
115



24
        DoNotAlign_false);
116
117
    // TRANSLATORS: settings option
118
2
    new SetupItemIntTextField(_("Parallel number of sounds"), "",
119
        "parallelAudioChannels", this, "parallelAudioChannelsEvent", 1, 1000,
120



24
        MainConfig_true);
121
122
123
    // TRANSLATORS: settings group
124
2
    new SetupItemLabel(_("Sound effects"), "", this,
125


12
        Separator_true);
126
127
    // TRANSLATORS: settings option
128
2
    new SetupItemSound(_("Information dialog sound"), "",
129
        "soundinfo", this, "soundinfoEvent", mSoundModel,
130



24
        150, OnTheFly_false, MainConfig_true);
131
132
    // TRANSLATORS: settings option
133
2
    new SetupItemSound(_("Request dialog sound"), "",
134
        "soundrequest", this, "soundrequestEvent", mSoundModel,
135



24
        150, OnTheFly_false, MainConfig_true);
136
137
    // TRANSLATORS: settings option
138
2
    new SetupItemSound(_("Whisper message sound"), "",
139
        "soundwhisper", this, "soundwhisperEvent", mSoundModel,
140



24
        150, OnTheFly_false, MainConfig_true);
141
142
    // TRANSLATORS: settings option
143
2
    new SetupItemSound(_("Guild message sound"), "",
144
        "soundguild", this, "soundguildEvent", mSoundModel,
145



24
        150, OnTheFly_false, MainConfig_true);
146
147
    // TRANSLATORS: settings option
148
2
    new SetupItemSound(_("Party message sound"), "",
149
        "soundparty", this, "soundpartyEvent", mSoundModel,
150



24
        150, OnTheFly_false, MainConfig_true);
151
152
    // TRANSLATORS: settings option
153
2
    new SetupItemSound(_("Clan message sound"), "",
154
        "soundclan", this, "soundclanEvent", mSoundModel,
155



24
        150, OnTheFly_false, MainConfig_true);
156
157
    // TRANSLATORS: settings option
158
2
    new SetupItemSound(_("Highlight message sound"), "",
159
        "soundhighlight", this, "soundhighlightEvent", mSoundModel,
160



24
        150, OnTheFly_false, MainConfig_true);
161
162
    // TRANSLATORS: settings option
163
2
    new SetupItemSound(_("Global message sound"), "",
164
        "soundglobal", this, "soundglobalEvent", mSoundModel,
165



24
        150, OnTheFly_false, MainConfig_true);
166
167
    // TRANSLATORS: settings option
168
2
    new SetupItemSound(_("Error message sound"), "",
169
        "sounderror", this, "sounderrorEvent", mSoundModel,
170



24
        150, OnTheFly_false, MainConfig_true);
171
172
    // TRANSLATORS: settings option
173
2
    new SetupItemSound(_("Trade request sound"), "",
174
        "soundtrade", this, "soundtradeEvent", mSoundModel,
175



24
        150, OnTheFly_false, MainConfig_true);
176
177
    // TRANSLATORS: settings option
178
2
    new SetupItemSound(_("Show window sound"), "",
179
        "soundshowwindow", this, "soundshowwindowEvent", mSoundModel,
180



24
        150, OnTheFly_false, MainConfig_true);
181
182
    // TRANSLATORS: settings option
183
2
    new SetupItemSound(_("Hide window sound"), "",
184
        "soundhidewindow", this, "soundhidewindowEvent", mSoundModel,
185



24
        150, OnTheFly_false, MainConfig_true);
186
187
    // TRANSLATORS: settings group
188
2
    new SetupItemLabel(_("Other"), "", this,
189


12
        Separator_true);
190
191
#ifdef USE_MUMBLE
192
    // TRANSLATORS: settings option
193
2
    new SetupItemCheckBox(_("Enable mumble voice chat"), "",
194
        "enableMumble", this, "enableMumbleEvent",
195



24
        MainConfig_true);
196
#endif  // USE_MUMBLE
197
198
    // TRANSLATORS: settings option
199
2
    new SetupItemCheckBox(_("Download music"), "",
200
        "download-music", this, "download-musicEvent",
201



26
        MainConfig_true);
202
203
2
    setDimension(Rect(0, 0, 550, 350));
204
2
}
205
206
6
Setup_Audio::~Setup_Audio()
207
{
208
2
    delete2(mSoundModel);
209
2
    delete2(mChannelsList);
210
4
}
211
212
void Setup_Audio::apply()
213
{
214
    SetupTabScroll::apply();
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
                {
225
                    soundManager.playMusic(map->getMusicFile(),
226
                        SkipError_false);
227
                }
228
            }
229
            else
230
            {  // not in game
231
                soundManager.playMusic(branding.getValue(
232
                    "loginMusic",
233
                    "keprohm.ogg"),
234
                    SkipError_true);
235
            }
236
        }
237
        else
238
        {
239
            soundManager.stopMusic();
240
        }
241
    }
242
    else
243
    {
244
        soundManager.close();
245
    }
246
2
}