mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +00:00
- removed most dependencies on ZDoom code in ADL Midi device.
This commit is contained in:
parent
d3df422031
commit
9b0529b8a3
5 changed files with 109 additions and 86 deletions
|
@ -1185,6 +1185,7 @@ set (PCH_SOURCES
|
|||
sound/music/i_music.cpp
|
||||
sound/music/i_soundfont.cpp
|
||||
sound/backend/i_sound.cpp
|
||||
sound/mididevices/midi_cvars.cpp
|
||||
sound/mididevices/music_adlmidi_mididevice.cpp
|
||||
sound/mididevices/music_opl_mididevice.cpp
|
||||
sound/mididevices/music_opnmidi_mididevice.cpp
|
||||
|
|
71
src/sound/mididevices/midi_cvars.cpp
Normal file
71
src/sound/mididevices/midi_cvars.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
|
||||
#include "i_musicinterns.h"
|
||||
#include "i_soundfont.h"
|
||||
#include "adlmidi.h"
|
||||
|
||||
static void CheckRestart(int devtype)
|
||||
{
|
||||
if (currSong != nullptr && currSong->GetDeviceType() == devtype)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
// This is part of the config struct so that the device does not have to depend on the sound font manager and can work without it.
|
||||
static const char *ADL_FullPath(const char *bankfile)
|
||||
{
|
||||
auto info = sfmanager.FindSoundFont(bankfile, SF_WOPL);
|
||||
if(info == nullptr) return nullptr;
|
||||
return info->mFilename;
|
||||
}
|
||||
|
||||
ADLConfig adlConfig = { ADL_FullPath };
|
||||
|
||||
|
||||
CUSTOM_CVAR(Int, adl_chips_count, 6, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
CheckRestart(MDEV_ADL);
|
||||
adlConfig.adl_chips_count = self;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Int, adl_emulator_id, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
CheckRestart(MDEV_ADL);
|
||||
adlConfig.adl_emulator_id = self;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_run_at_pcm_rate, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
CheckRestart(MDEV_ADL);
|
||||
adlConfig.adl_run_at_pcm_rate = self;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_fullpan, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
CheckRestart(MDEV_ADL);
|
||||
adlConfig.adl_fullpan = self;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Int, adl_bank, 14, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
CheckRestart(MDEV_ADL);
|
||||
adlConfig.adl_bank = self;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_use_custom_bank, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
CheckRestart(MDEV_ADL);
|
||||
adlConfig.adl_use_custom_bank = self;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(String, adl_custom_bank, "", CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
CheckRestart(MDEV_ADL);
|
||||
adlConfig.adl_custom_bank = self;
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Int, adl_volume_model, ADLMIDI_VolumeModel_DMX, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
CheckRestart(MDEV_ADL);
|
||||
adlConfig.adl_volume_model = self;
|
||||
}
|
|
@ -36,13 +36,12 @@
|
|||
|
||||
#include "i_musicinterns.h"
|
||||
#include "adlmidi.h"
|
||||
#include "i_soundfont.h"
|
||||
|
||||
class ADLMIDIDevice : public SoftSynthMIDIDevice
|
||||
{
|
||||
struct ADL_MIDIPlayer *Renderer;
|
||||
public:
|
||||
ADLMIDIDevice(const char *args);
|
||||
ADLMIDIDevice(const char *args, const ADLConfig *config);
|
||||
~ADLMIDIDevice();
|
||||
|
||||
int Open(MidiCallback, void *userdata);
|
||||
|
@ -55,7 +54,7 @@ protected:
|
|||
void ComputeOutput(float *buffer, int len);
|
||||
|
||||
private:
|
||||
int LoadCustomBank(const char *bankfile);
|
||||
int LoadCustomBank(const char *bankfile, const ADLConfig *config);
|
||||
};
|
||||
|
||||
|
||||
|
@ -70,90 +69,25 @@ enum
|
|||
ME_PITCHWHEEL = 0xE0
|
||||
};
|
||||
|
||||
CUSTOM_CVAR(Int, adl_chips_count, 6, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_ADL)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Int, adl_emulator_id, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_ADL)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_run_at_pcm_rate, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_ADL)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_fullpan, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_ADL)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CUSTOM_CVAR(Int, adl_bank, 14, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_ADL)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Bool, adl_use_custom_bank, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_ADL)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(String, adl_custom_bank, "", CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (adl_use_custom_bank && currSong != nullptr && currSong->GetDeviceType() == MDEV_ADL)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
CUSTOM_CVAR(Int, adl_volume_model, ADLMIDI_VolumeModel_DMX, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
if (currSong != nullptr && currSong->GetDeviceType() == MDEV_ADL)
|
||||
{
|
||||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// ADLMIDIDevice Constructor
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
ADLMIDIDevice::ADLMIDIDevice(const char *args)
|
||||
ADLMIDIDevice::ADLMIDIDevice(const char *args, const ADLConfig *config)
|
||||
:SoftSynthMIDIDevice(44100)
|
||||
{
|
||||
Renderer = adl_init(44100); // todo: make it configurable
|
||||
if (Renderer != nullptr)
|
||||
{
|
||||
adl_switchEmulator(Renderer, (int)adl_emulator_id);
|
||||
adl_setRunAtPcmRate(Renderer, (int)adl_run_at_pcm_rate);
|
||||
if(!LoadCustomBank(adl_custom_bank))
|
||||
adl_setBank(Renderer, (int)adl_bank);
|
||||
adl_setNumChips(Renderer, (int)adl_chips_count);
|
||||
adl_setVolumeRangeModel(Renderer, (int)adl_volume_model);
|
||||
adl_setSoftPanEnabled(Renderer, (int)adl_fullpan);
|
||||
adl_switchEmulator(Renderer, config->adl_emulator_id);
|
||||
adl_setRunAtPcmRate(Renderer, config->adl_run_at_pcm_rate);
|
||||
if(!LoadCustomBank(config->adl_custom_bank, config))
|
||||
adl_setBank(Renderer, config->adl_bank);
|
||||
adl_setNumChips(Renderer, config->adl_chips_count);
|
||||
adl_setVolumeRangeModel(Renderer, config->adl_volume_model);
|
||||
adl_setSoftPanEnabled(Renderer, config->adl_fullpan);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,14 +115,15 @@ ADLMIDIDevice::~ADLMIDIDevice()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
int ADLMIDIDevice::LoadCustomBank(const char *bankfile)
|
||||
int ADLMIDIDevice::LoadCustomBank(const char *bankfile, const ADLConfig *config)
|
||||
{
|
||||
if(!adl_use_custom_bank)
|
||||
if(!config->adl_use_custom_bank)
|
||||
return 0;
|
||||
auto info = sfmanager.FindSoundFont(bankfile, SF_WOPL);
|
||||
if(info == nullptr)
|
||||
return 0;
|
||||
bankfile = info->mFilename.GetChars();
|
||||
if (config->adl_full_path)
|
||||
{
|
||||
bankfile = config->adl_full_path(bankfile);
|
||||
if(bankfile == nullptr) return 0;
|
||||
}
|
||||
return (adl_openBankFile(Renderer, bankfile) == 0);
|
||||
}
|
||||
|
||||
|
@ -294,9 +229,9 @@ void ADLMIDIDevice::ComputeOutput(float *buffer, int len)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
MIDIDevice *CreateADLMIDIDevice(const char *args)
|
||||
MIDIDevice *CreateADLMIDIDevice(const char *args, const ADLConfig *config)
|
||||
{
|
||||
return new ADLMIDIDevice(args);
|
||||
return new ADLMIDIDevice(args, config);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include "oplsynth/opl_mus_player.h"
|
||||
#include "c_cvars.h"
|
||||
#include "mus2midi.h"
|
||||
|
@ -26,6 +27,21 @@ struct MidiHeader
|
|||
MidiHeader *lpNext;
|
||||
};
|
||||
|
||||
struct ADLConfig
|
||||
{
|
||||
const char * (*adl_full_path)(const char* filename);
|
||||
int adl_chips_count;
|
||||
int adl_emulator_id;
|
||||
int adl_bank;
|
||||
int adl_volume_model;
|
||||
bool adl_run_at_pcm_rate;
|
||||
bool adl_fullpan;
|
||||
bool adl_use_custom_bank;
|
||||
const char *adl_custom_bank;
|
||||
};
|
||||
|
||||
extern ADLConfig adlConfig;
|
||||
|
||||
|
||||
class MIDIStreamer;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ MIDIDevice *CreateWinMIDIDevice(int mididevice);
|
|||
MIDIDevice *CreateFluidSynthMIDIDevice(const char *args, int samplerate);
|
||||
MIDIDevice *CreateTimidityMIDIDevice(const char *args, int samplerate);
|
||||
MIDIDevice *CreateTimidityPPMIDIDevice(const char *args, int samplerate);
|
||||
MIDIDevice *CreateADLMIDIDevice(const char *args);
|
||||
MIDIDevice *CreateADLMIDIDevice(const char *args, const ADLConfig* config);
|
||||
MIDIDevice *CreateOPNMIDIDevice(const char *args);
|
||||
MIDIDevice *CreateWildMIDIDevice(const char *args, int samplerate);
|
||||
|
||||
|
@ -211,7 +211,7 @@ MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype, int samplerate)
|
|||
break;
|
||||
|
||||
case MDEV_ADL:
|
||||
dev = CreateADLMIDIDevice(Args);
|
||||
dev = CreateADLMIDIDevice(Args, &adlConfig);
|
||||
break;
|
||||
|
||||
case MDEV_OPN:
|
||||
|
|
Loading…
Reference in a new issue