From 52655b584957df0b504e51a34b1a192449048dc2 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 18 Mar 2018 16:15:14 +0100 Subject: [PATCH] Change: [Win32 MIDI] Reset pitch bend range controllers on song change Some songs (at least one in OpenMSX) use the MIDI pitch bend range controllers but don't reset these at the end. This causes all subsequent songs to sound wrong. --- src/music/win32_m.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp index bd2ed7038e..edaae36fa2 100644 --- a/src/music/win32_m.cpp +++ b/src/music/win32_m.cpp @@ -126,6 +126,19 @@ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR dwUser, DWORD_PTR, DW DEBUG(driver, 2, "Win32-MIDI: timer: do_start is set"); if (_midi.playing) { midiOutReset(_midi.midi_out); + /* Some songs change the "Pitch bend range" registered + * parameter. If this doesn't get reset, everything else + * will start sounding wrong. */ + for (int ch = 0; ch < 16; ch++) { + /* Running status, only need status for first message */ + /* Select RPN 00.00, set value to 02.00, and unselect again */ + TransmitChannelMsg(MIDIST_CONTROLLER | ch, MIDICT_RPN_SELECT_LO, 0x00); + TransmitChannelMsg(MIDICT_RPN_SELECT_HI, 0x00); + TransmitChannelMsg(MIDICT_DATAENTRY, 0x02); + TransmitChannelMsg(MIDICT_DATAENTRY_LO, 0x00); + TransmitChannelMsg(MIDICT_RPN_SELECT_LO, 0x7F); + TransmitChannelMsg(MIDICT_RPN_SELECT_HI, 0x7F); + } } _midi.current_file.MoveFrom(_midi.next_file); std::swap(_midi.next_segment, _midi.current_segment);