From f452fb3e353953153b2e4da4b50b6800ed9221ae Mon Sep 17 00:00:00 2001 From: Emanuele Disco Date: Mon, 23 Jan 2023 10:12:01 +0900 Subject: [PATCH] fix: gus emulation not falling back to fluidsynth when no patches are found and a valid dmxgus lump is provided If we load the instruments config without patches the gus emulation will not fall back to fluidsynth and no music will play. How to replicate the issue: 1. set midi_dmxgus=true 2. select Gus Emulation as midi device 3. remove any path from section SoundfontSearch.Directories (we prevent auto selection of patches) 4. ULTRADIR and gus_patchdir should not be present --- .../mididevices/music_timidity_mididevice.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/source/mididevices/music_timidity_mididevice.cpp b/source/mididevices/music_timidity_mididevice.cpp index c512554..f1b0c7c 100644 --- a/source/mididevices/music_timidity_mididevice.cpp +++ b/source/mididevices/music_timidity_mididevice.cpp @@ -97,6 +97,7 @@ void TimidityMIDIDevice::LoadInstruments() if (gusConfig.reader) { // Check if we got some GUS data before using it. + bool prepareInstruments = gusConfig.readerName == "DMXGUS" ? false : true; std::string ultradir; const char *ret = getenv("ULTRADIR"); if (ret) ultradir = std::string(ret); @@ -105,12 +106,20 @@ void TimidityMIDIDevice::LoadInstruments() { ultradir += "/midi"; gusConfig.reader->add_search_path(ultradir.c_str()); + prepareInstruments = true; } // Load DMXGUS lump and patches from gus_patchdir - if (gusConfig.gus_patchdir.length() != 0) gusConfig.reader->add_search_path(gusConfig.gus_patchdir.c_str()); + if (gusConfig.gus_patchdir.length() != 0) + { + gusConfig.reader->add_search_path(gusConfig.gus_patchdir.c_str()); + prepareInstruments = true; + } - gusConfig.instruments.reset(new Timidity::Instruments(gusConfig.reader)); - gusConfig.loadedConfig = gusConfig.readerName; + if (prepareInstruments) + { + gusConfig.instruments.reset(new Timidity::Instruments(gusConfig.reader)); + gusConfig.loadedConfig = gusConfig.readerName; + } } if (gusConfig.instruments == nullptr) @@ -256,8 +265,6 @@ void TimidityMIDIDevice::ComputeOutput(float *buffer, int len) bool GUS_SetupConfig(const char* args) { if (*args == 0) args = gusConfig.gus_config.c_str(); - if (gusConfig.gus_dmxgus && *args == 0) args = "DMXGUS"; - //if (stricmp(gusConfig.loadedConfig.c_str(), args) == 0) return false; // aleady loaded MusicIO::SoundFontReaderInterface* reader = MusicIO::ClientOpenSoundFont(args, SF_GUS); if (!reader && MusicIO::fileExists(args)) @@ -277,6 +284,7 @@ bool GUS_SetupConfig(const char* args) if (!reader && gusConfig.gus_dmxgus) { + args = "DMXGUS"; reader = new MusicIO::FileSystemSoundFontReader(args, true); }