#define SUPERTUX_SOUND_MANAGER_H
#include <string>
+#include <vector>
#include <map>
#include "SDL_mixer.h"
class MusicRef;
class MovingObject;
+ /// enum of different internal music types
+ enum Music_Type {
+ NO_MUSIC,
+ LEVEL_MUSIC,
+ HURRYUP_MUSIC,
+ HERRING_MUSIC
+ };
+
/// Sound manager
/** This class handles all sounds that are played
*/
class SoundManager
{
public:
- SoundManager();
- ~SoundManager();
/// Play sound.
void play_sound(Mix_Chunk* sound);
void play_sound(Mix_Chunk* sound, const Vector& pos, const Vector& pos2);
/// Play sound relative to a MovingObject and a Vector.
void play_sound(Mix_Chunk* sound, const MovingObject* object, const Vector& pos);
-
+
/// Load music.
/** Is used to load the music for a MusicRef. */
MusicRef load_music(const std::string& file);
+
+ /// Load sound.
+ Mix_Chunk * load_sound(const std::string& file);
+
/// Test if a certain music file exists.
bool exists_music(const std::string& filename);
/// Enable/Disable music.
void enable_music(bool enable);
+ /// Is music enabled?
+ bool music_enabled()
+ {
+ return m_music_enabled;
+ }
+
+ /// Enable/Disable sound.
+ void enable_sound(bool enable);
+
+ /// Is sound enabled?
+ bool sound_enabled()
+ {
+ return m_sound_enabled;
+ }
+
+ /* functions handling the sound and music */
+ int open_audio(int frequency, Uint16 format, int channels, int chunksize);
+ void close_audio( void );
+
+ /// Is audio available?
+ bool audio_device_available()
+ {
+ return audio_device;
+ }
+
+ void set_audio_device_available(bool available)
+ {
+ audio_device = available;
+ }
+
+ static SoundManager* get()
+ {
+ return instance_ ? instance_ : instance_ = new SoundManager();
+ }
+ static void destroy_instance()
+ {
+ delete instance_;
+ instance_ = 0;
+ }
+
+ void add_sound(Mix_Chunk* sound, int id)
+ {
+ sounds[id] = sound;
+ }
+
+ Mix_Chunk* get_sound(int id)
+ {
+ return sounds[id];
+ }
+
private:
+ SoundManager();
+ ~SoundManager();
+
// music part
friend class MusicRef;
+ friend class Setup;
+ friend Mix_Chunk* IDToSound(int id);
+
+ static SoundManager* instance_ ;
+
+ void free_chunk(Mix_Chunk* chunk);
/// Resource for music.
/** Contains the raw music data and
void free_music(MusicResource* music);
+ /*variables for stocking the sound and music*/
+ std::map<int, Mix_Chunk*> sounds;
std::map<std::string, MusicResource> musics;
MusicResource* current_music;
- bool music_enabled;
+ bool m_music_enabled;
+ bool m_sound_enabled;
+ bool audio_device; /* != 0: available and initialized */
+
};
+ Mix_Chunk* IDToSound(int id);
+
} // namespace SuperTux
-
#endif /*SUPERTUX_SOUND_MANAGER_H*/