X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Faudio%2Fsound_manager.h;h=9eece9c8327775458ce778771d2ba202bdb2257e;hb=a5e66c8aec9b24595006c52499c926807cc7118b;hp=1f615604a9ecb7f9afe9e0e86179bfde73e0af6c;hpb=450c450755e68527fd35b17242c71bffff951a6c;p=supertux.git diff --git a/lib/audio/sound_manager.h b/lib/audio/sound_manager.h index 1f615604a..9eece9c83 100644 --- a/lib/audio/sound_manager.h +++ b/lib/audio/sound_manager.h @@ -21,70 +21,149 @@ #define SUPERTUX_SOUND_MANAGER_H #include +#include #include #include "SDL_mixer.h" #include "math/vector.h" -class MusicRef; -class MovingObject; - -/// Sound manager -/** This class handles all sounds that are played - */ -class SoundManager -{ -public: - SoundManager(); - ~SoundManager(); - - /// Play sound. - void play_sound(Mix_Chunk* sound); - /// Play sound relative to two Vectors. - 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); - /// Test if a certain music file exists. - bool exists_music(const std::string& filename); - - /// Play music. - /** @Param loops: Defaults to -1, which means endless loops. */ - void play_music(const MusicRef& music, int loops = -1); - - /// Halt music. - void halt_music(); - - /// Enable/Disable music. - void enable_music(bool enable); - -private: - // music part - friend class MusicRef; - - /// Resource for music. - /** Contains the raw music data and - informations for music reference - counting. */ - class MusicResource +namespace SuperTux { - public: - ~MusicResource(); - SoundManager* manager; - Mix_Music* music; - int refcount; + class MusicRef; + class MovingObject; + + /// enum of different internal music types + enum Music_Type { + NO_MUSIC, + LEVEL_MUSIC, + HURRYUP_MUSIC, + HERRING_MUSIC }; - void free_music(MusicResource* music); + /// Sound manager + /** This class handles all sounds that are played + */ + class SoundManager + { + public: + /// Play sound. + void play_sound(Mix_Chunk* sound); + /// Play sound relative to two Vectors. + 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); + + /// Play music. + /** @param loops: Defaults to -1, which means endless loops. */ + void play_music(const MusicRef& music, int loops = -1); + + /// Halt music. + void halt_music(); + + /// 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 + information for music reference + counting. */ + class MusicResource + { + public: + ~MusicResource(); + + SoundManager* manager; + Mix_Music* music; + int refcount; + }; + + void free_music(MusicResource* music); - std::map musics; - MusicResource* current_music; - bool music_enabled; -}; + /*variables for stocking the sound and music*/ + std::map sounds; + std::map musics; + MusicResource* current_music; + 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*/