From da5fccb598554e8f1df2fa300f1aa8fd9296ddfe 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 7b9276f1f..03516236a 100644 --- a/src/sound/midisources/midisource_hmi.cpp +++ b/src/sound/midisources/midisource_hmi.cpp @@ -648,7 +648,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 5330d74d4..2f7f29d29 100644 --- a/src/sound/midisources/midisource_smf.cpp +++ b/src/sound/midisources/midisource_smf.cpp @@ -589,7 +589,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 3fbfdeb5d..84f860a48 100644 --- a/src/sound/midisources/midisource_xmi.cpp +++ b/src/sound/midisources/midisource_xmi.cpp @@ -519,7 +519,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 eea40e8c4..f83b5196e 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -366,6 +366,7 @@ bool MIDIStreamer::InitPlayback() } source->CheckCaps(MIDI->GetTechnology()); + if (!MIDI->CanHandleSysex()) source->SkipSysex(); if (MIDI->Preprocess(this, m_Looping)) {