From aee5cabf75557929e70654268dbc4da9ad9d9947 Mon Sep 17 00:00:00 2001 From: defiantnerd <97224712+defiantnerd@users.noreply.github.com> Date: Sun, 10 Mar 2024 17:32:09 +0100 Subject: [PATCH] Check active state before querying latency. Fixes #229 --- src/wrapasvst3.cpp | 25 +++++++++++++++++++++---- src/wrapasvst3.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/wrapasvst3.cpp b/src/wrapasvst3.cpp index 5f3423d6..ee37012f 100644 --- a/src/wrapasvst3.cpp +++ b/src/wrapasvst3.cpp @@ -59,6 +59,11 @@ tresult PLUGIN_API ClapAsVst3::terminate() if (_plugin) { _os_attached.off(); // ensure we are detached + if (_active) + { + // HOST has misbehaved + _plugin->deactivate(); + } _plugin->terminate(); _plugin.reset(); } @@ -87,6 +92,11 @@ tresult PLUGIN_API ClapAsVst3::setActive(TBool state) _expressionmap & clap_supported_note_expressions::AS_VST3_NOTE_EXPRESSION_TUNING); updateAudioBusses(); + if (_missedLatencyRequest) + { + latency_changed(); + } + _os_attached.on(); } if (!state) @@ -137,11 +147,18 @@ tresult PLUGIN_API ClapAsVst3::getState(IBStream* state) uint32 PLUGIN_API ClapAsVst3::getLatencySamples() { - if (_plugin->_ext._latency && _active) + if (!_plugin->_ext._latency) { - return _plugin->_ext._latency->get(_plugin->_plugin); + return 0; } - return 0; + if (!_active) + { + _missedLatencyRequest = true; + return 0; + } + + _missedLatencyRequest = false; + return _plugin->_ext._latency->get(_plugin->_plugin); } uint32 PLUGIN_API ClapAsVst3::getTailSamples() @@ -950,7 +967,7 @@ void ClapAsVst3::onIdle() std::lock_guard lock(_processingLock); _requestedFlush = false; - if (!_processing) + if (!_active) { // setup a ProcessAdapter just for flush with no audio Clap::ProcessAdapter pa; diff --git a/src/wrapasvst3.h b/src/wrapasvst3.h index df00c005..fa11b408 100644 --- a/src/wrapasvst3.h +++ b/src/wrapasvst3.h @@ -280,6 +280,7 @@ class ClapAsVst3 : public Steinberg::Vst::SingleComponentEffect, std::mutex _processingLock; std::atomic_bool _requestedFlush = false; std::atomic_bool _requestUICallback = false; + bool _missedLatencyRequest = false; // the queue from audiothread to UI thread ClapWrapper::detail::shared::fixedqueue _queueToUI;