GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/soundmanager.h Lines: 0 1 0.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

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
#ifndef SOUNDMANAGER_H
24
#define SOUNDMANAGER_H
25
26
#include "enums/simpletypes/skiperror.h"
27
28
#include "listeners/configlistener.h"
29
30
#include "localconsts.h"
31
32
PRAGMA48(GCC diagnostic push)
33
PRAGMA48(GCC diagnostic ignored "-Wshadow")
34
#include <SDL_mixer.h>
35
PRAGMA48(GCC diagnostic pop)
36
37
class SDLMusic;
38
39
/** SoundManager
40
 *
41
 * \ingroup CORE
42
 */
43
class SoundManager final : public ConfigListener
44
{
45
    public:
46
        SoundManager();
47
48
        A_DELETE_COPY(SoundManager)
49
50
        ~SoundManager();
51
52
        void optionChanged(const std::string &value) override final;
53
54
        /**
55
         * Installs the sound engine.
56
         */
57
        void init();
58
59
        void testAudio();
60
61
        /**
62
         * Removes all sound functionalities.
63
         */
64
        void close();
65
66
        /**
67
         * Starts background music.
68
         *
69
         * @param fileName The name of the music file.
70
         */
71
        void playMusic(const std::string &fileName,
72
                       const SkipError skipError);
73
74
        /**
75
         * Stops currently running background music track.
76
         */
77
        void stopMusic();
78
79
        /**
80
         * Fades in background music.
81
         *
82
         * @param fileName The name of the music file.
83
         * @param ms       Duration of fade-in effect (ms)
84
         */
85
//        void fadeInMusic(const std::string &fileName, const int ms = 1000);
86
87
        /**
88
         * Fades out currently running background music track.
89
         *
90
         * @param ms   Duration of fade-out effect (ms)
91
         */
92
        void fadeOutMusic(const int ms = 1000);
93
94
        /**
95
         * Fades out a background music and play a new one.
96
         *
97
         * @param fileName The name of the music file.
98
         * @param ms       Duration of fade-out effect (ms)
99
         */
100
        void fadeOutAndPlayMusic(const std::string &fileName,
101
                                 const int ms = 1000);
102
103
        constexpr static int getMaxVolume() A_WARN_UNUSED
104
        { return MIX_MAX_VOLUME; }
105
106
        void setMusicVolume(const int volume);
107
108
        void setSfxVolume(const int volume);
109
110
        /**
111
         * Plays an item.
112
         *
113
         * @param path The resource path to the sound file.
114
         */
115
        void playSfx(const std::string &path, const int x = 0,
116
                     const int y = 0) const;
117
118
        /**
119
         * Plays an item for gui.
120
         *
121
         * @param path The resource path to the sound file.
122
         */
123
        void playGuiSfx(const std::string &path);
124
125
        void playGuiSound(const std::string &name);
126
127
        void changeAudio();
128
129
        void volumeOff() const;
130
131
        void volumeRestore() const;
132
133
        std::string getCurrentMusicFile() const noexcept2 A_WARN_UNUSED
134
        { return mCurrentMusicFile; }
135
136
        /**
137
         * The sound logic.
138
         * Currently used to check whether the music file can be freed after
139
         * a fade out, and whether new music has to be played.
140
         */
141
        void logic();
142
143
        void shutdown();
144
145
        void setChannels(const int channels) const;
146
147
    private:
148
        /** Logs various info about sound device. */
149
        static void info();
150
151
        /** Halts and frees currently playing music. */
152
        void haltMusic();
153
154
        /**
155
         * When calling fadeOutAndPlayMusic(),
156
         * the music file below will then be played
157
         */
158
        std::string mNextMusicFile;
159
160
        bool mInstalled;
161
162
        int mSfxVolume;
163
        int mMusicVolume;
164
165
        std::string mCurrentMusicFile;
166
        SDLMusic *mMusic;
167
        int mGuiChannel;
168
        bool mPlayBattle;
169
        bool mPlayGui;
170
        bool mPlayMusic;
171
        bool mFadeoutMusic;
172
        bool mCacheSounds;
173
};
174
175
extern SoundManager soundManager;
176
177
#endif  // SOUNDMANAGER_H