1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

VST2 Client: Avoid C-style casts of function pointers

This commit is contained in:
reuk 2024-11-18 13:32:00 +00:00
parent 04fa895f38
commit 6e910d8010
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -274,10 +274,38 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
}
}
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.