diff --git a/src/wrapper/clap/plugin.rs b/src/wrapper/clap/plugin.rs index 867a2bd2..40c13bb2 100644 --- a/src/wrapper/clap/plugin.rs +++ b/src/wrapper/clap/plugin.rs @@ -1,13 +1,14 @@ use clap_sys::host::clap_host; use clap_sys::plugin::clap_plugin; use clap_sys::process::{clap_process, clap_process_status}; +use crossbeam::atomic::AtomicCell; use parking_lot::RwLock; use std::ffi::c_void; use std::os::raw::c_char; use std::ptr; use super::descriptor::PluginDescriptor; -use crate::plugin::ClapPlugin; +use crate::plugin::{BufferConfig, BusConfig, ClapPlugin}; #[repr(C)] pub struct Plugin { @@ -17,6 +18,13 @@ pub struct Plugin { /// The wrapped plugin instance. plugin: RwLock

, + /// The current IO configuration, modified through the `clap_plugin_audio_ports_config` + /// extension. + current_bus_config: AtomicCell, + /// The current buffer configuration, containing the sample rate and the maximum block size. + /// Will be set in `clap_plugin::activate()`. + pub current_buffer_config: AtomicCell>, + host_callback: *const clap_host, /// Needs to be boxed because the plugin object is supposed to contain a static reference to /// this. @@ -49,6 +57,11 @@ impl Plugin

{ }, plugin: RwLock::new(P::default()), + current_bus_config: AtomicCell::new(BusConfig { + num_input_channels: P::DEFAULT_NUM_INPUTS, + num_output_channels: P::DEFAULT_NUM_OUTPUTS, + }), + current_buffer_config: AtomicCell::new(None), host_callback, plugin_descriptor, @@ -57,41 +70,82 @@ impl Plugin

{ } impl Plugin

{ - unsafe extern "C" fn init(plugin: *const clap_plugin) -> bool { - todo!(); + // pub fn make_process_context(&self) -> WrapperProcessContext<'_, P> { + // WrapperProcessContext { + // plugin: self, + // input_events_guard: self.input_events.write(), + // } + // } + + unsafe extern "C" fn init(_plugin: *const clap_plugin) -> bool { + // We don't need any special initialization + true } + unsafe extern "C" fn destroy(plugin: *const clap_plugin) { - todo!(); + Box::from_raw(plugin as *mut Self); } + unsafe extern "C" fn activate( plugin: *const clap_plugin, sample_rate: f64, min_frames_count: u32, max_frames_count: u32, ) -> bool { + let plugin = &*(plugin as *const Self); + + let bus_config = plugin.current_bus_config.load(); + let buffer_config = BufferConfig { + sample_rate: sample_rate as f32, + max_buffer_size: max_frames_count, + }; + + // TODO: Reset smoothers + todo!(); + // if plugin.plugin.write().initialize( + // &bus_config, + // &buffer_config, + // plugin.make_process_context(), + // ) { + // // TODO: Allocate buffer slices + + // // Also store this for later, so we can reinitialize the plugin after restoring state + // plugin.current_buffer_config.store(Some(buffer_config)); + + // true + // } else { + // false + // } } - unsafe extern "C" fn deactivate(plugin: *const clap_plugin) { - todo!(); + + unsafe extern "C" fn deactivate(_plugin: *const clap_plugin) { + // We currently don't do anything here } - unsafe extern "C" fn start_processing(plugin: *const clap_plugin) -> bool { - todo!(); + + unsafe extern "C" fn start_processing(_plugin: *const clap_plugin) -> bool { + // We currently don't do anything here + true } - unsafe extern "C" fn stop_processing(plugin: *const clap_plugin) { - todo!(); + + unsafe extern "C" fn stop_processing(_plugin: *const clap_plugin) { + // We currently don't do anything here } + unsafe extern "C" fn process( plugin: *const clap_plugin, process: *const clap_process, ) -> clap_process_status { todo!(); } + unsafe extern "C" fn get_extension( plugin: *const clap_plugin, id: *const c_char, ) -> *const c_void { todo!(); } + unsafe extern "C" fn on_main_thread(plugin: *const clap_plugin) { todo!(); }