Skip to content

Commit

Permalink
AUv2 responds to request_resize (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul authored Oct 11, 2024
1 parent bf887a8 commit bc32cb3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmake/wrap_auv2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/detail/auv2/auv2_base_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ class WrapAsAUV2 : public ausdk::AUBase,
private:
AUV2_Type _autype;

ui_connection _uiconn;

bool initializeClapDesc();

public:
Expand Down Expand Up @@ -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
{
Expand Down
6 changes: 4 additions & 2 deletions src/detail/auv2/auv2_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

#include <iostream>
#include <functional>
#include "clap_proxy.h"
#include <AudioToolbox/AudioUnitProperties.h>

Expand All @@ -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<void(clap_window_t *)> _registerWindow = nullptr;
} ui_connection;

} // namespace free_audio::auv2_wrapper
19 changes: 19 additions & 0 deletions src/detail/auv2/auv2_shared.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#include <clap/ext/gui.h>
#include <cstdint>
#include <iostream>

#include <Cocoa/Cocoa.h>

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
6 changes: 5 additions & 1 deletion src/detail/auv2/wrappedview.asinclude.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/wrapasauv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,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)
{
Expand Down Expand Up @@ -694,6 +692,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<ui_connection*>(outData) = _uiconn;
return noErr;

Expand Down

0 comments on commit bc32cb3

Please sign in to comment.