From 7c14010656ca7e3594d66c7419f0f061782aded3 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 12 Mar 2023 17:12:59 +0100 Subject: [PATCH] Keep track of the current latency in standalones Even though it's not actually used, this avoids spamming the debug assertion failure when the value doesn't change. --- src/wrapper/standalone/context.rs | 8 ++++---- src/wrapper/standalone/wrapper.rs | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/wrapper/standalone/context.rs b/src/wrapper/standalone/context.rs index 4329ac12..7ce8b185 100644 --- a/src/wrapper/standalone/context.rs +++ b/src/wrapper/standalone/context.rs @@ -48,8 +48,8 @@ impl> InitContext

for WrapperInitContext<'_, P, B> { (self.wrapper.task_executor.lock())(task); } - fn set_latency_samples(&self, _samples: u32) { - nih_debug_assert_failure!("TODO: WrapperInitContext::set_latency_samples()"); + fn set_latency_samples(&self, samples: u32) { + self.wrapper.set_latency_samples(samples) } fn set_current_voice_capacity(&self, _capacity: u32) { @@ -93,8 +93,8 @@ impl> ProcessContext

for WrapperProcessContext<'_, P self.output_events.push(event); } - fn set_latency_samples(&self, _samples: u32) { - nih_debug_assert_failure!("TODO: WrapperProcessContext::set_latency_samples()"); + fn set_latency_samples(&self, samples: u32) { + self.wrapper.set_latency_samples(samples) } fn set_current_voice_capacity(&self, _capacity: u32) { diff --git a/src/wrapper/standalone/wrapper.rs b/src/wrapper/standalone/wrapper.rs index 3d5ad7c7..0f870676 100644 --- a/src/wrapper/standalone/wrapper.rs +++ b/src/wrapper/standalone/wrapper.rs @@ -6,7 +6,7 @@ use parking_lot::Mutex; use raw_window_handle::HasRawWindowHandle; use std::any::Any; use std::collections::{HashMap, HashSet}; -use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::sync::Arc; use std::thread; @@ -86,6 +86,11 @@ pub struct Wrapper> { updated_state_sender: channel::Sender, /// The receiver belonging to [`new_state_sender`][Self::new_state_sender]. updated_state_receiver: channel::Receiver, + /// The current latency in samples, as set by the plugin through the [`InitContext`] and the + /// [`ProcessContext`]. This value may not be used depending on the audio backend, but it's + /// still kept track of to avoid firing debug assertions multiple times for the same latency + /// value. + current_latency: AtomicU32, } /// Tasks that can be sent from the plugin to be executed on the main thread in a non-blocking @@ -250,6 +255,7 @@ impl> Wrapper { unprocessed_param_changes: ArrayQueue::new(EVENT_QUEUE_CAPACITY), updated_state_sender, updated_state_receiver, + current_latency: AtomicU32::new(0), }); *wrapper.event_loop.borrow_mut() = @@ -475,6 +481,15 @@ impl> Wrapper { } } + pub fn set_latency_samples(&self, samples: u32) { + // This should only change the value if it's actually needed + let old_latency = self.current_latency.swap(samples, Ordering::SeqCst); + if old_latency != samples { + // None of the backends actually support this at the moment + nih_debug_assert_failure!("Standalones currently don't support latency reporting"); + } + } + /// The audio thread. This should be called from another thread, and it will run until /// `should_terminate` is `true`. fn run_audio_thread(