Skip to content
Closed
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
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 <thread>
#include <iostream>

WrappedView::WrappedView(const clap_plugin_t* plugin, const clap_plugin_gui_t* gui,
Expand Down Expand Up @@ -103,6 +104,8 @@ tresult PLUGIN_API WrappedView::isPlatformTypeSupported(FIDString type)

tresult PLUGIN_API WrappedView::attached(void* parent, FIDString /*type*/)
{
_main_thread_id = std::this_thread::get_id();

#if WIN
_window = {CLAP_WINDOW_API_WIN32, {parent}};
#endif
Expand Down Expand Up @@ -259,6 +262,12 @@ tresult PLUGIN_API WrappedView::checkSizeConstraint(ViewRect* rect)

bool WrappedView::request_resize(uint32_t width, uint32_t height)
{
if (_main_thread_id != std::this_thread::get_id())
{
resize_request = {width, height};
return true;
}

auto oldrect = _rect;
_rect.right = _rect.left + (int32)width;
_rect.bottom = _rect.top + (int32)height;
Expand All @@ -268,6 +277,7 @@ bool WrappedView::request_resize(uint32_t width, uint32_t height)
_rect = oldrect;
return false;
}

return true;
}
tresult WrappedView::setContentScaleFactor(IPlugViewContentScaleSupport::ScaleFactor factor)
Expand Down
19 changes: 19 additions & 0 deletions src/detail/vst3/plugview.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <pluginterfaces/gui/iplugviewcontentscalesupport.h>
#include <clap/clap.h>
#include <functional>
#include <thread>
#include <atomic>

using namespace Steinberg;

Expand Down Expand Up @@ -94,6 +96,22 @@ class WrappedView : public Steinberg::IPlugView,
// wrapper needed interfaces
bool request_resize(uint32_t width, uint32_t height);

// processed in ClapAsVst3::onIdle()
struct GuiResizeRequest
{
bool operator==(GuiResizeRequest const& other) const
{
return w == other.w && h == other.h;
}
bool operator!=(GuiResizeRequest const& other) const
{
return w != other.w || h != other.h;
}
uint32_t w, h;
};
constexpr static GuiResizeRequest invalid_size = {(uint32_t)-1, (uint32_t)-1};
std::atomic<GuiResizeRequest> resize_request{invalid_size};

private:
void ensure_ui();
void drop_ui();
Expand All @@ -107,6 +125,7 @@ class WrappedView : public Steinberg::IPlugView,
ViewRect _rect = {0, 0, 0, 0};
bool _created = false;
bool _attached = false;
std::thread::id _main_thread_id{};

#if LIN
public:
Expand Down
10 changes: 10 additions & 0 deletions src/wrapasvst3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "detail/vst3/process.h"
#include "detail/vst3/parameter.h"
#include "detail/clap/fsutil.h"
#include <atomic>
#include <locale>
#include <sstream>

Expand Down Expand Up @@ -1292,6 +1293,15 @@ void ClapAsVst3::onIdle()
_plugin->_plugin->on_main_thread(_plugin->_plugin);
}

if (_wrappedview)
{
if (auto const size = _wrappedview->resize_request.exchange(WrappedView::invalid_size);
size != WrappedView::invalid_size)
{
_wrappedview->request_resize(size.w, size.h);
}
}

#if LIN
if (!_iRunLoop) // don't process timers if we have a runloop.
// (but if we don't have a runloop on linux onIdle isn't called
Expand Down
Loading