Skip to content

Commit

Permalink
Implement Steinberg::IPlugViewContentScaleSupport (#284)
Browse files Browse the repository at this point in the history
This passes to gui.set_scale. It's pretty critical to make VST3 and CLAP work identicially on bitwig linux.

Also add a defensive guard against malformed claps. In clap in bws resizing a destroyed gui would post a misbehaving error but in the vst3 we would crash absent this guard. Just a defensive check.

Closes #262
  • Loading branch information
baconpaul authored Aug 13, 2024
1 parent fcaa434 commit 6cecd3c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/detail/vst3/plugview.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "plugview.h"
#include <clap/clap.h>
#include <cassert>
#include <iostream>

WrappedView::WrappedView(const clap_plugin_t* plugin, const clap_plugin_gui_t* gui,
std::function<void()> onReleaseAdditionalReferences,
Expand Down Expand Up @@ -269,3 +270,12 @@ bool WrappedView::request_resize(uint32_t width, uint32_t height)
}
return true;
}
tresult WrappedView::setContentScaleFactor(IPlugViewContentScaleSupport::ScaleFactor factor)
{
ensure_ui();
if (_extgui->set_scale(_plugin, factor))
{
return kResultOk;
}
return kResultFalse;
}
8 changes: 7 additions & 1 deletion src/detail/vst3/plugview.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

#include "base/source/fobject.h"
#include <pluginterfaces/gui/iplugview.h>
#include <pluginterfaces/gui/iplugviewcontentscalesupport.h>
#include <clap/clap.h>
#include <functional>

using namespace Steinberg;

class WrappedView : public Steinberg::IPlugView, public Steinberg::FObject
class WrappedView : public Steinberg::IPlugView,
public Steinberg::IPlugViewContentScaleSupport,
public Steinberg::FObject
{
public:
WrappedView(const clap_plugin_t* plugin, const clap_plugin_gui_t* gui,
Expand Down Expand Up @@ -78,10 +81,13 @@ class WrappedView : public Steinberg::IPlugView, public Steinberg::FObject
* adjust the rect to the allowed size. */
tresult PLUGIN_API checkSizeConstraint(ViewRect* rect) override;

tresult setContentScaleFactor(ScaleFactor factor) override;

//---Interface------
OBJ_METHODS(WrappedView, FObject)
DEFINE_INTERFACES
DEF_INTERFACE(IPlugView)
DEF_INTERFACE(IPlugViewContentScaleSupport)
END_DEFINE_INTERFACES(FObject)
REFCOUNT_METHODS(FObject)

Expand Down
5 changes: 4 additions & 1 deletion src/wrapasvst3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,10 @@ bool ClapAsVst3::gui_can_resize()

bool ClapAsVst3::gui_request_resize(uint32_t width, uint32_t height)
{
return _wrappedview->request_resize(width, height);
if (_wrappedview)
return _wrappedview->request_resize(width, height);
else
return false;
}

bool ClapAsVst3::gui_request_show()
Expand Down

0 comments on commit 6cecd3c

Please sign in to comment.