1
/*
2
 *  The Mana World
3
 *  Copyright (C) 2004  The Mana World Development Team
4
 *
5
 *  This file is part of The Mana World.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 */
21
22
#ifndef SOUND_H
23
#define SOUND_H
24
25
#ifdef __APPLE__
26
#include <SDL_mixer/SDL_mixer.h>
27
#else
28
#include <SDL_mixer.h>
29
#endif
30
31
#include <string>
32
33
/** Sound engine
34
 *
35
 * \ingroup CORE
36
 */
37
class Sound
38
{
39
    public:
40
        Sound();
41
        ~Sound();
42
43
        /**
44
         * Installs the sound engine.
45
         */
46
        void init();
47
48
        /**
49
         * Removes all sound functionalities.
50
         */
51
        void close();
52
53
        /**
54
         * Starts background music.
55
         *
56
         * @param path The full path to the music file.
57
         */
58
        void playMusic(const std::string &path);
59
60
        /**
61
         * Stops currently running background music track.
62
         */
63
        void stopMusic();
64
65
        /**
66
         * Fades in background music.
67
         *
68
         * @param path The full path to the music file.
69
         * @param ms   Duration of fade-in effect (ms)
70
         */
71
        void fadeInMusic(const std::string &path, int ms = 2000);
72
73
        /**
74
         * Fades out currently running background music track.
75
         *
76
         * @param ms   Duration of fade-out effect (ms)
77
         */
78
        void fadeOutMusic(int ms);
79
80
        int getMaxVolume() const;
81
82
        void setMusicVolume(int volume);
83
        void setSfxVolume(int volume);
84
85
        /**
86
         * Plays an item.
87
         *
88
         * @param path The resource path to the sound file.
89
         */
90
        void playSfx(const std::string &path);
91
92
    private:
93
        /** Logs various info about sound device. */
94
        void info();
95
96
        /** Halts and frees currently playing music. */
97
        void haltMusic();
98
99
        bool mInstalled;
100
101
        int mSfxVolume;
102
        int mMusicVolume;
103
104
        std::string mCurrentMusicFile;
105
        Mix_Music *mMusic;
106
};
107
108
extern Sound sound;
109
110
#endif