From 8b47f90dd7e6be82e044a2e2b0389d0c5bd4bcb7 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 25 Oct 2022 17:38:51 +0200 Subject: [PATCH] Fix setActive() in Ardour when setting latency --- src/wrapper/vst3/wrapper.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/wrapper/vst3/wrapper.rs b/src/wrapper/vst3/wrapper.rs index 70f558dd..5e1c9812 100644 --- a/src/wrapper/vst3/wrapper.rs +++ b/src/wrapper/vst3/wrapper.rs @@ -388,8 +388,23 @@ impl IComponent for Wrapper

{ param.update_smoother(buffer_config.sample_rate, true); } + // HACK: This is needed because if you change the latency during + // `IComponent::setActive(true)` then Ardour will reentrantly call + // `IComponent::setActive(true)` again during the previous call. This use of `static` + // is also fine here because the host may only call this from the main thread, so + // multiple simultaneous calls of this function are not allowed. + let mut plugin = match self.inner.plugin.try_lock() { + Some(plugin) => plugin, + None => { + nih_debug_assert_failure!( + "The host tried to call IComponent::setActive(true) while it was \ + already calling IComponent::setActive(true), returning kResultOk" + ); + return kResultOk; + } + }; + let bus_config = self.inner.current_bus_config.load(); - let mut plugin = self.inner.plugin.lock(); if plugin.initialize( &bus_config, &buffer_config,