1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef NUVIE_SOUND_SOUND_MANAGER_H 24 #define NUVIE_SOUND_SOUND_MANAGER_H 25 26 //priorities: 27 //todo: 28 //-sample loading partialy implemented, will do later (now is 21/01/04) 29 //-make songs fade in & out - add query/callback for end of song so that they can cycle 30 //-make samples sound from mapwindow 31 //-make samples fade in & out according to distance 32 //-try and use original .m files 33 34 #include "ultima/nuvie/sound/sound.h" 35 #include "ultima/nuvie/sound/song.h" 36 #include "ultima/nuvie/core/nuvie_defs.h" 37 #include "ultima/nuvie/conf/configuration.h" 38 #include "ultima/nuvie/files/nuvie_io_file.h" 39 #include "ultima/nuvie/sound/sfx.h" 40 #include "audio/mixer.h" 41 42 namespace Ultima { 43 namespace Nuvie { 44 45 #define SFX_PLAY_ASYNC true 46 #define SFX_PLAY_SYNC false 47 48 class SfxManager; 49 class CEmuopl; 50 51 struct SoundManagerSfx { 52 SfxIdType sfx_id; 53 Audio::SoundHandle handle; 54 } ; 55 56 class SoundManager { 57 public: 58 SoundManager(Audio::Mixer *mixer); 59 ~SoundManager(); 60 61 bool nuvieStartup(Configuration *config); 62 bool initAudio(); 63 void update_map_sfx(); //updates the active sounds 64 void update(); // at the moment this just changes songs if required 65 66 void musicPlayFrom(string group); 67 68 void musicPause(); 69 void musicPlay(); 70 void musicPlay(const char *filename, uint16 song_num = 0); 71 72 void musicStop(); // SB-X 73 Audio::SoundHandle playTownsSound(Std::string filename, uint16 sample_num); 74 bool isSoundPLaying(Audio::SoundHandle handle); 75 76 bool playSfx(uint16 sfx_id, bool async = false); is_audio_enabled()77 bool is_audio_enabled() { 78 return audio_enabled; 79 } 80 void set_audio_enabled(bool val); is_music_enabled()81 bool is_music_enabled() { 82 return music_enabled; 83 } 84 void set_music_enabled(bool val); is_speech_enabled()85 bool is_speech_enabled() { 86 return speech_enabled; 87 } 88 void set_speech_enabled(bool val); is_sfx_enabled()89 bool is_sfx_enabled() { 90 return sfx_enabled; 91 } set_sfx_enabled(bool val)92 void set_sfx_enabled(bool val) { 93 sfx_enabled = val; 94 } get_sfx_volume()95 uint8 get_sfx_volume() { 96 return sfx_volume; 97 } set_sfx_volume(uint8 val)98 void set_sfx_volume(uint8 val) { 99 sfx_volume = val; 100 } get_music_volume()101 uint8 get_music_volume() { 102 return music_volume; 103 } set_music_volume(uint8 val)104 void set_music_volume(uint8 val) { 105 music_volume = val; 106 } get_m_pCurrentSong()107 Sound *get_m_pCurrentSong() { 108 return m_pCurrentSong; 109 } 110 111 bool stop_music_on_group_change; 112 113 private: 114 bool LoadCustomSongs(string scriptname); 115 bool LoadNativeU6Songs(); 116 bool loadSong(Song *song, const char *filename); 117 bool loadSong(Song *song, const char *filename, const char *title); 118 bool groupAddSong(const char *group, Song *song); 119 120 //bool LoadObjectSamples(string sound_dir); 121 //bool LoadTileSamples(string sound_dir); 122 bool LoadSfxManager(string sfx_style); 123 124 Sound *SongExists(string name); //have we loaded this sound before? 125 Sound *SampleExists(string name); //have we loaded this sound before? 126 127 128 Sound *RequestTileSound(int id); 129 Sound *RequestObjectSound(int id); 130 Sound *RequestSong(string group); //request a song from this group 131 132 uint16 RequestObjectSfxId(uint16 obj_n); 133 134 typedef map<int, SoundCollection *> IntCollectionMap; 135 typedef map<Common::String, SoundCollection *> StringCollectionMap; 136 IntCollectionMap m_TileSampleMap; 137 IntCollectionMap m_ObjectSampleMap; 138 StringCollectionMap m_MusicMap; 139 list<Sound *> m_Songs; 140 list<Sound *> m_Samples; 141 Configuration *m_Config; 142 143 //state info: 144 string m_CurrentGroup; 145 Sound *m_pCurrentSong; 146 list<SoundManagerSfx> m_ActiveSounds; 147 bool audio_enabled; 148 bool music_enabled; 149 bool speech_enabled; 150 bool sfx_enabled; 151 152 uint8 music_volume; 153 uint8 sfx_volume; 154 155 Audio::Mixer *_mixer; 156 SfxManager *m_SfxManager; 157 158 CEmuopl *opl; 159 160 int game_type; //FIXME there's a nuvie_game_t, but almost everything uses int game_type (or gametype) 161 162 public: 163 static bool g_MusicFinished; 164 }; 165 166 } // End of namespace Nuvie 167 } // End of namespace Ultima 168 169 #endif 170