1
0
Fork 0

Spool param rescan call to the GUI thread

Otherwise the CLAP example host std::terminates, and we can also reuse
the existing restart task for the VST3 wrapper.
This commit is contained in:
Robbert van der Helm 2022-04-07 17:22:50 +02:00
parent d0064f87d6
commit 84bac0a47c
3 changed files with 16 additions and 18 deletions

View file

@ -228,6 +228,8 @@ pub struct Wrapper<P: ClapPlugin> {
pub enum Task { pub enum Task {
/// Inform the host that the latency has changed. /// Inform the host that the latency has changed.
LatencyChanged, LatencyChanged,
/// Tell the host that it should rescan the current parameter values.
RescanParamValues,
} }
/// The types of CLAP parameter updates for events. /// The types of CLAP parameter updates for events.
@ -314,6 +316,12 @@ impl<P: ClapPlugin> MainThreadExecutor<Task> for Wrapper<P> {
} }
None => nih_debug_assert_failure!("Host does not support the latency extension"), None => nih_debug_assert_failure!("Host does not support the latency extension"),
}, },
Task::RescanParamValues => match &*self.host_params.borrow() {
Some(host_params) => {
(host_params.rescan)(&*self.host_callback, CLAP_PARAM_RESCAN_VALUES);
}
None => nih_debug_assert_failure!("The host does not support parameters? What?"),
},
}; };
} }
} }
@ -993,12 +1001,8 @@ impl<P: ClapPlugin> Wrapper<P> {
} }
// After the state has been updated, notify the host about the new parameter values // After the state has been updated, notify the host about the new parameter values
match &*self.host_params.borrow() { let task_posted = self.do_maybe_async(Task::RescanParamValues);
Some(host_params) => { nih_debug_assert!(task_posted, "The task queue is full, dropping task...");
(host_params.rescan)(&*self.host_callback, CLAP_PARAM_RESCAN_VALUES)
}
None => nih_debug_assert_failure!("The host does not support parameters? What?"),
}
} }
unsafe extern "C" fn init(plugin: *const clap_plugin) -> bool { unsafe extern "C" fn init(plugin: *const clap_plugin) -> bool {

View file

@ -2,7 +2,7 @@ use atomic_refcell::AtomicRefMut;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::sync::Arc; use std::sync::Arc;
use vst3_sys::vst::IComponentHandler; use vst3_sys::vst::{IComponentHandler, RestartFlags};
use super::inner::{Task, WrapperInner}; use super::inner::{Task, WrapperInner};
use crate::context::{GuiContext, ProcessContext, Transport}; use crate::context::{GuiContext, ProcessContext, Transport};
@ -112,9 +112,7 @@ impl<P: Vst3Plugin> ProcessContext for WrapperProcessContext<'_, P> {
let old_latency = self.inner.current_latency.swap(samples, Ordering::SeqCst); let old_latency = self.inner.current_latency.swap(samples, Ordering::SeqCst);
if old_latency != samples { if old_latency != samples {
let task_posted = unsafe { self.inner.event_loop.borrow().assume_init_ref() } let task_posted = unsafe { self.inner.event_loop.borrow().assume_init_ref() }
.do_maybe_async(Task::TriggerRestart( .do_maybe_async(Task::TriggerRestart(RestartFlags::kLatencyChanged as i32));
vst3_sys::vst::RestartFlags::kLatencyChanged as i32,
));
nih_debug_assert!(task_posted, "The task queue is full, dropping task..."); nih_debug_assert!(task_posted, "The task queue is full, dropping task...");
} }
} }

View file

@ -397,14 +397,10 @@ impl<P: Vst3Plugin> WrapperInner<P> {
} }
// After the state has been updated, notify the host about the new parameter values // After the state has been updated, notify the host about the new parameter values
match &*self.component_handler.borrow() { let task_posted = unsafe { self.event_loop.borrow().assume_init_ref() }.do_maybe_async(
Some(component_handler) => { Task::TriggerRestart(RestartFlags::kParamValuesChanged as i32),
unsafe { );
component_handler.restart_component(RestartFlags::kParamValuesChanged as i32) nih_debug_assert!(task_posted, "The task queue is full, dropping task...");
};
}
None => nih_debug_assert_failure!("The host does not support parameters? What?"),
}
} }
} }