00001 /****************************************************************************** 00002 * Wormux is a convivial mass murder game. 00003 * Copyright (C) 2001-2004 Lawrence Azzoug. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00018 ****************************************************************************** 00019 * Sound Engine 00020 *****************************************************************************/ 00021 00022 #ifndef JUKEBOX_H 00023 #define JUKEBOX_H 00024 //----------------------------------------------------------------------------- 00025 #include <SDL.h> 00026 #include <SDL_mixer.h> 00027 00028 #include <map> 00029 #include <set> 00030 #include <utility> 00031 #include "../include/base.h" 00032 //----------------------------------------------------------------------------- 00033 00034 class JukeBox 00035 { 00036 private: 00037 00038 typedef std::multimap<std::string, std::string>::value_type 00039 sound_sample; 00040 typedef std::multimap<std::string, std::string>::iterator 00041 sample_iterator; 00042 00043 std::multimap<std::string, std::string> m_soundsamples; 00044 00045 std::map<int, Mix_Chunk*> chunks; 00046 00047 struct s_m_config{ 00048 bool music; 00049 bool effects; 00050 int frequency; 00051 int channels; // (1 channel = mono, 2 = stereo, etc) 00052 } m_config; 00053 00054 bool m_init; 00055 00056 std::set<std::string> m_profiles_loaded; 00057 00058 static void EndChunk(int channel); 00059 00060 public: 00061 JukeBox(); 00062 void Init(); 00063 void End(); 00064 00065 bool UseMusic() const {return m_config.music;}; 00066 bool UseEffects() const {return m_config.effects;}; 00067 int GetFrequency() const {return m_config.frequency;}; 00068 int HowManyChannels() const {return m_config.channels;}; 00069 void Pause(); 00070 void Resume(); 00071 00072 void ActiveMusic (bool on) {m_config.music = on ;}; 00073 void ActiveEffects (bool on) {m_config.effects = on;}; 00074 00075 void SetFrequency (int frequency); 00076 void SetNumbersOfChannel(int channels); // Not used 00077 00078 void LoadXML(const std::string& profile); 00079 00085 int Play(const std::string& category, 00086 const std::string& sample, 00087 const int loop = 1); 00088 00089 int Stop(int channel); 00090 00091 int StopAll(); 00092 00093 private: 00099 int PlaySample (Mix_Chunk * sample, int loop=0); 00100 }; 00101 00102 extern JukeBox jukebox; 00103 //----------------------------------------------------------------------------- 00104 #endif