GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/setup_audio.cpp Lines: 72 84 85.7 %
Date: 2018-06-18 21:15:20 Branches: 170 366 46.4 %

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
4
Setup_Audio::Setup_Audio(const Widget2 *const widget) :
43
    SetupTabScroll(widget),
44

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

28
    new SetupItemLabel(_("Basic settings"), "", this,
57

4
        Separator_true);
58
59
    // TRANSLATORS: settings option
60


52
    new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent",
61

4
        MainConfig_true);
62
63
    // TRANSLATORS: settings option
64


52
    new SetupItemCheckBox(_("Enable music"), "",
65
        "playMusic", this, "playMusicEvent",
66

4
        MainConfig_true);
67
68
    // TRANSLATORS: settings option
69


52
    new SetupItemCheckBox(_("Enable game sfx"), "",
70
        "playBattleSound", this, "playBattleSoundEvent",
71

4
        MainConfig_true);
72
73
    // TRANSLATORS: settings option
74


52
    new SetupItemCheckBox(_("Enable gui sfx"), "",
75
        "playGuiSound", this, "playGuiSoundEvent",
76

4
        MainConfig_true);
77
78
    // TRANSLATORS: settings option
79


52
    new SetupItemSlider(_("Sfx volume"), "", "sfxVolume",
80
        this, "sfxVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
81
        150,
82
        OnTheFly_true,
83

4
        MainConfig_true);
84
85
    // TRANSLATORS: settings option
86


52
    new SetupItemSlider(_("Music volume"), "", "musicVolume",
87
        this, "musicVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
88
        150,
89
        OnTheFly_true,
90

4
        MainConfig_true);
91
92
    // TRANSLATORS: settings option
93


52
    new SetupItemCheckBox(_("Enable music fade out"), "",
94
        "fadeoutmusic", this, "fadeoutmusicEvent",
95

4
        MainConfig_true);
96
97
    // TRANSLATORS: settings option
98


52
    new SetupItemIntTextField(_("Audio frequency"), "",
99
        "audioFrequency", this, "audioFrequencyEvent", 14000, 192000,
100

4
        MainConfig_true);
101
102
    // TRANSLATORS: audio type
103
20
    mChannelsList->push_back(_("mono"));
104
    // TRANSLATORS: audio type
105
20
    mChannelsList->push_back(_("stereo"));
106
    // TRANSLATORS: audio type
107
20
    mChannelsList->push_back(_("surround"));
108
    // TRANSLATORS: audio type
109
20
    mChannelsList->push_back(_("surround+center+lfe"));
110
    // TRANSLATORS: settings option
111


52
    new SetupItemSlider2(_("Audio channels"), "", "audioChannels", this,
112
        "audioChannels", 1, 4, 1, mChannelsList,
113
        OnTheFly_false,
114
        MainConfig_true,
115

4
        DoNotAlign_false);
116
117
    // TRANSLATORS: settings option
118


52
    new SetupItemIntTextField(_("Parallel number of sounds"), "",
119
        "parallelAudioChannels", this, "parallelAudioChannelsEvent", 1, 1000,
120

4
        MainConfig_true);
121
122
123
    // TRANSLATORS: settings group
124

28
    new SetupItemLabel(_("Sound effects"), "", this,
125

4
        Separator_true);
126
127
    // TRANSLATORS: settings option
128


52
    new SetupItemSound(_("Information dialog sound"), "",
129
        "soundinfo", this, "soundinfoEvent", mSoundModel,
130

4
        150, OnTheFly_false, MainConfig_true);
131
132
    // TRANSLATORS: settings option
133


52
    new SetupItemSound(_("Request dialog sound"), "",
134
        "soundrequest", this, "soundrequestEvent", mSoundModel,
135

4
        150, OnTheFly_false, MainConfig_true);
136
137
    // TRANSLATORS: settings option
138


52
    new SetupItemSound(_("Whisper message sound"), "",
139
        "soundwhisper", this, "soundwhisperEvent", mSoundModel,
140

4
        150, OnTheFly_false, MainConfig_true);
141
142
    // TRANSLATORS: settings option
143


52
    new SetupItemSound(_("Guild message sound"), "",
144
        "soundguild", this, "soundguildEvent", mSoundModel,
145

4
        150, OnTheFly_false, MainConfig_true);
146
147
    // TRANSLATORS: settings option
148


52
    new SetupItemSound(_("Party message sound"), "",
149
        "soundparty", this, "soundpartyEvent", mSoundModel,
150

4
        150, OnTheFly_false, MainConfig_true);
151
152
    // TRANSLATORS: settings option
153


52
    new SetupItemSound(_("Clan message sound"), "",
154
        "soundclan", this, "soundclanEvent", mSoundModel,
155

4
        150, OnTheFly_false, MainConfig_true);
156
157
    // TRANSLATORS: settings option
158


52
    new SetupItemSound(_("Highlight message sound"), "",
159
        "soundhighlight", this, "soundhighlightEvent", mSoundModel,
160

4
        150, OnTheFly_false, MainConfig_true);
161
162
    // TRANSLATORS: settings option
163


52
    new SetupItemSound(_("Global message sound"), "",
164
        "soundglobal", this, "soundglobalEvent", mSoundModel,
165

4
        150, OnTheFly_false, MainConfig_true);
166
167
    // TRANSLATORS: settings option
168


52
    new SetupItemSound(_("Error message sound"), "",
169
        "sounderror", this, "sounderrorEvent", mSoundModel,
170

4
        150, OnTheFly_false, MainConfig_true);
171
172
    // TRANSLATORS: settings option
173


52
    new SetupItemSound(_("Trade request sound"), "",
174
        "soundtrade", this, "soundtradeEvent", mSoundModel,
175

4
        150, OnTheFly_false, MainConfig_true);
176
177
    // TRANSLATORS: settings option
178


52
    new SetupItemSound(_("Show window sound"), "",
179
        "soundshowwindow", this, "soundshowwindowEvent", mSoundModel,
180

4
        150, OnTheFly_false, MainConfig_true);
181
182
    // TRANSLATORS: settings option
183


52
    new SetupItemSound(_("Hide window sound"), "",
184
        "soundhidewindow", this, "soundhidewindowEvent", mSoundModel,
185

4
        150, OnTheFly_false, MainConfig_true);
186
187
    // TRANSLATORS: settings group
188

28
    new SetupItemLabel(_("Other"), "", this,
189

4
        Separator_true);
190
191
#ifdef USE_MUMBLE
192
    // TRANSLATORS: settings option
193


52
    new SetupItemCheckBox(_("Enable mumble voice chat"), "",
194
        "enableMumble", this, "enableMumbleEvent",
195

4
        MainConfig_true);
196
#endif  // USE_MUMBLE
197
198
    // TRANSLATORS: settings option
199


52
    new SetupItemCheckBox(_("Download music"), "",
200
        "download-music", this, "download-musicEvent",
201

4
        MainConfig_true);
202
203
8
    setDimension(Rect(0, 0, 550, 350));
204
4
}
205
206
12
Setup_Audio::~Setup_Audio()
207
{
208
4
    delete2(mSoundModel);
209
4
    delete2(mChannelsList);
210
8
}
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
4
}