diff --git a/include/soul/patch/helper_classes/soul_patch_Blueprint.h b/include/soul/patch/helper_classes/soul_patch_Blueprint.h index fd461f9..418d728 100644 --- a/include/soul/patch/helper_classes/soul_patch_Blueprint.h +++ b/include/soul/patch/helper_classes/soul_patch_Blueprint.h @@ -93,22 +93,28 @@ struct BlueprintEditorComponent : public juce::AudioProcessorEditor, startTimerHz (30); } + template + juce::var call (MethodType method, const juce::var::NativeFunctionArgs& args) + { + if (args.numArguments != numParams) + return juce::var::undefined(); + + if constexpr (numParams == 0) return (this->*method)(); + if constexpr (numParams == 1) return (this->*method) (args.arguments[0]); + if constexpr (numParams == 2) return (this->*method) (args.arguments[0], args.arguments[1]); + if constexpr (numParams == 3) return (this->*method) (args.arguments[0], args.arguments[1], args.arguments[2]); + if constexpr (numParams == 4) return (this->*method) (args.arguments[0], args.arguments[1], args.arguments[2], args.arguments[3]); + static_assert (numParams <= 4); + return {}; + } + template void addMethodBinding (const char* name, MethodType method) { reactRootComponent.engine.registerNativeMethod (name, [this, method] (const juce::var::NativeFunctionArgs& args) -> juce::var { - if (args.numArguments != numParams) - return juce::var::undefined(); - - if constexpr (numParams == 0) return (this->*method)(); - if constexpr (numParams == 1) return (this->*method) (args.arguments[0]); - if constexpr (numParams == 2) return (this->*method) (args.arguments[0], args.arguments[1]); - if constexpr (numParams == 3) return (this->*method) (args.arguments[0], args.arguments[1], args.arguments[2]); - if constexpr (numParams == 4) return (this->*method) (args.arguments[0], args.arguments[1], args.arguments[2], args.arguments[3]); - static_assert (numParams <= 4); - return {}; + return call (method, args); }); }