From 45b69bc01f77c848c745f0808df322a6d2a64858 Mon Sep 17 00:00:00 2001 From: David Schornsheim Date: Mon, 26 Feb 2024 12:17:35 +0100 Subject: [PATCH] Store missed latency call and report after activate() --- src/wrapasvst3.cpp | 19 ++++++++++++++++--- src/wrapasvst3.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/wrapasvst3.cpp b/src/wrapasvst3.cpp index 234c742f..a699b410 100644 --- a/src/wrapasvst3.cpp +++ b/src/wrapasvst3.cpp @@ -87,6 +87,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) @@ -132,11 +137,19 @@ 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() diff --git a/src/wrapasvst3.h b/src/wrapasvst3.h index 7ce4f8c2..dca1a788 100644 --- a/src/wrapasvst3.h +++ b/src/wrapasvst3.h @@ -259,6 +259,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;