1 //============================================================================== 2 // This program is free software; you can redistribute it and/or modify 3 // it under the terms of the GNU General Public License as published by 4 // the Free Software Foundation; either version 2 of the License, or 5 // (at your option) any later version. 6 // 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU Library General Public License for more details. 11 // 12 // You should have received a copy of the GNU General Public License 13 // along with this program; if not, write to the Free Software 14 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 //============================================================================== 16 17 //============================================================================== 18 // File: cMixer.hpp 19 // Project: Shooting Star 20 // Author: Jarmo Hekkanen <jarski@2ndpoint.fi> 21 // Copyrights (c) 2003 2ndPoint ry (www.2ndpoint.fi) 22 //------------------------------------------------------------------------------ 23 // Revision history 24 //============================================================================== 25 #ifndef cMixer_hpp 26 #define cMixer_hpp 27 //============================================================================== 28 // Includes 29 #include <map> 30 #include <vector> 31 #include <string> 32 #include <SDL_mixer.h> 33 //------------------------------------------------------------------------------ 34 // Namespaces 35 using namespace std; 36 namespace ShootingStar { 37 //------------------------------------------------------------------------------ 38 // Forward declarations 39 //============================================================================== 40 41 //! Singleton sound mixer 42 class cMixer 43 { 44 // Constructor & Destructor 45 private: 46 //! Constructor 47 cMixer (void); 48 public: 49 //! Destructor 50 ~cMixer (void); 51 52 // Public methods 53 public: 54 //! Return singleton GetInstance(void)55 static cMixer &GetInstance (void) 56 { 57 static cMixer singleton; 58 return singleton; 59 }; 60 61 //! Load sound 62 Uint32 LoadSound (string filename); 63 //! Free all sounds 64 void FreeAllSounds (void); 65 //! Free music 66 void FreeMusic (void); 67 68 //! Play sound 69 int PlaySound (Uint32 sound, int loop = 0); 70 //! Stop sound 71 void StopSound (int channel,int delay=0 ); 72 //! Stop all sounds 73 void StopAllSounds (void); 74 //! Play music 75 void PlayMusic (string filename); 76 void FadeMusic (void); 77 78 void SetMusicVolume (int volume); 79 int GetMusicVolume (void); 80 81 void SetSoundsVolume (int volume); 82 int GetSoundsVolume (void); 83 SetDataDir(const string & dir)84 void SetDataDir (const string &dir) { mDataDir = dir; }; GetDataDir(void) const85 const string &GetDataDir (void) const { return mDataDir; }; 86 EnableSounds(bool value=true)87 void EnableSounds (bool value = true) { mSoundsEnabled = value; }; EnableMusic(bool value=true)88 void EnableMusic (bool value = true) { mMusicEnabled = value; }; 89 // Member variables 90 private: 91 bool mInitialized; 92 bool mSoundsEnabled; 93 bool mMusicEnabled; 94 string mDataDir; 95 map<string, Uint32> mSoundIDs; 96 vector<Mix_Chunk*> mSounds; 97 Mix_Music *mpMusic; 98 }; 99 100 //============================================================================== 101 } // End of the ShootingStar namespace 102 #endif // cMixer_hpp 103 //------------------------------------------------------------------------------ 104 // EOF 105 //============================================================================== 106