16 #ifdef HAVE_RAD_MSS //[ 32 GlobalMilesManager *GlobalMilesManager::_global_ptr;
38 GlobalMilesManager() :
39 _managers_lock(
"GlobalMilesManager::_managers_lock"),
40 _samples_lock(
"GlobalMilesManager::_samples_lock"),
41 _sequences_lock(
"GlobalMilesManager::_sequences_lock")
54 void GlobalMilesManager::
55 add_manager(MilesAudioManager *manager) {
57 _managers.insert(manager);
67 void GlobalMilesManager::
68 remove_manager(MilesAudioManager *manager) {
70 _managers.erase(manager);
71 if (_managers.empty() && _is_open) {
79 void GlobalMilesManager::
82 Managers::iterator mi;
83 for (mi = _managers.begin(); mi != _managers.end(); ++mi) {
99 bool GlobalMilesManager::
100 get_sample(HSAMPLE &sample,
size_t &index, MilesAudioSample *sound) {
103 for (
size_t i = 0; i < _samples.size(); ++i) {
104 SampleData &smp = _samples[i];
105 if (AIL_sample_status(smp._sample) == SMP_DONE) {
106 if (smp._sound !=
nullptr) {
108 smp._sound->internal_stop();
111 sample = smp._sample;
118 sample = AIL_allocate_sample_handle(_digital_driver);
123 AIL_init_sample(sample, DIG_F_STEREO_16, 0);
124 index = _samples.size();
128 smp._sample = sample;
129 _samples.push_back(smp);
136 void GlobalMilesManager::
137 release_sample(
size_t index, MilesAudioSample *sound) {
139 nassertv(index < _samples.size());
141 SampleData &smp = _samples[index];
142 if (smp._sound == sound) {
143 smp._sound =
nullptr;
158 bool GlobalMilesManager::
159 get_sequence(HSEQUENCE &sequence,
size_t &index, MilesAudioSequence *sound) {
162 for (
size_t i = 0; i < _sequences.size(); ++i) {
163 SequenceData &seq = _sequences[i];
164 if (AIL_sequence_status(seq._sequence) == SEQ_DONE) {
165 if (seq._sound !=
nullptr) {
168 seq._sound->internal_stop();
171 sequence = seq._sequence;
178 sequence = AIL_allocate_sequence_handle(_midi_driver);
183 index = _sequences.size();
187 seq._sequence = sequence;
188 _sequences.push_back(seq);
195 void GlobalMilesManager::
196 release_sequence(
size_t index, MilesAudioSequence *sound) {
198 nassertv(index < _sequences.size());
200 SequenceData &seq = _sequences[index];
201 if (seq._sound == sound) {
202 seq._sound =
nullptr;
211 void GlobalMilesManager::
213 if (!miles_audio_force_midi_reset) {
214 audio_debug(
"MilesAudioManager::skipping force_midi_reset");
217 audio_debug(
"MilesAudioManager::force_midi_reset");
220 if ((_midi_driver!=
nullptr) && (_midi_driver->deviceid != MIDI_nullptr_DRIVER) && (_midi_driver->hMidiOut !=
nullptr)) {
221 audio_debug(
"MilesAudioManager::calling midiOutReset");
222 midiOutReset(_midi_driver->hMidiOut);
230 GlobalMilesManager *GlobalMilesManager::
232 if (_global_ptr ==
nullptr) {
233 _global_ptr =
new GlobalMilesManager;
241 void GlobalMilesManager::
243 audio_debug(
"GlobalMilesManager::open_api()")
246 bool use_digital = (audio_play_wave || audio_play_mp3);
247 if (audio_play_midi && audio_software_midi) {
252 audio_software_midi =
true;
255 audio_debug(
" use_digital="<<use_digital);
256 audio_debug(
" audio_play_midi="<<audio_play_midi);
257 audio_debug(
" audio_software_midi="<<audio_software_midi);
258 audio_debug(
" audio_output_rate="<<audio_output_rate);
259 audio_debug(
" audio_output_bits="<<audio_output_bits);
260 audio_debug(
" audio_output_channels="<<audio_output_channels);
261 audio_debug(
" audio_software_midi="<<audio_software_midi);
263 #if !defined(NDEBUG) && defined(AIL_MSS_version) //[ 265 AIL_MSS_version(version, 8);
266 audio_debug(
" Mss32.dll Version: "<<version);
269 if (!AIL_startup()) {
270 milesAudio_cat.warning()
271 <<
"Miles Sound System already initialized!\n";
274 AIL_set_file_callbacks(open_callback, close_callback,
275 seek_callback, read_callback);
279 AIL_open_digital_driver(audio_output_rate, audio_output_bits,
280 audio_output_channels, 0);
283 if (audio_play_midi) {
284 if (audio_software_midi) {
285 _midi_driver = AIL_open_XMIDI_driver(AIL_OPEN_XMIDI_NULL_DRIVER);
288 _dls_device = AIL_DLS_open(_midi_driver, _digital_driver,
nullptr, 0,
289 audio_output_rate, audio_output_bits,
290 audio_output_channels);
299 if (file ==
nullptr) {
300 milesAudio_cat.warning()
301 <<
"DLS file does not exist: " << dls_pathname <<
"\n";
303 }
else if (!file->read_file(_dls_data,
true)) {
304 milesAudio_cat.warning()
305 <<
"Could not read DLS file: " << dls_pathname <<
"\n";
307 }
else if (_dls_data.empty()) {
308 milesAudio_cat.warning()
309 <<
"DLS file is empty: " << dls_pathname <<
"\n";
312 _dls_file = AIL_DLS_load_memory(_dls_device, &_dls_data[0], 0);
315 if (_dls_file == 0) {
316 audio_error(
" Could not get DLS file, switching to hardware MIDI.");
317 AIL_DLS_close(_dls_device, 0);
319 AIL_close_XMIDI_driver(_midi_driver);
320 _midi_driver = AIL_open_XMIDI_driver(0);
323 audio_info(
" using Miles software midi");
326 _midi_driver = AIL_open_XMIDI_driver(0);
327 audio_info(
" using Miles hardware midi");
337 void GlobalMilesManager::
339 audio_debug(
"GlobalMilesManager::close_api()")
342 Samples::iterator si;
343 for (si = _samples.begin(); si != _samples.end(); ++si) {
344 SampleData &smp = (*si);
345 AIL_release_sample_handle(smp._sample);
349 Sequences::iterator qi;
350 for (qi = _sequences.begin(); qi != _sequences.end(); ++qi) {
351 SequenceData &smp = (*qi);
352 AIL_release_sequence_handle(smp._sequence);
356 if (_dls_file != 0) {
357 AIL_DLS_unload(_dls_device, _dls_file);
361 if (_dls_device != 0) {
362 AIL_DLS_close(_dls_device, 0);
366 if (_midi_driver != 0) {
367 AIL_close_XMIDI_driver(_midi_driver);
371 if (_digital_driver != 0) {
372 AIL_close_digital_driver(_digital_driver);
386 U32 AILCALLBACK GlobalMilesManager::
387 open_callback(
char const *filename, UINTa *file_handle) {
389 istream *strm = vfs->
open_read_file(Filename::binary_filename(
string(filename)),
true);
390 if (strm ==
nullptr) {
395 (*file_handle) = (UINTa)strm;
403 void AILCALLBACK GlobalMilesManager::
404 close_callback(UINTa file_handle) {
405 istream *strm = (istream *)file_handle;
414 S32 AILCALLBACK GlobalMilesManager::
415 seek_callback(UINTa file_handle, S32 offset, U32 type) {
416 istream *strm = (istream *)file_handle;
419 case AIL_FILE_SEEK_BEGIN:
420 strm->seekg(offset, std::ios::beg);
423 case AIL_FILE_SEEK_CURRENT:
424 strm->seekg(offset, std::ios::cur);
427 case AIL_FILE_SEEK_END:
428 strm->seekg(offset, std::ios::end);
432 return strm->tellg();
439 U32 AILCALLBACK GlobalMilesManager::
440 read_callback(UINTa file_handle,
void *buffer, U32 bytes) {
441 istream *strm = (istream *)file_handle;
442 strm->read((
char *)buffer, bytes);
443 return strm->gcount();
A hierarchy of directories and files that appears to be one continuous file system,...
std::istream * open_read_file(const Filename &filename, bool auto_unwrap) const
Convenience function; returns a newly allocated istream if the file exists and can be read,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool resolve_filename(Filename &filename, const DSearchPath &searchpath, const std::string &default_extension=std::string()) const
Searches the given search path for the filename.
The abstract base class for a file or directory within the VirtualFileSystem.
get_dls_pathname
Returns the full pathname to the DLS file, as specified by the Config.prc file, or the default for th...
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
The name of a file, such as a texture file or an Egg file.
Similar to MutexHolder, but for a light mutex.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.