Skip to content

Commit

Permalink
drop() no longer calls midiOutReset
Browse files Browse the repository at this point in the history
Fixes Boddlnagg#122

On Windows, midiOutReset was being called before midiOutClose,
presumably to cancel any pending output. This caused extra MIDI
commands to be sent. Instead, we now call midiOutClose repeatedly
until it's no longer blocked by pending output.
  • Loading branch information
dwmuller committed Oct 16, 2022
1 parent c6aa248 commit 4ccaf57
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/backend/winmm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use windows::Win32::Media::Audio::{
midiInOpen, midiInPrepareHeader, midiInReset, midiInStart,
midiInStop, midiInUnprepareHeader, midiOutClose,
midiOutGetDevCapsW, midiOutGetNumDevs, midiOutLongMsg, midiOutOpen,
midiOutPrepareHeader, midiOutReset, midiOutShortMsg,
midiOutPrepareHeader, midiOutShortMsg,
midiOutUnprepareHeader, midiInMessage, midiOutMessage,
HMIDIIN, HMIDIOUT, MIDIHDR, MIDIINCAPSW, MIDIOUTCAPSW, CALLBACK_FUNCTION, CALLBACK_NULL,
MIDIERR_NOTREADY, MIDIERR_STILLPLAYING,
Expand Down Expand Up @@ -533,9 +533,12 @@ impl MidiOutputConnection {

impl Drop for MidiOutputConnection {
fn drop(&mut self) {
unsafe {
midiOutReset(self.out_handle);
midiOutClose(self.out_handle);
loop {
let result = unsafe { midiOutClose(self.out_handle) };
if result == MIDIERR_STILLPLAYING {
sleep(Duration::from_millis(1));
continue;
} else { break; }
}
}
}

0 comments on commit 4ccaf57

Please sign in to comment.