The BIG COMMIT(tm)
[supertux.git] / lib / audio / sound_manager.h
index 48a1440..b9878e4 100644 (file)
@@ -21,6 +21,7 @@
 #define SUPERTUX_SOUND_MANAGER_H
 
 #include <string>
+#include <vector>
 #include <map>
 
 #include "SDL_mixer.h"
@@ -32,25 +33,34 @@ namespace SuperTux
   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);
       /// 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);
 
@@ -64,9 +74,68 @@ namespace SuperTux
       /// 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
@@ -84,12 +153,17 @@ namespace SuperTux
 
       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*/