Skip to content
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
24 changes: 24 additions & 0 deletions src/wrapasvst3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <locale>
#include <sstream>

// we need this lock free since we can request a gui resize from any thread in CLAP
static_assert(std::atomic<uint32_t>::is_always_lock_free,
"compiler must ensure that std::atomic<uint32_t> is lock free");

#if WIN
#include <tchar.h>
#define S16(x) reinterpret_cast<const Steinberg::Vst::TChar*>(_T(x))
Expand Down Expand Up @@ -1106,6 +1110,16 @@ bool ClapAsVst3::gui_can_resize()

bool ClapAsVst3::gui_request_resize(uint32_t width, uint32_t height)
{
// UIs with 65kx65k resolution are not supported
if ((width > 0xffff) || (height > 0xffff)) return false;

if (_main_thread_id != std::this_thread::get_id())
{
uint32_t newSize = ((width & 0xffff) << 16) | (height & 0xffff);
_gui_resize_request.store(newSize);
return true;
}

if (_wrappedview)
return _wrappedview->request_resize(width, height);
else
Expand Down Expand Up @@ -1292,6 +1306,16 @@ void ClapAsVst3::onIdle()
_plugin->_plugin->on_main_thread(_plugin->_plugin);
}

if (_wrappedview)
{
if (auto const size = _gui_resize_request.exchange(_gui_invalid_size); size != _gui_invalid_size)
{
auto w = (size >> 16) & 0xffff;
auto h = (size & 0xffff);
_wrappedview->request_resize(w, 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
6 changes: 6 additions & 0 deletions src/wrapasvst3.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include "detail/vst3/aravst3.h"
#include "detail/shared/spinlock.h"
#include <mutex>
#include <thread>
#include <atomic>

using namespace Steinberg;

Expand Down Expand Up @@ -386,6 +388,10 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect,
std::atomic_bool _requestUICallback = false;
bool _missedLatencyRequest = false;

std::thread::id _main_thread_id{};
static const uint32_t _gui_invalid_size = 0xffffffff;
std::atomic<uint32_t> _gui_resize_request = _gui_invalid_size;

// the queue from audiothread to UI thread
ClapWrapper::detail::shared::fixedqueue<queueEvent, 8192> _queueToUI;

Expand Down
Loading