From 15113ea56d68018262c6a74a0e681aab2f30c8a9 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Fri, 11 Oct 2024 11:21:15 -0400 Subject: [PATCH] AUv2 responds to request_resize if you call ::gui_request_resize in the auv2 we now pass that to the [window setFramSize:] selector. --- cmake/wrap_auv2.cmake | 1 + src/detail/auv2/auv2_base_classes.h | 5 ++++- src/detail/auv2/auv2_shared.h | 6 ++++-- src/detail/auv2/auv2_shared.mm | 19 +++++++++++++++++++ src/detail/auv2/wrappedview.asinclude.mm | 6 +++++- src/wrapasauv2.cpp | 3 +-- 6 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/detail/auv2/auv2_shared.mm diff --git a/cmake/wrap_auv2.cmake b/cmake/wrap_auv2.cmake index 0f6f7c2a..7fa11f65 100644 --- a/cmake/wrap_auv2.cmake +++ b/cmake/wrap_auv2.cmake @@ -182,6 +182,7 @@ function(target_add_auv2_wrapper) target_sources(${AUV2_TARGET} PRIVATE ${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/wrapasauv2.cpp ${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/auv2_shared.h + ${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/auv2_shared.mm ${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/auv2_base_classes.h ${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/process.h ${CLAP_WRAPPER_CMAKE_CURRENT_SOURCE_DIR}/src/detail/auv2/process.cpp diff --git a/src/detail/auv2/auv2_base_classes.h b/src/detail/auv2/auv2_base_classes.h index 9b9f661d..84726ddf 100644 --- a/src/detail/auv2/auv2_base_classes.h +++ b/src/detail/auv2/auv2_base_classes.h @@ -244,6 +244,8 @@ class WrapAsAUV2 : public ausdk::AUBase, private: AUV2_Type _autype; + ui_connection _uiconn; + bool initializeClapDesc(); public: @@ -403,7 +405,8 @@ class WrapAsAUV2 : public ausdk::AUBase, } bool gui_request_resize(uint32_t width, uint32_t height) override { - return false; + extern bool auv2shared_mm_request_resize(const clap_window_t*, uint32_t, uint32_t); + return auv2shared_mm_request_resize(_uiconn._window, width, height); } bool gui_request_show() override { diff --git a/src/detail/auv2/auv2_shared.h b/src/detail/auv2/auv2_shared.h index 248e167b..dd34fe0a 100644 --- a/src/detail/auv2/auv2_shared.h +++ b/src/detail/auv2/auv2_shared.h @@ -13,6 +13,7 @@ */ #include +#include #include "clap_proxy.h" #include @@ -24,8 +25,9 @@ namespace free_audio::auv2_wrapper typedef struct ui_connection { uint32_t identifier = kAudioUnitProperty_ClapWrapper_UIConnection_id; - Clap::Plugin* _plugin = nullptr; - clap_window_t* _window = nullptr; + Clap::Plugin *_plugin = nullptr; + clap_window_t *_window = nullptr; + std::function _registerWindow = nullptr; } ui_connection; } // namespace free_audio::auv2_wrapper diff --git a/src/detail/auv2/auv2_shared.mm b/src/detail/auv2/auv2_shared.mm new file mode 100644 index 00000000..cee7c208 --- /dev/null +++ b/src/detail/auv2/auv2_shared.mm @@ -0,0 +1,19 @@ + +#include +#include +#include + +#include + +namespace free_audio::auv2_wrapper +{ +bool auv2shared_mm_request_resize(const clap_window_t* win, uint32_t w, uint32_t h) +{ + if (!win) return false; + + auto* nsv = (NSView*)win; + [nsv setFrameSize:NSMakeSize(w, h)]; + + return false; +} +} // namespace free_audio::auv2_wrapper diff --git a/src/detail/auv2/wrappedview.asinclude.mm b/src/detail/auv2/wrappedview.asinclude.mm index ecf9c185..0d98cd6e 100644 --- a/src/detail/auv2/wrappedview.asinclude.mm +++ b/src/detail/auv2/wrappedview.asinclude.mm @@ -86,6 +86,10 @@ - (id)initWithAUv2:(free_audio::auv2_wrapper::ui_connection *)cont preferredSize LOGINFO("[clap-wrapper] creating NSView"); ui = *cont; + if (ui._registerWindow) + { + ui._registerWindow((clap_window_t *)self); + } ui._plugin->_ext._gui->create(ui._plugin->_plugin, CLAP_WINDOW_API_COCOA, false); auto gui = ui._plugin->_ext._gui; @@ -111,7 +115,7 @@ - (id)initWithAUv2:(free_audio::auv2_wrapper::ui_connection *)cont preferredSize gui->set_parent(ui._plugin->_plugin, &m); gui->set_scale(ui._plugin->_plugin, 1.0); - if (gui->can_resize(ui._plugin->_plugin)) + if (gui->can_resize(ui._plugin->_plugin)) { clap_gui_resize_hints_t resize_hints; gui->get_resize_hints(ui._plugin->_plugin, &resize_hints); diff --git a/src/wrapasauv2.cpp b/src/wrapasauv2.cpp index 730960ab..4b3adf3b 100644 --- a/src/wrapasauv2.cpp +++ b/src/wrapasauv2.cpp @@ -627,8 +627,6 @@ OSStatus WrapAsAUV2::GetPropertyInfo(AudioUnitPropertyID inID, AudioUnitScope in return Base::GetPropertyInfo(inID, inScope, inElement, outDataSize, outWritable); } -ui_connection _uiconn; - OSStatus WrapAsAUV2::GetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, void* outData) { @@ -673,6 +671,7 @@ OSStatus WrapAsAUV2::GetProperty(AudioUnitPropertyID inID, AudioUnitScope inScop case kAudioUnitProperty_ClapWrapper_UIConnection_id: _uiconn._plugin = _plugin.get(); _uiconn._window = nullptr; + _uiconn._registerWindow = [this](auto* x) { this->_uiconn._window = x; }; *static_cast(outData) = _uiconn; return noErr;