optionally reset midi before playing new song

This commit is contained in:
cxgeorge 2002-10-08 03:06:22 +00:00
parent dd2b927420
commit da7257d5a1
3 changed files with 53 additions and 9 deletions

View File

@ -96,6 +96,7 @@ MilesAudioManager() {
_volume = audio_volume;
_cache_limit = audio_cache_limit;
_is_valid = true;
_bHasMidiSounds = false;
if (!_active_managers) {
S32 use_digital=(audio_play_wave || audio_play_mp3)?1:0;
S32 use_MIDI=(audio_play_midi)?1:0;
@ -315,6 +316,8 @@ get_sound(const string& file_name) {
_soundsOnLoan.insert(milesAudioSound);
audioSound=milesAudioSound;
}
_bHasMidiSounds |= (file_name.find(".mid")!=string::npos);
audio_debug(" returning 0x" << (void*)audioSound);
assert(is_valid());
return audioSound;
@ -472,6 +475,33 @@ set_volume(float volume) {
}
}
void MilesAudioManager::
stop_all_sounds(void) {
audio_debug("MilesAudioManager::stop_all_sounds()");
AudioSet::iterator i=_soundsOnLoan.begin();
for (; i!=_soundsOnLoan.end(); ++i) {
if((**i).status()==AudioSound::PLAYING)
(**i).stop();
}
if(_bHasMidiSounds) {
forceMidiReset();
}
}
void MilesAudioManager::
forceMidiReset(void) {
audio_debug("MilesAudioManager::ForceMidiReset");
// sometimes Miles seems to leave midi notes hanging, even after stop is called,
// so perform an explicit reset using winMM.dll calls, just to ensure silence.
HMDIDRIVER hMid=NULL;
AIL_quick_handles(0, &hMid, 0);
if ((hMid!=NULL) && (hMid->deviceid != MIDI_NULL_DRIVER) && (hMid->hMidiOut != NULL)) {
midiOutReset(hMid->hMidiOut);
}
}
////////////////////////////////////////////////////////////////////
// Function: MilesAudioManager::get_volume
// Access: Public
@ -498,6 +528,10 @@ set_active(bool active) {
for (; i!=_soundsOnLoan.end(); ++i) {
(**i).set_active(_active);
}
if((!_active) && _bHasMidiSounds) {
forceMidiReset();
}
}
}

View File

@ -51,6 +51,8 @@ public:
void set_active(bool active);
bool get_active();
void stop_all_sounds();
void forceMidiReset();
// Optional Downloadable Sound field for software midi:
// made public so C atexit fn can access it
@ -60,12 +62,14 @@ private:
// The sound cache:
typedef pmap<string, HAUDIO > SoundMap;
SoundMap _sounds;
typedef pset<MilesAudioSound* > AudioSet;
// The offspring of this manager:
AudioSet _soundsOnLoan;
// The Least Recently Used mechanism:
typedef pdeque<const string* > LRU;
LRU _lru;
// The offspring of this manager:
typedef pset<MilesAudioSound* > AudioSet;
AudioSet _soundsOnLoan;
// State:
float _volume;
bool _active;
@ -74,6 +78,7 @@ private:
static int _active_managers;
bool _is_valid;
bool _bHasMidiSounds;
HAUDIO load(Filename file_name);
// Tell the manager that the sound dtor was called.

View File

@ -80,21 +80,26 @@ void MilesAudioSound::
play() {
#if 0
if(_file_name.find(".mid")!=string::npos) {
miles_audio_debug("play() midi");
miles_audio_debug("play() midi");
}
#endif
miles_audio_debug("play()");
if (_active) {
if(_manager->_bExclusive) {
// stop any other sound that parent mgr is playing
_manager->stop_all_sounds();
}
// Start playing:
if (AIL_quick_play(_audio, _loop_count)) {
audio_debug(" started sound");
audio_debug(" started sound " << _file_name );
} else {
audio_debug(" failed to play sound "<<AIL_last_error());
audio_debug(" sound " << _file_name<<" failed to start, err: " <<AIL_last_error());
}
} else {
// In case _loop_count gets set to forever (zero):
audio_debug(" paused");
audio_debug(" paused "<<_file_name );
_paused=true;
}
}
@ -106,7 +111,7 @@ stop() {
miles_audio_debug("stop() midi");
}
#endif
miles_audio_debug("stop()");
miles_audio_debug("stopping snd " << _file_name);
_paused=false;
AIL_quick_halt(_audio);
}