From c5153ca095ae07d07986f3d71cc831ece049d71c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 1 Nov 2018 10:22:21 +0100 Subject: [PATCH] - fixed: Do not pass Sysex messages to Windows's GS Wavetable synth. This will totally refuse to play a MIDI if that happens. Duke Nukem's Alienz.mid, which did not play before works after this change. --- src/sound/i_musicinterns.h | 1 + src/sound/mididevices/music_win_mididevice.cpp | 6 ++++++ src/sound/midisources/midisource.h | 3 +++ src/sound/midisources/midisource_hmi.cpp | 2 +- src/sound/midisources/midisource_smf.cpp | 2 +- src/sound/midisources/midisource_xmi.cpp | 2 +- src/sound/musicformats/music_midistream.cpp | 1 + 7 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index c638afbe7..b3cebfccf 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -82,6 +82,7 @@ public: virtual bool Preprocess(MIDIStreamer *song, bool looping); virtual FString GetStats(); virtual int GetDeviceType() const { return MDEV_DEFAULT; } + virtual bool CanHandleSysex() const { return true; } }; diff --git a/src/sound/mididevices/music_win_mididevice.cpp b/src/sound/mididevices/music_win_mididevice.cpp index 2e1a4c5a9..f9820033f 100644 --- a/src/sound/mididevices/music_win_mididevice.cpp +++ b/src/sound/mididevices/music_win_mididevice.cpp @@ -86,6 +86,12 @@ public: bool Update() override; void PrecacheInstruments(const uint16_t *instruments, int count); DWORD PlayerLoop(); + bool CanHandleSysex() const override + { + // No Sysex for GS synth. + return VolumeWorks; + } + //protected: static void CALLBACK CallbackFunc(HMIDIOUT, UINT, DWORD_PTR, DWORD, DWORD); diff --git a/src/sound/midisources/midisource.h b/src/sound/midisources/midisource.h index 7e7381eae..12e0188b4 100644 --- a/src/sound/midisources/midisource.h +++ b/src/sound/midisources/midisource.h @@ -25,6 +25,7 @@ class MIDISource protected: bool isLooping = false; + bool skipSysex = false; int Division = 0; int Tempo = 500000; int InitialTempo = 500000; @@ -54,6 +55,8 @@ public: LoopLimit = looplimit; isLooping = looped; } + + void SkipSysex() { skipSysex = true; } bool isValid() const { return Division > 0; } int getDivision() const { return Division; } diff --git a/src/sound/midisources/midisource_hmi.cpp b/src/sound/midisources/midisource_hmi.cpp index 0c555268c..1fe08e9cc 100644 --- a/src/sound/midisources/midisource_hmi.cpp +++ b/src/sound/midisources/midisource_hmi.cpp @@ -644,7 +644,7 @@ uint32_t *HMISong::SendCommand (uint32_t *events, TrackInfo *track, uint32_t del if (event == MIDI_SYSEX || event == MIDI_SYSEXEND) { len = ReadVarLen(track); - if (len >= (MAX_MIDI_EVENTS-1)*3*4) + if (len >= (MAX_MIDI_EVENTS-1)*3*4 || skipSysex) { // This message will never fit. Throw it away. track->TrackP += len; } diff --git a/src/sound/midisources/midisource_smf.cpp b/src/sound/midisources/midisource_smf.cpp index d7e8808f1..42299b7f8 100644 --- a/src/sound/midisources/midisource_smf.cpp +++ b/src/sound/midisources/midisource_smf.cpp @@ -585,7 +585,7 @@ uint32_t *MIDISong2::SendCommand (uint32_t *events, TrackInfo *track, uint32_t d if (event == MIDI_SYSEX || event == MIDI_SYSEXEND) { len = track->ReadVarLen(); - if (len >= (MAX_MIDI_EVENTS-1)*3*4) + if (len >= (MAX_MIDI_EVENTS-1)*3*4 || skipSysex) { // This message will never fit. Throw it away. track->TrackP += len; } diff --git a/src/sound/midisources/midisource_xmi.cpp b/src/sound/midisources/midisource_xmi.cpp index caad0897c..3e2fcac87 100644 --- a/src/sound/midisources/midisource_xmi.cpp +++ b/src/sound/midisources/midisource_xmi.cpp @@ -515,7 +515,7 @@ uint32_t *XMISong::SendCommand (uint32_t *events, EventSource due, uint32_t dela if (event == MIDI_SYSEX || event == MIDI_SYSEXEND) { len = track->ReadVarLen(); - if (len >= (MAX_MIDI_EVENTS-1)*3*4) + if (len >= (MAX_MIDI_EVENTS-1)*3*4 || skipSysex) { // This message will never fit. Throw it away. track->EventP += len; } diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index 85c4135de..60061b264 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -364,6 +364,7 @@ bool MIDIStreamer::InitPlayback() } source->CheckCaps(MIDI->GetTechnology()); + if (!MIDI->CanHandleSysex()) source->SkipSysex(); if (MIDI->Preprocess(this, m_Looping)) {