GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/setup_audio.cpp Lines: 64 76 84.2 %
Date: 2017-11-29 Branches: 155 336 46.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-2017  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
58
    // TRANSLATORS: settings option
59



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


52
    new SetupItemCheckBox(_("Enable music"), "",
63

4
        "playMusic", this, "playMusicEvent");
64
65
    // TRANSLATORS: settings option
66


52
    new SetupItemCheckBox(_("Enable game sfx"), "",
67

4
        "playBattleSound", this, "playBattleSoundEvent");
68
69
    // TRANSLATORS: settings option
70


52
    new SetupItemCheckBox(_("Enable gui sfx"), "",
71

4
        "playGuiSound", this, "playGuiSoundEvent");
72
73
    // TRANSLATORS: settings option
74


52
    new SetupItemSlider(_("Sfx volume"), "", "sfxVolume",
75
        this, "sfxVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
76
        150,
77
        OnTheFly_true,
78

4
        MainConfig_true);
79
80
    // TRANSLATORS: settings option
81


52
    new SetupItemSlider(_("Music volume"), "", "musicVolume",
82
        this, "musicVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
83
        150,
84
        OnTheFly_true,
85

4
        MainConfig_true);
86
87
    // TRANSLATORS: settings option
88


52
    new SetupItemCheckBox(_("Enable music fade out"), "",
89

4
        "fadeoutmusic", this, "fadeoutmusicEvent");
90
91
    // TRANSLATORS: settings option
92


52
    new SetupItemIntTextField(_("Audio frequency"), "",
93

4
        "audioFrequency", this, "audioFrequencyEvent", 14000, 192000);
94
95
    // TRANSLATORS: audio type
96
20
    mChannelsList->push_back(_("mono"));
97
    // TRANSLATORS: audio type
98
20
    mChannelsList->push_back(_("stereo"));
99
    // TRANSLATORS: audio type
100
20
    mChannelsList->push_back(_("surround"));
101
    // TRANSLATORS: audio type
102
20
    mChannelsList->push_back(_("surround+center+lfe"));
103
    // TRANSLATORS: settings option
104


52
    new SetupItemSlider2(_("Audio channels"), "", "audioChannels", this,
105
        "audioChannels", 1, 4, 1, mChannelsList,
106
        OnTheFly_false,
107
        MainConfig_true,
108

4
        DoNotAlign_false);
109
110
    // TRANSLATORS: settings option
111


52
    new SetupItemIntTextField(_("Parallel number of sounds"), "",
112

4
        "parallelAudioChannels", this, "parallelAudioChannelsEvent", 1, 1000);
113
114
115
    // TRANSLATORS: settings group
116


28
    new SetupItemLabel(_("Sound effects"), "", this);
117
118
    // TRANSLATORS: settings option
119


52
    new SetupItemSound(_("Information dialog sound"), "",
120

4
        "soundinfo", this, "soundinfoEvent", mSoundModel);
121
122
    // TRANSLATORS: settings option
123


52
    new SetupItemSound(_("Request dialog sound"), "",
124

4
        "soundrequest", this, "soundrequestEvent", mSoundModel);
125
126
    // TRANSLATORS: settings option
127


52
    new SetupItemSound(_("Whisper message sound"), "",
128

4
        "soundwhisper", this, "soundwhisperEvent", mSoundModel);
129
130
    // TRANSLATORS: settings option
131
36
    new SetupItemSound(_("Guild / Party message sound"), "",
132

4
        "soundguild", this, "soundguildEvent", mSoundModel);
133
134
    // TRANSLATORS: settings option
135


52
    new SetupItemSound(_("Highlight message sound"), "",
136

4
        "soundhighlight", this, "soundhighlightEvent", mSoundModel);
137
138
    // TRANSLATORS: settings option
139


36
    new SetupItemSound(_("Global message sound"), "",
140

4
        "soundglobal", this, "soundglobalEvent", mSoundModel);
141
142
    // TRANSLATORS: settings option
143


52
    new SetupItemSound(_("Error message sound"), "",
144

4
        "sounderror", this, "sounderrorEvent", mSoundModel);
145
146
    // TRANSLATORS: settings option
147


52
    new SetupItemSound(_("Trade request sound"), "",
148

4
        "soundtrade", this, "soundtradeEvent", mSoundModel);
149
150
    // TRANSLATORS: settings option
151


52
    new SetupItemSound(_("Show window sound"), "",
152

4
        "soundshowwindow", this, "soundshowwindowEvent", mSoundModel);
153
154
    // TRANSLATORS: settings option
155


52
    new SetupItemSound(_("Hide window sound"), "",
156

4
        "soundhidewindow", this, "soundhidewindowEvent", mSoundModel);
157
158
    // TRANSLATORS: settings group
159


28
    new SetupItemLabel(_("Other"), "", this);
160
161
#ifdef USE_MUMBLE
162
    // TRANSLATORS: settings option
163


52
    new SetupItemCheckBox(_("Enable mumble voice chat"), "",
164

4
        "enableMumble", this, "enableMumbleEvent");
165
#endif  // USE_MUMBLE
166
167
    // TRANSLATORS: settings option
168


52
    new SetupItemCheckBox(_("Download music"), "",
169

4
        "download-music", this, "download-musicEvent");
170
171
8
    setDimension(Rect(0, 0, 550, 350));
172
4
}
173
174
12
Setup_Audio::~Setup_Audio()
175
{
176
4
    delete2(mSoundModel);
177
4
    delete2(mChannelsList);
178
8
}
179
180
void Setup_Audio::apply()
181
{
182
    SetupTabScroll::apply();
183
    if (config.getBoolValue("sound"))
184
    {
185
        soundManager.init();
186
        if (config.getBoolValue("playMusic"))
187
        {
188
            if (viewport != nullptr)
189
            {  // in game
190
                const Map *const map = viewport->getMap();
191
                if (map != nullptr)
192
                {
193
                    soundManager.playMusic(map->getMusicFile(),
194
                        SkipError_false);
195
                }
196
            }
197
            else
198
            {  // not in game
199
                soundManager.playMusic(branding.getValue(
200
                    "loginMusic",
201
                    "keprohm.ogg"),
202
                    SkipError_true);
203
            }
204
        }
205
        else
206
        {
207
            soundManager.stopMusic();
208
        }
209
    }
210
    else
211
    {
212
        soundManager.close();
213
    }
214
4
}