GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/soundmanager.h Lines: 0 1 0.0 %
Date: 2018-07-14 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-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
#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() override final;
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);
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);
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,
116
                     const int x,
117
                     const int y) const;
118
119
        /**
120
         * Plays an item for gui.
121
         *
122
         * @param path The resource path to the sound file.
123
         */
124
        void playGuiSfx(const std::string &path);
125
126
        void playGuiSound(const std::string &name);
127
128
        void changeAudio();
129
130
        void volumeOff() const;
131
132
        void volumeRestore() const;
133
134
        std::string getCurrentMusicFile() const noexcept2 A_WARN_UNUSED
135
        { return mCurrentMusicFile; }
136
137
        /**
138
         * The sound logic.
139
         * Currently used to check whether the music file can be freed after
140
         * a fade out, and whether new music has to be played.
141
         */
142
        void logic();
143
144
        void shutdown();
145
146
        void setChannels(const int channels) const;
147
148
    private:
149
        /** Logs various info about sound device. */
150
        static void info();
151
152
        /** Halts and frees currently playing music. */
153
        void haltMusic();
154
155
        /**
156
         * When calling fadeOutAndPlayMusic(),
157
         * the music file below will then be played
158
         */
159
        std::string mNextMusicFile;
160
161
        bool mInstalled;
162
163
        int mSfxVolume;
164
        int mMusicVolume;
165
166
        std::string mCurrentMusicFile;
167
        SDLMusic *mMusic;
168
        int mGuiChannel;
169
        bool mPlayBattle;
170
        bool mPlayGui;
171
        bool mPlayMusic;
172
        bool mFadeoutMusic;
173
        bool mCacheSounds;
174
};
175
176
extern SoundManager soundManager;
177
178
#endif  // SOUNDMANAGER_H