Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUv2 responds to request_resize #318

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
{
Expand Down Expand Up @@ -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<ui_connection*>(outData) = _uiconn;
return noErr;

Expand Down
Loading