ref: a84bfaefd8ded67dff17cf97e047196fefb440dc
parent: aa8172e9002ff31a8a2f8daa74fbd9f49c44b3b6
author: Roman Fomin <rfomin@gmail.com>
date: Mon Dec 6 11:16:39 EST 2021
win midi: Reset pitch bend range when stopping song
--- a/src/i_winmusic.c
+++ b/src/i_winmusic.c
@@ -407,6 +407,29 @@
hPlayerThread = NULL;
}
+ for (i = 0; i < MIDI_CHANNELS_PER_TRACK; ++i)
+ {
+ DWORD msg = 0;
+
+ // RPN sequence to adjust pitch bend range (RPN value 0x0000)
+ msg = MIDI_EVENT_CONTROLLER | i | 0x65 << 8 | 0x00 << 16;
+ midiOutShortMsg((HMIDIOUT)hMidiStream, msg);
+ msg = MIDI_EVENT_CONTROLLER | i | 0x64 << 8 | 0x00 << 16;
+ midiOutShortMsg((HMIDIOUT)hMidiStream, msg);
+
+ // reset pitch bend range to central tuning +/- 2 semitones and 0 cents
+ msg = MIDI_EVENT_CONTROLLER | i | 0x06 << 8 | 0x02 << 16;
+ midiOutShortMsg((HMIDIOUT)hMidiStream, msg);
+ msg = MIDI_EVENT_CONTROLLER | i | 0x26 << 8 | 0x00 << 16;
+ midiOutShortMsg((HMIDIOUT)hMidiStream, msg);
+
+ // end of RPN sequence
+ msg = MIDI_EVENT_CONTROLLER | i | 0x64 << 8 | 0x7F << 16;
+ midiOutShortMsg((HMIDIOUT)hMidiStream, msg);
+ msg = MIDI_EVENT_CONTROLLER | i | 0x65 << 8 | 0x7F << 16;
+ midiOutShortMsg((HMIDIOUT)hMidiStream, msg);
+ }
+
mmr = midiStreamStop(hMidiStream);
if (mmr != MMSYSERR_NOERROR)
{