diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 22cbcf3af..09bba62dc 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -87,10 +87,7 @@ public: }; -#ifdef _WIN32 -MIDIDevice *CreateWinMIDIDevice(int mididevice); -#endif -MIDIDevice *CreateTimidityPPMIDIDevice(const char *args, int samplerate); + void TimidityPP_Shutdown(); // Base class for software synthesizer MIDI output devices ------------------ @@ -172,29 +169,6 @@ public: void Stop(); }; -// Internal TiMidity MIDI device -------------------------------------------- - -namespace Timidity { struct Renderer; } - -class TimidityMIDIDevice : public SoftSynthMIDIDevice -{ -public: - TimidityMIDIDevice(const char *args, int samplerate); - ~TimidityMIDIDevice(); - - int Open(MidiCallback, void *userdata); - void PrecacheInstruments(const uint16_t *instruments, int count); - FString GetStats(); - int GetDeviceType() const override { return MDEV_GUS; } - -protected: - Timidity::Renderer *Renderer; - - void HandleEvent(int status, int parm1, int parm2); - void HandleLongEvent(const uint8_t *data, int len); - void ComputeOutput(float *buffer, int len); -}; - // Internal disk writing version of a MIDI device ------------------ class MIDIWaveWriter : public SoftSynthMIDIDevice @@ -226,140 +200,6 @@ protected: SoftSynthMIDIDevice *playDevice; }; -// WildMidi implementation of a MIDI device --------------------------------- - -class WildMIDIDevice : public SoftSynthMIDIDevice -{ -public: - WildMIDIDevice(const char *args, int samplerate); - ~WildMIDIDevice(); - - int Open(MidiCallback, void *userdata); - void PrecacheInstruments(const uint16_t *instruments, int count); - FString GetStats(); - int GetDeviceType() const override { return MDEV_WILDMIDI; } - -protected: - WildMidi_Renderer *Renderer; - - void HandleEvent(int status, int parm1, int parm2); - void HandleLongEvent(const uint8_t *data, int len); - void ComputeOutput(float *buffer, int len); - void WildMidiSetOption(int opt, int set); -}; - -// FluidSynth implementation of a MIDI device ------------------------------- - -#ifndef DYN_FLUIDSYNTH -#include -#else -#include "i_module.h" -extern FModule FluidSynthModule; - -struct fluid_settings_t; -struct fluid_synth_t; -#endif - -class FluidSynthMIDIDevice : public SoftSynthMIDIDevice -{ -public: - FluidSynthMIDIDevice(const char *args, int samplerate); - ~FluidSynthMIDIDevice(); - - int Open(MidiCallback, void *userdata); - FString GetStats(); - void FluidSettingInt(const char *setting, int value); - void FluidSettingNum(const char *setting, double value); - void FluidSettingStr(const char *setting, const char *value); - int GetDeviceType() const override { return MDEV_FLUIDSYNTH; } - -protected: - void HandleEvent(int status, int parm1, int parm2); - void HandleLongEvent(const uint8_t *data, int len); - void ComputeOutput(float *buffer, int len); - int LoadPatchSets(const char *patches); - - fluid_settings_t *FluidSettings; - fluid_synth_t *FluidSynth; - -#ifdef DYN_FLUIDSYNTH - enum { FLUID_FAILED = -1, FLUID_OK = 0 }; - static TReqProc new_fluid_settings; - static TReqProc new_fluid_synth; - static TReqProc delete_fluid_synth; - static TReqProc delete_fluid_settings; - static TReqProc fluid_settings_setnum; - static TReqProc fluid_settings_setstr; - static TReqProc fluid_settings_setint; - static TReqProc fluid_settings_getint; - static TReqProc fluid_synth_set_reverb_on; - static TReqProc fluid_synth_set_chorus_on; - static TReqProc fluid_synth_set_interp_method; - static TReqProc fluid_synth_set_polyphony; - static TReqProc fluid_synth_get_polyphony; - static TReqProc fluid_synth_get_active_voice_count; - static TReqProc fluid_synth_get_cpu_load; - static TReqProc fluid_synth_system_reset; - static TReqProc fluid_synth_noteon; - static TReqProc fluid_synth_noteoff; - static TReqProc fluid_synth_cc; - static TReqProc fluid_synth_program_change; - static TReqProc fluid_synth_channel_pressure; - static TReqProc fluid_synth_pitch_bend; - static TReqProc fluid_synth_write_float; - static TReqProc fluid_synth_sfload; - static TReqProc fluid_synth_set_reverb; - static TReqProc fluid_synth_set_chorus; - static TReqProc fluid_synth_sysex; - - bool LoadFluidSynth(); - void UnloadFluidSynth(); -#endif -}; - - -class ADLMIDIDevice : public SoftSynthMIDIDevice -{ - struct ADL_MIDIPlayer *Renderer; -public: - ADLMIDIDevice(const char *args); - ~ADLMIDIDevice(); - - int Open(MidiCallback, void *userdata); - int GetDeviceType() const override { return MDEV_ADL; } - -protected: - - void HandleEvent(int status, int parm1, int parm2); - void HandleLongEvent(const uint8_t *data, int len); - void ComputeOutput(float *buffer, int len); - -private: - int LoadCustomBank(const char *bankfile); -}; - - -class OPNMIDIDevice : public SoftSynthMIDIDevice -{ - struct OPN2_MIDIPlayer *Renderer; -public: - OPNMIDIDevice(const char *args); - ~OPNMIDIDevice(); - - - int Open(MidiCallback, void *userdata); - int GetDeviceType() const override { return MDEV_OPN; } - -protected: - void HandleEvent(int status, int parm1, int parm2); - void HandleLongEvent(const uint8_t *data, int len); - void ComputeOutput(float *buffer, int len); - -private: - int LoadCustomBank(const char *bankfile); -}; - - // Base class for streaming MUS and MIDI files ------------------------------ enum diff --git a/src/sound/mididevices/music_adlmidi_mididevice.cpp b/src/sound/mididevices/music_adlmidi_mididevice.cpp index 061f6abab..29a098a59 100644 --- a/src/sound/mididevices/music_adlmidi_mididevice.cpp +++ b/src/sound/mididevices/music_adlmidi_mididevice.cpp @@ -38,6 +38,27 @@ #include "adlmidi/adlmidi.h" #include "i_soundfont.h" +class ADLMIDIDevice : public SoftSynthMIDIDevice +{ + struct ADL_MIDIPlayer *Renderer; +public: + ADLMIDIDevice(const char *args); + ~ADLMIDIDevice(); + + int Open(MidiCallback, void *userdata); + int GetDeviceType() const override { return MDEV_ADL; } + +protected: + + void HandleEvent(int status, int parm1, int parm2); + void HandleLongEvent(const uint8_t *data, int len); + void ComputeOutput(float *buffer, int len); + +private: + int LoadCustomBank(const char *bankfile); +}; + + enum { ME_NOTEOFF = 0x80, @@ -267,3 +288,15 @@ void ADLMIDIDevice::ComputeOutput(float *buffer, int len) } } +//========================================================================== +// +// +// +//========================================================================== + +MIDIDevice *CreateADLMIDIDevice(const char *args) +{ + return new ADLMIDIDevice(args); +} + + diff --git a/src/sound/mididevices/music_fluidsynth_mididevice.cpp b/src/sound/mididevices/music_fluidsynth_mididevice.cpp index be2229807..a83d59e11 100644 --- a/src/sound/mididevices/music_fluidsynth_mididevice.cpp +++ b/src/sound/mididevices/music_fluidsynth_mididevice.cpp @@ -41,6 +41,75 @@ #include "i_soundfont.h" #include "doomerrors.h" +// FluidSynth implementation of a MIDI device ------------------------------- + +#ifndef DYN_FLUIDSYNTH +#include +#else +#include "i_module.h" +extern FModule FluidSynthModule; + +struct fluid_settings_t; +struct fluid_synth_t; +#endif + +class FluidSynthMIDIDevice : public SoftSynthMIDIDevice +{ +public: + FluidSynthMIDIDevice(const char *args, int samplerate); + ~FluidSynthMIDIDevice(); + + int Open(MidiCallback, void *userdata); + FString GetStats(); + void FluidSettingInt(const char *setting, int value); + void FluidSettingNum(const char *setting, double value); + void FluidSettingStr(const char *setting, const char *value); + int GetDeviceType() const override { return MDEV_FLUIDSYNTH; } + +protected: + void HandleEvent(int status, int parm1, int parm2); + void HandleLongEvent(const uint8_t *data, int len); + void ComputeOutput(float *buffer, int len); + int LoadPatchSets(const char *patches); + + fluid_settings_t *FluidSettings; + fluid_synth_t *FluidSynth; + +#ifdef DYN_FLUIDSYNTH + enum { FLUID_FAILED = -1, FLUID_OK = 0 }; + static TReqProc new_fluid_settings; + static TReqProc new_fluid_synth; + static TReqProc delete_fluid_synth; + static TReqProc delete_fluid_settings; + static TReqProc fluid_settings_setnum; + static TReqProc fluid_settings_setstr; + static TReqProc fluid_settings_setint; + static TReqProc fluid_settings_getint; + static TReqProc fluid_synth_set_reverb_on; + static TReqProc fluid_synth_set_chorus_on; + static TReqProc fluid_synth_set_interp_method; + static TReqProc fluid_synth_set_polyphony; + static TReqProc fluid_synth_get_polyphony; + static TReqProc fluid_synth_get_active_voice_count; + static TReqProc fluid_synth_get_cpu_load; + static TReqProc fluid_synth_system_reset; + static TReqProc fluid_synth_noteon; + static TReqProc fluid_synth_noteoff; + static TReqProc fluid_synth_cc; + static TReqProc fluid_synth_program_change; + static TReqProc fluid_synth_channel_pressure; + static TReqProc fluid_synth_pitch_bend; + static TReqProc fluid_synth_write_float; + static TReqProc fluid_synth_sfload; + static TReqProc fluid_synth_set_reverb; + static TReqProc fluid_synth_set_chorus; + static TReqProc fluid_synth_sysex; + + bool LoadFluidSynth(); + void UnloadFluidSynth(); +#endif +}; + // MACROS ------------------------------------------------------------------ #ifdef DYN_FLUIDSYNTH @@ -742,6 +811,17 @@ void FluidSynthMIDIDevice::UnloadFluidSynth() FluidSynthModule.Unload(); } +//========================================================================== +// +// +// +//========================================================================== + +MIDIDevice *CreateFluidSynthMIDIDevice(const char *args, int samplerate) +{ + return new FluidSynthMIDIDevice(args, samplerate); +} + #endif diff --git a/src/sound/mididevices/music_opnmidi_mididevice.cpp b/src/sound/mididevices/music_opnmidi_mididevice.cpp index 60a9e6167..ed308554e 100644 --- a/src/sound/mididevices/music_opnmidi_mididevice.cpp +++ b/src/sound/mididevices/music_opnmidi_mididevice.cpp @@ -40,6 +40,27 @@ #include "opnmidi/opnmidi.h" #include "i_soundfont.h" +class OPNMIDIDevice : public SoftSynthMIDIDevice +{ + struct OPN2_MIDIPlayer *Renderer; +public: + OPNMIDIDevice(const char *args); + ~OPNMIDIDevice(); + + + int Open(MidiCallback, void *userdata); + int GetDeviceType() const override { return MDEV_OPN; } + +protected: + void HandleEvent(int status, int parm1, int parm2); + void HandleLongEvent(const uint8_t *data, int len); + void ComputeOutput(float *buffer, int len); + +private: + int LoadCustomBank(const char *bankfile); +}; + + enum { ME_NOTEOFF = 0x80, @@ -255,3 +276,16 @@ void OPNMIDIDevice::ComputeOutput(float *buffer, int len) OPN2_UInt8* right = reinterpret_cast(buffer + 1); opn2_generateFormat(Renderer, len * 2, left, right, &audio_output_format); } + +//========================================================================== +// +// +// +//========================================================================== + +MIDIDevice *CreateOPNMIDIDevice(const char *args) +{ + return new OPNMIDIDevice(args); +} + + diff --git a/src/sound/mididevices/music_timidity_mididevice.cpp b/src/sound/mididevices/music_timidity_mididevice.cpp index 0022f527a..b9ce33d6f 100644 --- a/src/sound/mididevices/music_timidity_mididevice.cpp +++ b/src/sound/mididevices/music_timidity_mididevice.cpp @@ -52,6 +52,30 @@ // PRIVATE DATA DEFINITIONS ------------------------------------------------ +// Internal TiMidity MIDI device -------------------------------------------- + +namespace Timidity { struct Renderer; } + +class TimidityMIDIDevice : public SoftSynthMIDIDevice +{ +public: + TimidityMIDIDevice(const char *args, int samplerate); + ~TimidityMIDIDevice(); + + int Open(MidiCallback, void *userdata); + void PrecacheInstruments(const uint16_t *instruments, int count); + FString GetStats(); + int GetDeviceType() const override { return MDEV_GUS; } + +protected: + Timidity::Renderer *Renderer; + + void HandleEvent(int status, int parm1, int parm2); + void HandleLongEvent(const uint8_t *data, int len); + void ComputeOutput(float *buffer, int len); +}; + + // PUBLIC DATA DEFINITIONS ------------------------------------------------- // CODE -------------------------------------------------------------------- @@ -214,3 +238,15 @@ FString TimidityMIDIDevice::GetStats() } return out; } + +//========================================================================== +// +// +// +//========================================================================== + +MIDIDevice *CreateTimidityMIDIDevice(const char *args, int samplerate) +{ + return new TimidityMIDIDevice(args, samplerate); +} + diff --git a/src/sound/mididevices/music_wildmidi_mididevice.cpp b/src/sound/mididevices/music_wildmidi_mididevice.cpp index 235110044..f294fecfa 100644 --- a/src/sound/mididevices/music_wildmidi_mididevice.cpp +++ b/src/sound/mididevices/music_wildmidi_mididevice.cpp @@ -41,6 +41,31 @@ // TYPES ------------------------------------------------------------------- +// WildMidi implementation of a MIDI device --------------------------------- + +class WildMIDIDevice : public SoftSynthMIDIDevice +{ +public: + WildMIDIDevice(const char *args, int samplerate); + ~WildMIDIDevice(); + + int Open(MidiCallback, void *userdata); + void PrecacheInstruments(const uint16_t *instruments, int count); + FString GetStats(); + int GetDeviceType() const override { return MDEV_WILDMIDI; } + +protected: + WildMidi_Renderer *Renderer; + + void HandleEvent(int status, int parm1, int parm2); + void HandleLongEvent(const uint8_t *data, int len); + void ComputeOutput(float *buffer, int len); + void WildMidiSetOption(int opt, int set); +}; + + + + // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- @@ -231,3 +256,15 @@ void WildMIDIDevice::WildMidiSetOption(int opt, int set) { Renderer->SetOption(opt, set); } + +//========================================================================== +// +// +// +//========================================================================== + +MIDIDevice *CreateWildMIDIDevice(const char *args, int samplerate) +{ + return new WildMIDIDevice(args, samplerate); +} + diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index ce0c82684..63206c622 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -47,6 +47,16 @@ // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- +#ifdef _WIN32 +MIDIDevice *CreateWinMIDIDevice(int mididevice); +#endif +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 *CreateOPNMIDIDevice(const char *args); +MIDIDevice *CreateWildMIDIDevice(const char *args, int samplerate); + // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- @@ -197,15 +207,15 @@ MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype, int samplerate) switch (devtype) { case MDEV_GUS: - dev = new TimidityMIDIDevice(Args, samplerate); + dev = CreateTimidityMIDIDevice(Args, samplerate); break; case MDEV_ADL: - dev = new ADLMIDIDevice(Args); + dev = CreateADLMIDIDevice(Args); break; case MDEV_OPN: - dev = new OPNMIDIDevice(Args); + dev = CreateOPNMIDIDevice(Args); break; case MDEV_MMAPI: @@ -217,7 +227,7 @@ MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype, int samplerate) // Intentional fall-through for non-Windows systems. case MDEV_FLUIDSYNTH: - dev = new FluidSynthMIDIDevice(Args, samplerate); + dev = CreateFluidSynthMIDIDevice(Args, samplerate); break; case MDEV_OPL: @@ -229,7 +239,7 @@ MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype, int samplerate) break; case MDEV_WILDMIDI: - dev = new WildMIDIDevice(Args, samplerate); + dev = CreateWildMIDIDevice(Args, samplerate); break; default: