diff --git a/src/format/clap/factory.rs b/src/format/clap/factory.rs index ec7de73..6fb32f3 100644 --- a/src/format/clap/factory.rs +++ b/src/format/clap/factory.rs @@ -110,14 +110,14 @@ impl Factory

{ unsafe extern "C" fn create_plugin( factory: *const clap_plugin_factory, - _host: *const clap_host, + host: *const clap_host, plugin_id: *const c_char, ) -> *const clap_plugin { let factory = &*(factory as *const Self); if let Some(state) = &*factory.state.get() { if CStr::from_ptr(plugin_id) == CStr::from_ptr(state.descriptor.id) { - let instance = Box::new(Instance::

::new(&state.descriptor, &state.info)); + let instance = Box::new(Instance::

::new(&state.descriptor, &state.info, host)); return Box::into_raw(instance) as *const clap_plugin; } } diff --git a/src/format/clap/instance.rs b/src/format/clap/instance.rs index a091bb4..84345ff 100644 --- a/src/format/clap/instance.rs +++ b/src/format/clap/instance.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use std::{io, ptr, slice}; use clap_sys::ext::{audio_ports::*, audio_ports_config::*, gui::*, params::*, state::*}; -use clap_sys::{events::*, id::*, plugin::*, process::*, stream::*}; +use clap_sys::{events::*, host::*, id::*, plugin::*, process::*, stream::*}; use crate::buffers::{BufferData, BufferType, Buffers}; use crate::bus::{BusDir, Format}; @@ -59,6 +59,7 @@ pub struct ProcessState { pub struct Instance { #[allow(unused)] pub clap_plugin: clap_plugin, + pub host: *const clap_host, pub info: Arc, pub input_bus_map: Vec, pub output_bus_map: Vec, @@ -74,7 +75,11 @@ pub struct Instance { unsafe impl Sync for Instance

{} impl Instance

{ - pub fn new(desc: *const clap_plugin_descriptor, info: &Arc) -> Self { + pub fn new( + desc: *const clap_plugin_descriptor, + info: &Arc, + host: *const clap_host, + ) -> Self { let mut input_bus_map = Vec::new(); let mut output_bus_map = Vec::new(); for (index, bus) in info.buses.iter().enumerate() { @@ -108,6 +113,7 @@ impl Instance

{ get_extension: Some(Self::get_extension), on_main_thread: Some(Self::on_main_thread), }, + host, info: info.clone(), input_bus_map, output_bus_map, @@ -329,6 +335,8 @@ impl Instance

{ }); } + let mut params_changed = false; + let in_events = process.in_events; let size = (*in_events).size.unwrap()(in_events); for i in 0..size { @@ -351,10 +359,16 @@ impl Instance

{ }); instance.plugin_params.set(index, value); + + params_changed = true; } } } + if params_changed { + (*instance.host).request_callback.unwrap()(instance.host); + } + processor.process( Buffers::from_raw_parts( &process_state.buffer_data, @@ -400,7 +414,12 @@ impl Instance

{ ptr::null() } - unsafe extern "C" fn on_main_thread(_plugin: *const clap_plugin) {} + unsafe extern "C" fn on_main_thread(plugin: *const clap_plugin) { + let instance = &*(plugin as *const Self); + let main_thread_state = &mut *instance.main_thread_state.get(); + + instance.sync_plugin(main_thread_state); + } } impl Instance

{ @@ -683,6 +702,8 @@ impl Instance

{ }); } + let mut params_changed = false; + let size = (*in_).size.unwrap()(in_); for i in 0..size { let event = (*in_).get.unwrap()(in_, i); @@ -704,10 +725,16 @@ impl Instance

{ }); instance.plugin_params.set(index, value); + + params_changed = true; } } } + if params_changed { + (*instance.host).request_callback.unwrap()(instance.host); + } + processor.process( Buffers::from_raw_parts( &process_state.buffer_data,