mirror of
https://github.com/ZDoom/ZMusic.git
synced 2025-01-29 20:00:53 +00:00
OPNMIDI: Fixed an inability to load a custom bank
This commit is contained in:
parent
13623aeda8
commit
14c771f609
1 changed files with 35 additions and 15 deletions
|
@ -46,7 +46,7 @@ class OPNMIDIDevice : public SoftSynthMIDIDevice
|
|||
{
|
||||
struct OPN2_MIDIPlayer *Renderer;
|
||||
public:
|
||||
OPNMIDIDevice(const char *bank);
|
||||
OPNMIDIDevice(const OpnConfig *config);
|
||||
~OPNMIDIDevice();
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ protected:
|
|||
void ComputeOutput(float *buffer, int len) override;
|
||||
|
||||
private:
|
||||
int LoadCustomBank(const char *bankfile);
|
||||
int LoadCustomBank(const OpnConfig *config);
|
||||
};
|
||||
|
||||
|
||||
|
@ -82,25 +82,25 @@ enum
|
|||
//==========================================================================
|
||||
#include "data/xg.h"
|
||||
|
||||
OPNMIDIDevice::OPNMIDIDevice(const char *bank)
|
||||
OPNMIDIDevice::OPNMIDIDevice(const OpnConfig *config)
|
||||
:SoftSynthMIDIDevice(44100)
|
||||
{
|
||||
Renderer = opn2_init(44100); // todo: make it configurable
|
||||
if (Renderer != nullptr)
|
||||
{
|
||||
if (!opnConfig.opn_use_custom_bank || !LoadCustomBank(opnConfig.opn_custom_bank.c_str()))
|
||||
if (!LoadCustomBank(config))
|
||||
{
|
||||
if(opnConfig.default_bank.size() == 0)
|
||||
if(config->default_bank.size() == 0)
|
||||
{
|
||||
opn2_openBankData(Renderer, xg_default, sizeof(xg_default));
|
||||
}
|
||||
else opn2_openBankData(Renderer, opnConfig.default_bank.data(), (long)opnConfig.default_bank.size());
|
||||
else opn2_openBankData(Renderer, config->default_bank.data(), (long)config->default_bank.size());
|
||||
}
|
||||
|
||||
opn2_switchEmulator(Renderer, (int)opnConfig.opn_emulator_id);
|
||||
opn2_setRunAtPcmRate(Renderer, (int)opnConfig.opn_run_at_pcm_rate);
|
||||
opn2_setNumChips(Renderer, opnConfig.opn_chips_count);
|
||||
opn2_setSoftPanEnabled(Renderer, (int)opnConfig.opn_fullpan);
|
||||
opn2_switchEmulator(Renderer, (int)config->opn_emulator_id);
|
||||
opn2_setRunAtPcmRate(Renderer, (int)config->opn_run_at_pcm_rate);
|
||||
opn2_setNumChips(Renderer, config->opn_chips_count);
|
||||
opn2_setSoftPanEnabled(Renderer, (int)config->opn_fullpan);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -133,9 +133,12 @@ OPNMIDIDevice::~OPNMIDIDevice()
|
|||
//==========================================================================
|
||||
|
||||
|
||||
int OPNMIDIDevice::LoadCustomBank(const char *bankfile)
|
||||
int OPNMIDIDevice::LoadCustomBank(const OpnConfig *config)
|
||||
{
|
||||
if(!bankfile || !*bankfile)
|
||||
const char *bankfile = config->opn_custom_bank.c_str();
|
||||
if(!config->opn_use_custom_bank)
|
||||
return 0;
|
||||
if(!*bankfile)
|
||||
return 0;
|
||||
return (opn2_openBankFile(Renderer, bankfile) == 0);
|
||||
}
|
||||
|
@ -235,17 +238,34 @@ void OPNMIDIDevice::ComputeOutput(float *buffer, int len)
|
|||
|
||||
MIDIDevice *CreateOPNMIDIDevice(const char *Args)
|
||||
{
|
||||
OpnConfig config = opnConfig;
|
||||
|
||||
const char* bank = Args && *Args ? Args : opnConfig.opn_use_custom_bank ? opnConfig.opn_custom_bank.c_str() : nullptr;
|
||||
if (bank && *bank)
|
||||
{
|
||||
const char* info;
|
||||
if (musicCallbacks.PathForSoundfont)
|
||||
{
|
||||
auto info = musicCallbacks.PathForSoundfont(bank, SF_WOPN);
|
||||
if (info != nullptr) bank = info;
|
||||
info = musicCallbacks.PathForSoundfont(bank, SF_WOPN);
|
||||
}
|
||||
else
|
||||
{
|
||||
info = bank;
|
||||
}
|
||||
|
||||
if(info == nullptr)
|
||||
{
|
||||
config.opn_custom_bank = "";
|
||||
config.opn_use_custom_bank = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
config.opn_custom_bank = info;
|
||||
config.opn_use_custom_bank = true;
|
||||
}
|
||||
}
|
||||
|
||||
return new OPNMIDIDevice(bank);
|
||||
return new OPNMIDIDevice(&config);
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue