diff --git a/lv2/sfizz_ui.cpp b/lv2/sfizz_ui.cpp index 069d4942..b7fe308b 100644 --- a/lv2/sfizz_ui.cpp +++ b/lv2/sfizz_ui.cpp @@ -374,6 +374,9 @@ lv2ui_descriptor(uint32_t index) #if LINUX VSTGUI::initializeSoHandle(); #endif +#if MAC + VSTGUI::initializeBundleRef(); +#endif switch (index) { diff --git a/lv2/vstgui_helpers.cpp b/lv2/vstgui_helpers.cpp index 43ff0901..d1ad3187 100644 --- a/lv2/vstgui_helpers.cpp +++ b/lv2/vstgui_helpers.cpp @@ -18,6 +18,9 @@ #if WINDOWS #include #endif +#if MAC +#include "vstgui/plugin-bindings/getpluginbundle.h" +#endif #if LINUX void Lv2IdleRunLoop::execIdle() @@ -184,3 +187,38 @@ BOOL WINAPI DllMain(HINSTANCE dllInstance, DWORD reason, LPVOID) return TRUE; } #endif + +/// +#if MAC +namespace VSTGUI +{ +void* gBundleRef = nullptr; + +static volatile bool gBundleRefInitialized = false; +static std::mutex gBundleRefMutex; + +struct CFBundle_deleter { + void operator()(CFBundleRef x) const noexcept + { + CFRelease(x); + } +}; +static std::unique_ptr<__CFBundle, CFBundle_deleter> gBundleRefPointer; +} // namespace VSTGUI + +void VSTGUI::initializeBundleRef() +{ + if (VSTGUI::gBundleRefInitialized) + return; + + std::lock_guard lock(VSTGUI::gBundleRefMutex); + if (VSTGUI::gBundleRefInitialized) + return; + + CFBundleRef bundleRef = GetPluginBundle(); + VSTGUI::gBundleRef = bundleRef; + VSTGUI::gBundleRefPointer.reset(bundleRef); + + VSTGUI::gBundleRefInitialized = true; +} +#endif diff --git a/lv2/vstgui_helpers.h b/lv2/vstgui_helpers.h index bb48936e..8367a2c4 100644 --- a/lv2/vstgui_helpers.h +++ b/lv2/vstgui_helpers.h @@ -66,3 +66,10 @@ namespace VSTGUI void initializeSoHandle(); } #endif + +#if MAC +namespace VSTGUI +{ +void initializeBundleRef(); +} +#endif