From 73cb3b88adbce84abd30ed2bef765278241d2ca1 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 18 Nov 2024 13:32:07 +0000 Subject: [PATCH] VST2 Host: Avoid C-style casts of function pointers --- .../format_types/juce_VSTPluginFormat.cpp | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp index e1c214c3cc..08b48f1f32 100644 --- a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp @@ -81,7 +81,7 @@ JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4355) #endif #ifndef JUCE_VST_WRAPPER_INVOKE_MAIN -#define JUCE_VST_WRAPPER_INVOKE_MAIN effect = module->moduleMain ((Vst2::audioMasterCallback) &audioMaster); +#define JUCE_VST_WRAPPER_INVOKE_MAIN effect = module->moduleMain (audioMaster); #endif #ifndef JUCE_VST_FALLBACK_HOST_NAME @@ -222,8 +222,7 @@ namespace } //============================================================================== -typedef Vst2::AEffect* (VSTCALLBACK *MainCall) (Vst2::audioMasterCallback); -static pointer_sized_int VSTCALLBACK audioMaster (Vst2::AEffect*, int32, int32, pointer_sized_int, void*, float); +using MainCall = Vst2::AEffect* (VSTCALLBACK*) (Vst2::audioMasterCallback); //============================================================================== // Change this to disable logging of various VST activities @@ -2156,6 +2155,20 @@ private: UseResFile (module->resFileId); #endif + constexpr Vst2::audioMasterCallback audioMaster = [] (Vst2::AEffect* eff, + Vst2::VstInt32 opcode, + Vst2::VstInt32 index, + Vst2::VstIntPtr value, + void* ptr, + float opt) -> Vst2::VstIntPtr + { + if (eff != nullptr) + if (auto* instance = (VSTPluginInstance*) (eff->resvd2)) + return instance->handleCallback (opcode, index, value, ptr, opt); + + return VSTPluginInstance::handleGeneralCallback (opcode, index, value, ptr, opt); + }; + { JUCE_VST_WRAPPER_INVOKE_MAIN } @@ -3458,15 +3471,6 @@ bool VSTPluginInstance::updateSizeFromEditor ([[maybe_unused]] int w, [[maybe_un //============================================================================== // entry point for all callbacks from the plugin -static pointer_sized_int VSTCALLBACK audioMaster (Vst2::AEffect* effect, int32 opcode, int32 index, pointer_sized_int value, void* ptr, float opt) -{ - if (effect != nullptr) - if (auto* instance = (VSTPluginInstance*) (effect->resvd2)) - return instance->handleCallback (opcode, index, value, ptr, opt); - - return VSTPluginInstance::handleGeneralCallback (opcode, index, value, ptr, opt); -} - //============================================================================== VSTPluginFormat::VSTPluginFormat() {} VSTPluginFormat::~VSTPluginFormat() {}