From 542012aa0e3cbc09ccee4d354112a8b484fa2a9b Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 3 Mar 2022 21:58:40 +0100 Subject: [PATCH] Request restart for latency change when processing Calling this change function seems to work fine, but apparently you're supposed to do it this way. --- src/wrapper/clap/wrapper.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index da650efb..8bead9db 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -265,7 +265,17 @@ impl MainThreadExecutor for Wrapper

{ // This function is always called from the main thread, from [Self::on_main_thread]. match task { Task::LatencyChanged => match &*self.host_latency.borrow() { - Some(host_latency) => (host_latency.changed)(&*self.host_callback), + Some(host_latency) => { + // XXX: The CLAP docs mention that you should request a restart if this happens + // while the plugin is activated (which is not entirely the same thing as + // is processing, but we'll treat it as the same thing). In practice just + // calling the latency changed function also seems to work just fine. + if self.is_processing.load(Ordering::SeqCst) { + (self.host_callback.request_restart)(&*self.host_callback) + } else { + (host_latency.changed)(&*self.host_callback) + } + } None => nih_debug_assert_failure!("Host does not support the latency extension"), }, };