1 // $Id: sound_manager.h 2353 2005-04-06 23:00:16Z matzebraun $
3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #ifndef SUPERTUX_SOUND_MANAGER_H
20 #define SUPERTUX_SOUND_MANAGER_H
26 #include "SDL_mixer.h"
27 #include "math/vector.h"
33 * This class handles all sounds that are played
42 void play_sound(const std::string& sound);
44 /// Play sound looping, return channel number - basti_
45 int play_sound(const std::string& sound,int loops);
47 /// Play sound relative to two Vectors.
48 void play_sound(const std::string& sound, const Vector& pos,
50 /// Play sound relative to a MovingObject and a Vector.
51 void play_sound(const std::string& sound, const MovingObject* object,
54 /// register an effect to a channel - basti_
55 void register_effect(int channel,Mix_EffectFunc_t f,Mix_EffectDone_t d,
59 static void volume_adjust(int,void *,int,void *);
62 * Is used to load the music for a MusicRef.
64 MusicRef load_music(const std::string& file);
67 * If the sound isn't loaded yet try to load it.
68 * Returns an existing instance of the sound, loads a new one and returns that
69 * or returns 0 if loading failed.
71 Mix_Chunk* preload_sound(const std::string& name);
73 /// Test if a certain music file exists.
74 bool exists_music(const std::string& filename);
77 * @param loops: Defaults to -1, which means endless loops.
79 void play_music(const MusicRef& music, int loops = -1);
84 /// Enable/Disable music.
85 void enable_music(bool enable);
90 return m_music_enabled;
93 /// Enable/Disable sound.
94 void enable_sound(bool enable);
99 return m_sound_enabled;
102 /// Is audio available?
103 bool audio_device_available()
108 void set_audio_device_available(bool available)
110 audio_device = available;
114 friend class MusicRef;
117 /// Resource for music.
118 /** Contains the raw music data and
119 information for music reference
126 SoundManager* manager;
131 void free_music(MusicResource* music);
133 typedef std::map<std::string, Mix_Chunk*> Sounds;
136 typedef std::map<std::string, MusicResource> Musics;
139 MusicResource* current_music;
140 bool m_music_enabled;
141 bool m_sound_enabled;
142 bool audio_device; /* true: available and initialized */
145 #endif /*SUPERTUX_SOUND_MANAGER_H*/