diff --git a/source/mididevices/music_fluidsynth_mididevice.cpp b/source/mididevices/music_fluidsynth_mididevice.cpp index ae3e7d1..1a33d3c 100644 --- a/source/mididevices/music_fluidsynth_mididevice.cpp +++ b/source/mididevices/music_fluidsynth_mididevice.cpp @@ -239,9 +239,10 @@ void FluidSynthMIDIDevice::HandleEvent(int status, int parm1, int parm2) void FluidSynthMIDIDevice::HandleLongEvent(const uint8_t *data, int len) { - if (len > 1 && (data[0] == 0xF0 || data[0] == 0xF7)) + constexpr int excludedByteCount = 2; // 0xF0 (first byte) and 0xF7 (last byte) are not given to FluidSynth. + if (len > excludedByteCount && data[0] == 0xF0 && data[len - 1] == 0xF7) { - fluid_synth_sysex(FluidSynth, (const char *)data + 1, len - 1, NULL, NULL, NULL, 0); + fluid_synth_sysex(FluidSynth, (const char *)data + 1, len - excludedByteCount, NULL, NULL, NULL, 0); } } diff --git a/source/musicformats/music_midi.cpp b/source/musicformats/music_midi.cpp index eb43daf..9dda9f4 100644 --- a/source/musicformats/music_midi.cpp +++ b/source/musicformats/music_midi.cpp @@ -815,7 +815,7 @@ int MIDIStreamer::FillBuffer(int buffer_num, int max_events, uint32_t max_time) if (InitialPlayback) { InitialPlayback = false; - // Send the GS System Reset SysEx message. + // Send the GM System Enable SysEx message. events[0] = 0; // dwDeltaTime events[1] = 0; // dwStreamID events[2] = (MEVENT_LONGMSG << 24) | 6; // dwEvent @@ -823,6 +823,15 @@ int MIDIStreamer::FillBuffer(int buffer_num, int max_events, uint32_t max_time) events[4] = MAKE_ID(0x01, 0xf7, 0x00, 0x00); // dwParms[1] events += 5; + // Send the GS DT1 MODE SET GS Reset SysEx message. + events[0] = 0; // dwDeltaTime + events[1] = 0; // dwStreamID + events[2] = (MEVENT_LONGMSG << 24) | 11; // dwEvent + events[3] = MAKE_ID(0xf0, 0x41, 0x7f, 0x42); // dwParms[0] + events[4] = MAKE_ID(0x12, 0x40, 0x00, 0x7f); // dwParms[1] + events[5] = MAKE_ID(0x00, 0x41, 0xf7, 0x00); // dwParms[2] + events += 6; + // Send the full master volume SysEx message. events[0] = 0; // dwDeltaTime events[1] = 0; // dwStreamID