-
Notifications
You must be signed in to change notification settings - Fork 1
/
SoundManager.h
68 lines (55 loc) · 1.37 KB
/
SoundManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef _SOUND_MANAGER_H_
#define _SOUND_MANAGER_H_
#include <string>
#include <map>
#include <memory>
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
namespace typing
{
class Sound
{
public:
Sound()
: m_chunk(NULL), m_channel(-1)
{
}
Sound(Mix_Chunk *chunk)
: m_chunk(chunk), m_channel(-1)
{
}
void Play(int loops = 0);
void FadeIn(int loops, int ms);
void FadeOut(int ms);
void Stop();
private:
Mix_Chunk *m_chunk;
int m_channel;
};
class SoundManager
{
public:
// Singleton Implementation
static SoundManager& GetSoundManager();
// Methods
Sound Add(const std::string& soundName);
Sound Get(const std::string& soundName) const;
void Play(const std::string& soundName) const;
void StopAll() const;
private:
// Ctors/Dtors
SoundManager()
{
}
// Typedefs
typedef std::map<std::string, Mix_Chunk*> SoundMap;
// Methods
Mix_Chunk * GetChunk(const std::string& soundName) const;
// Members
SoundMap m_soundMap;
// Singleton Implementation
static std::auto_ptr<SoundManager> m_singleton;
};
#define SOUNDS SoundManager::GetSoundManager()
}
#endif // _SOUND_MANAGER_H_