Skip to content

Commit

Permalink
VST2 Host: Avoid C-style casts of function pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
reuk committed Nov 21, 2024
1 parent 6e910d8 commit 73cb3b8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2156,6 +2155,20 @@ struct VSTPluginInstance final : public AudioPluginInstance,
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
}
Expand Down Expand Up @@ -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() {}
Expand Down

0 comments on commit 73cb3b8

Please sign in to comment.