GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/setup_audio.cpp Lines: 72 86 83.7 %
Date: 2021-03-17 Branches: 165 350 47.1 %

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

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


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



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



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



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



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



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



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



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



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



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



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


12
        Separator_true);
127
128
    // TRANSLATORS: settings option
129
2
    new SetupItemSound(_("Information dialog sound"), "",
130
        "soundinfo", this, "soundinfoEvent", mSoundModel,
131
18
        150, OnTheFly_false, MainConfig_true);
132
133
    // TRANSLATORS: settings option
134
2
    new SetupItemSound(_("Request dialog sound"), "",
135
        "soundrequest", this, "soundrequestEvent", mSoundModel,
136



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



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



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



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



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



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



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



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



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



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



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


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



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



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