From 244adf1647d7d417cb15e10a699361c706d50aa2 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 13 Feb 2024 12:41:51 -0500 Subject: [PATCH] Apply latency active patch (#59) Authored by David Schornsheim Reviewed by abique and me --- include/clap/helpers/plugin.hh | 1 + include/clap/helpers/plugin.hxx | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/clap/helpers/plugin.hh b/include/clap/helpers/plugin.hh index 28a1989..2ed3f32 100644 --- a/include/clap/helpers/plugin.hh +++ b/include/clap/helpers/plugin.hh @@ -550,6 +550,7 @@ namespace clap { namespace helpers { // state bool _wasInitialized = false; bool _isActive = false; + bool _isBeingActivated = false; bool _isProcessing = false; bool _isBeingDestroyed = false; double _sampleRate = 0; diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index c73aaaf..db8d4b2 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -319,12 +319,15 @@ namespace clap { namespace helpers { assert(!self._isActive); assert(self._sampleRate == 0); + self._isBeingActivated = true; if (!self.activate(sample_rate, minFrameCount, maxFrameCount)) { + self._isBeingActivated = false; assert(!self._isActive); assert(self._sampleRate == 0); return false; } + self._isBeingActivated = false; self._isActive = true; self._sampleRate = sample_rate; return true; @@ -506,7 +509,7 @@ namespace clap { namespace helpers { self.ensureMainThread("clap_plugin_latency.get"); if (l >= CheckingLevel::Minimal) { - if (!self._isActive) + if (!self._isActive && !self._isBeingActivated) self.hostMisbehaving("It is wrong to query the latency before the plugin is activated, " "because if the plugin dosen't know the sample rate, it can't " "know the number of samples of latency.");