From 6e910d801050e017a590a7ac2d0d2f3ea0bd187f Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 18 Nov 2024 13:32:00 +0000 Subject: [PATCH] VST2 Client: Avoid C-style casts of function pointers --- .../juce_audio_plugin_client_VST2.cpp | 87 ++++++++++--------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST2.cpp b/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST2.cpp index f3702c6c95c..629185e1b6c 100644 --- a/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST2.cpp +++ b/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST2.cpp @@ -274,10 +274,38 @@ class JuceVSTWrapper final : public AudioProcessorListener, memset (&vstEffect, 0, sizeof (vstEffect)); vstEffect.magic = 0x56737450 /* 'VstP' */; - vstEffect.dispatcher = (Vst2::AEffectDispatcherProc) dispatcherCB; + vstEffect.dispatcher = [] (Vst2::AEffect* vstInterface, + Vst2::VstInt32 opCode, + Vst2::VstInt32 index, + Vst2::VstIntPtr value, + void* ptr, + float opt) -> Vst2::VstIntPtr + { + auto* wrapper = getWrapper (vstInterface); + VstOpCodeArguments args = { index, value, ptr, opt }; + + if (opCode == Vst2::effClose) + { + wrapper->dispatcher (opCode, args); + delete wrapper; + return 1; + } + + return wrapper->dispatcher (opCode, args); + }; + vstEffect.process = nullptr; - vstEffect.setParameter = (Vst2::AEffectSetParameterProc) setParameterCB; - vstEffect.getParameter = (Vst2::AEffectGetParameterProc) getParameterCB; + + vstEffect.setParameter = [] (Vst2::AEffect* vstInterface, Vst2::VstInt32 index, float value) + { + getWrapper (vstInterface)->setParameter (index, value); + }; + + vstEffect.getParameter = [] (Vst2::AEffect* vstInterface, Vst2::VstInt32 index) -> float + { + return getWrapper (vstInterface)->getParameter (index); + }; + vstEffect.numPrograms = jmax (1, processor->getNumPrograms()); vstEffect.numParams = juceParameters.getNumParameters(); vstEffect.numInputs = maxNumInChannels; @@ -292,8 +320,21 @@ class JuceVSTWrapper final : public AudioProcessorListener, vstEffect.version = JucePlugin_VersionCode; #endif - vstEffect.processReplacing = (Vst2::AEffectProcessProc) processReplacingCB; - vstEffect.processDoubleReplacing = (Vst2::AEffectProcessDoubleProc) processDoubleReplacingCB; + vstEffect.processReplacing = [] (Vst2::AEffect* vstInterface, + float** inputs, + float** outputs, + Vst2::VstInt32 sampleFrames) + { + getWrapper (vstInterface)->processReplacing (inputs, outputs, sampleFrames); + }; + + vstEffect.processDoubleReplacing = [] (Vst2::AEffect* vstInterface, + double** inputs, + double** outputs, + Vst2::VstInt32 sampleFrames) + { + getWrapper (vstInterface)->processDoubleReplacing (inputs, outputs, sampleFrames); + }; vstEffect.flags |= Vst2::effFlagsHasEditor; @@ -505,22 +546,12 @@ class JuceVSTWrapper final : public AudioProcessorListener, internalProcessReplacing (inputs, outputs, sampleFrames, floatTempBuffers); } - static void processReplacingCB (Vst2::AEffect* vstInterface, float** inputs, float** outputs, int32 sampleFrames) - { - getWrapper (vstInterface)->processReplacing (inputs, outputs, sampleFrames); - } - void processDoubleReplacing (double** inputs, double** outputs, int32 sampleFrames) { jassert (processor->isUsingDoublePrecision()); internalProcessReplacing (inputs, outputs, sampleFrames, doubleTempBuffers); } - static void processDoubleReplacingCB (Vst2::AEffect* vstInterface, double** inputs, double** outputs, int32 sampleFrames) - { - getWrapper (vstInterface)->processDoubleReplacing (inputs, outputs, sampleFrames); - } - //============================================================================== void resume() { @@ -678,22 +709,12 @@ class JuceVSTWrapper final : public AudioProcessorListener, return 0.0f; } - static float getParameterCB (Vst2::AEffect* vstInterface, int32 index) - { - return getWrapper (vstInterface)->getParameter (index); - } - void setParameter (int32 index, float value) { if (auto* param = juceParameters.getParamForIndex (index)) setValueAndNotifyIfChanged (*param, value); } - static void setParameterCB (Vst2::AEffect* vstInterface, int32 index, float value) - { - getWrapper (vstInterface)->setParameter (index, value); - } - void audioProcessorParameterChanged (AudioProcessor*, int index, float newValue) override { if (inParameterChangedCallback.get()) @@ -902,22 +923,6 @@ class JuceVSTWrapper final : public AudioProcessorListener, } } - static pointer_sized_int dispatcherCB (Vst2::AEffect* vstInterface, int32 opCode, int32 index, - pointer_sized_int value, void* ptr, float opt) - { - auto* wrapper = getWrapper (vstInterface); - VstOpCodeArguments args = { index, value, ptr, opt }; - - if (opCode == Vst2::effClose) - { - wrapper->dispatcher (opCode, args); - delete wrapper; - return 1; - } - - return wrapper->dispatcher (opCode, args); - } - //============================================================================== // A component to hold the AudioProcessorEditor, and cope with some housekeeping // chores when it changes or repaints.