ScummVM API documentation
sound_manager.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_SOUND_SOUND_MANAGER_H
23 #define NUVIE_SOUND_SOUND_MANAGER_H
24 
25 //priorities:
26 //todo:
27 //-sample loading partially implemented, will do later (now is 21/01/04)
28 //-make songs fade in & out - add query/callback for end of song so that they can cycle
29 //-make samples sound from mapwindow
30 //-make samples fade in & out according to distance
31 //-try and use original .m files
32 
33 #include "mididrv_m_adlib.h"
34 #include "mididrv_m_mt32.h"
35 #include "midiparser_m.h"
36 
37 #include "ultima/nuvie/sound/sound.h"
38 #include "ultima/nuvie/sound/song.h"
39 #include "ultima/nuvie/core/nuvie_defs.h"
40 #include "ultima/nuvie/conf/configuration.h"
41 #include "ultima/nuvie/files/nuvie_io_file.h"
42 #include "ultima/nuvie/sound/sfx.h"
43 
44 #include "audio/mixer.h"
45 #include "audio/mididrv.h"
46 #include "common/mutex.h"
47 
48 namespace Ultima {
49 namespace Nuvie {
50 
51 #define SFX_PLAY_ASYNC true
52 #define SFX_PLAY_SYNC false
53 
54 class SfxManager;
55 class CEmuopl;
56 
58  SfxIdType sfx_id;
59  Audio::SoundHandle handle;
60 } ;
61 
62 class SoundManager {
63 private:
64  struct SongMT32InstrumentMapping {
65  char midiDatId;
66  const char *filename;
67  MInstrumentAssignment instrumentMapping[16];
68  };
69 
70  const static SongMT32InstrumentMapping DEFAULT_MT32_INSTRUMENT_MAPPING[12];
71 
72 public:
73  SoundManager(Audio::Mixer *mixer);
74  ~SoundManager();
75 
76  bool nuvieStartup(const Configuration *config);
77  bool initAudio();
78  void update_map_sfx(); //updates the active sounds
79  void update(); // at the moment this just changes songs if required
80 
81  void musicPlayFrom(string group);
82 
83  void musicPause();
84  void musicPlay();
85  void musicPlay(const char *filename, uint16 song_num = 0);
86 
87  void musicStop(); // SB-X
88  Audio::SoundHandle playTownsSound(const Common::Path &filename, uint16 sample_num);
89  bool isSoundPLaying(Audio::SoundHandle handle);
90 
91  bool playSfx(uint16 sfx_id, bool async = false);
92 
93  void syncSoundSettings();
94 
95  bool is_audio_enabled() {
96  return audio_enabled;
97  }
98  void set_audio_enabled(bool val);
99  bool is_music_enabled() {
100  return music_enabled;
101  }
102  void set_music_enabled(bool val);
103  bool is_speech_enabled() {
104  return speech_enabled;
105  }
106  void set_speech_enabled(bool val);
107  bool is_sfx_enabled() {
108  return sfx_enabled;
109  }
110  void set_sfx_enabled(bool val) {
111  sfx_enabled = val;
112  }
113  uint8 get_sfx_volume() {
114  return sfx_volume;
115  }
116  void set_sfx_volume(uint8 val) {
117  sfx_volume = val;
118  }
119  uint8 get_music_volume() {
120  return music_volume;
121  }
122  void set_music_volume(uint8 val) {
123  music_volume = val;
124  }
125  Sound *get_m_pCurrentSong() {
126  return m_pCurrentSong;
127  }
128 
129  bool stop_music_on_group_change;
130 
131 private:
132  bool LoadCustomSongs(const Common::Path &scriptname);
133  bool LoadNativeU6Songs();
134  bool loadSong(Song *song, const Common::Path &filename, const char *fileId);
135  bool loadSong(Song *song, const Common::Path &filename, const char *fileId, const char *title);
136  bool groupAddSong(const char *group, Song *song);
137 
138  //bool LoadObjectSamples(string sound_dir);
139  //bool LoadTileSamples(string sound_dir);
140  bool LoadSfxManager(string sfx_style);
141 
142  Sound *SongExists(const string &name); //have we loaded this sound before?
143  Sound *SampleExists(const string &name); //have we loaded this sound before?
144 
145 
146  Sound *RequestTileSound(int id);
147  Sound *RequestObjectSound(int id);
148  Sound *RequestSong(const string &group); //request a song from this group
149 
150  uint16 RequestObjectSfxId(uint16 obj_n);
151 
154  IntCollectionMap m_TileSampleMap;
155  IntCollectionMap m_ObjectSampleMap;
156  StringCollectionMap m_MusicMap;
157  list<Sound *> m_Songs;
158  list<Sound *> m_Samples;
159  const Configuration *m_Config;
160 
161  //state info:
162  string m_CurrentGroup;
163  Sound *m_pCurrentSong;
164  list<SoundManagerSfx> m_ActiveSounds;
165  bool audio_enabled;
166  bool music_enabled;
167  bool speech_enabled;
168  bool sfx_enabled;
169 
170  uint8 music_volume;
171  uint8 sfx_volume;
172 
173  Audio::Mixer *_mixer;
174  SfxManager *m_SfxManager;
175 
176  CEmuopl *opl;
177 
178  MidiDriver_Multisource *_midiDriver;
179  MidiDriver_M_MT32 *_mt32MidiDriver;
180  MidiParser_M *_midiParser;
181  MusicType _deviceType;
182  byte *_musicData;
183  const SongMT32InstrumentMapping *_mt32InstrumentMapping;
184  Common::Mutex _musicMutex;
185 
186  int game_type; //FIXME there's a nuvie_game_t, but almost everything uses int game_type (or gametype)
187 
188 public:
189  static bool g_MusicFinished;
190 };
191 
192 } // End of namespace Nuvie
193 } // End of namespace Ultima
194 
195 #endif
Definition: mididrv_m_mt32.h:32
Definition: configuration.h:61
Definition: mididrv_ms.h:86
Definition: list.h:39
MusicType
Definition: mididrv.h:44
Definition: path.h:52
Definition: midiparser_m.h:46
Definition: sfx_manager.h:33
Definition: mididrv_m_mt32.h:45
Definition: detection.h:27
Definition: mixer.h:49
Definition: mixer.h:59
Definition: mutex.h:67
Definition: sound_manager.h:62
Definition: sound.h:36
Definition: sound_manager.h:57
Definition: emu_opl.h:31
Definition: song.h:30