mirror of
https://github.com/ZDoom/ZMusic.git
synced 2024-11-14 00:20:44 +00:00
Fixes for gus and wildmidi emulation
- fixed gus emulation not working with DMXGUS and DMXGUSC lump - gus_patchdir and/or ULTRADIR variable can be used to load custom gus patches together with main patches set with midi_config (not required when using DMXGUS(C) lump configuration) - gus_patchdir and ULTRADIR variable can be used with both DMXGUS and timidity configuration when using GUS emulation - fixed wildmidi emulation not working with collection of gus patches (resource files) - removed sf2 files from midi_config items for gus emulation (when using sf2 with gus emulation the sound is distorted), only resource files will be listed to be used with gus emulation. - removed the `already loaded` check from timidity setup in order to recreate the reader even when changing the gus memory.
This commit is contained in:
parent
6b5aebf6a3
commit
f4cfb36f4a
3 changed files with 47 additions and 59 deletions
|
@ -94,42 +94,44 @@ protected:
|
|||
|
||||
void TimidityMIDIDevice::LoadInstruments()
|
||||
{
|
||||
if (gusConfig.dmxgus.size())
|
||||
if (gusConfig.reader)
|
||||
{
|
||||
// Check if we got some GUS data before using it.
|
||||
std::string ultradir = getenv("ULTRADIR");
|
||||
if (ultradir.length() || gusConfig.gus_patchdir.length() != 0)
|
||||
std::string ultradir;
|
||||
const char *ret = getenv("ULTRADIR");
|
||||
if (ret) ultradir = std::string(ret);
|
||||
// The GUS put its patches in %ULTRADIR%/MIDI so we can try that
|
||||
if (ultradir.length())
|
||||
{
|
||||
auto psreader = new MusicIO::FileSystemSoundFontReader("");
|
||||
|
||||
// The GUS put its patches in %ULTRADIR%/MIDI so we can try that
|
||||
if (ultradir.length())
|
||||
{
|
||||
ultradir += "/midi";
|
||||
psreader->add_search_path(ultradir.c_str());
|
||||
}
|
||||
// Load DMXGUS lump and patches from gus_patchdir
|
||||
if (gusConfig.gus_patchdir.length() != 0) psreader->add_search_path(gusConfig.gus_patchdir.c_str());
|
||||
|
||||
gusConfig.instruments.reset(new Timidity::Instruments(psreader));
|
||||
bool success = gusConfig.instruments->LoadDMXGUS(gusConfig.gus_memsize, (const char*)gusConfig.dmxgus.data(), gusConfig.dmxgus.size()) >= 0;
|
||||
|
||||
gusConfig.dmxgus.clear();
|
||||
|
||||
if (success)
|
||||
{
|
||||
gusConfig.loadedConfig = "DMXGUS";
|
||||
return;
|
||||
}
|
||||
ultradir += "/midi";
|
||||
gusConfig.reader->add_search_path(ultradir.c_str());
|
||||
}
|
||||
gusConfig.loadedConfig = "";
|
||||
gusConfig.instruments.reset();
|
||||
throw std::runtime_error("Unable to initialize DMXGUS for GUS MIDI device");
|
||||
}
|
||||
else if (gusConfig.reader)
|
||||
{
|
||||
gusConfig.loadedConfig = gusConfig.readerName;
|
||||
// Load DMXGUS lump and patches from gus_patchdir
|
||||
if (gusConfig.gus_patchdir.length() != 0) gusConfig.reader->add_search_path(gusConfig.gus_patchdir.c_str());
|
||||
|
||||
gusConfig.instruments.reset(new Timidity::Instruments(gusConfig.reader));
|
||||
gusConfig.loadedConfig = gusConfig.readerName;
|
||||
}
|
||||
|
||||
if (gusConfig.instruments == nullptr)
|
||||
{
|
||||
throw std::runtime_error("No instruments set for GUS device");
|
||||
}
|
||||
|
||||
if (gusConfig.gus_dmxgus && gusConfig.dmxgus.size())
|
||||
{
|
||||
bool success = gusConfig.instruments->LoadDMXGUS(gusConfig.gus_memsize, (const char*)gusConfig.dmxgus.data(), gusConfig.dmxgus.size()) >= 0;
|
||||
gusConfig.reader = nullptr;
|
||||
|
||||
if (!success)
|
||||
{
|
||||
gusConfig.instruments.reset();
|
||||
gusConfig.loadedConfig = "";
|
||||
throw std::runtime_error("Unable to initialize DMXGUS for GUS MIDI device");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool err = gusConfig.instruments->LoadConfig() < 0;
|
||||
gusConfig.reader = nullptr;
|
||||
|
||||
|
@ -140,10 +142,6 @@ void TimidityMIDIDevice::LoadInstruments()
|
|||
throw std::runtime_error("Unable to initialize instruments for GUS MIDI device");
|
||||
}
|
||||
}
|
||||
else if (gusConfig.instruments == nullptr)
|
||||
{
|
||||
throw std::runtime_error("No instruments set for GUS device");
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -257,20 +255,11 @@ void TimidityMIDIDevice::ComputeOutput(float *buffer, int len)
|
|||
|
||||
bool GUS_SetupConfig(const char* args)
|
||||
{
|
||||
gusConfig.reader = nullptr;
|
||||
if ((gusConfig.gus_dmxgus && *args == 0) || !stricmp(args, "DMXGUS"))
|
||||
{
|
||||
if (stricmp(gusConfig.loadedConfig.c_str(), "DMXGUS") == 0) return false; // aleady loaded
|
||||
if (gusConfig.dmxgus.size() > 0)
|
||||
{
|
||||
gusConfig.readerName = "DMXGUS";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (*args == 0) args = gusConfig.gus_config.c_str();
|
||||
if (stricmp(gusConfig.loadedConfig.c_str(), args) == 0) return false; // aleady loaded
|
||||
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 | SF_SF2);
|
||||
MusicIO::SoundFontReaderInterface* reader = MusicIO::ClientOpenSoundFont(args, SF_GUS);
|
||||
if (!reader && MusicIO::fileExists(args))
|
||||
{
|
||||
auto f = MusicIO::utf8_fopen(args, "rb");
|
||||
|
@ -286,6 +275,11 @@ bool GUS_SetupConfig(const char* args)
|
|||
if (!reader) reader = new MusicIO::FileSystemSoundFontReader(args, true);
|
||||
}
|
||||
|
||||
if (!reader && gusConfig.gus_dmxgus)
|
||||
{
|
||||
reader = new MusicIO::FileSystemSoundFontReader(args, true);
|
||||
}
|
||||
|
||||
if (reader == nullptr)
|
||||
{
|
||||
char error[80];
|
||||
|
|
|
@ -87,15 +87,7 @@ void WildMIDIDevice::LoadInstruments()
|
|||
{
|
||||
wildMidiConfig.loadedConfig = wildMidiConfig.readerName;
|
||||
wildMidiConfig.instruments.reset(new WildMidi::Instruments(wildMidiConfig.reader, SampleRate));
|
||||
int error = wildMidiConfig.instruments->LoadConfig(wildMidiConfig.readerName.c_str());
|
||||
wildMidiConfig.reader = nullptr;
|
||||
|
||||
if (error)
|
||||
{
|
||||
wildMidiConfig.instruments.reset();
|
||||
wildMidiConfig.loadedConfig = "";
|
||||
throw std::runtime_error("Unable to initialize instruments for WildMidi device");
|
||||
}
|
||||
}
|
||||
else if (wildMidiConfig.instruments == nullptr)
|
||||
{
|
||||
|
@ -104,7 +96,9 @@ void WildMIDIDevice::LoadInstruments()
|
|||
instruments = wildMidiConfig.instruments;
|
||||
if (instruments->LoadConfig(nullptr) < 0)
|
||||
{
|
||||
throw std::runtime_error("Unable to load instruments set for WildMidi device");
|
||||
wildMidiConfig.instruments.reset();
|
||||
wildMidiConfig.loadedConfig = "";
|
||||
throw std::runtime_error("Unable to initialize instruments for WildMidi device");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -503,7 +503,7 @@ DLL_EXPORT zmusic_bool ChangeMusicSettingInt(EIntConfigKey key, MusInfo *currSon
|
|||
|
||||
case zmusic_gus_memsize:
|
||||
ChangeAndReturn(gusConfig.gus_memsize, value, pRealValue);
|
||||
return devType() == MDEV_GUS && gusConfig.gus_dmxgus;
|
||||
return devType() == MDEV_GUS;
|
||||
#endif
|
||||
#ifdef HAVE_TIMIDITY
|
||||
case zmusic_timidity_modulation_wheel:
|
||||
|
@ -518,15 +518,15 @@ DLL_EXPORT zmusic_bool ChangeMusicSettingInt(EIntConfigKey key, MusInfo *currSon
|
|||
|
||||
case zmusic_timidity_reverb:
|
||||
if (value < 0 || value > 4) value = 0;
|
||||
else TimidityPlus_SetReverb();
|
||||
local_timidity_reverb = value;
|
||||
TimidityPlus_SetReverb();
|
||||
if (pRealValue) *pRealValue = value;
|
||||
return false;
|
||||
|
||||
case zmusic_timidity_reverb_level:
|
||||
if (value < 0 || value > 127) value = 0;
|
||||
else TimidityPlus_SetReverb();
|
||||
local_timidity_reverb_level = value;
|
||||
TimidityPlus_SetReverb();
|
||||
if (pRealValue) *pRealValue = value;
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Reference in a new issue