Partially implement clap_plugin
This commit is contained in:
parent
0511053b3b
commit
6d1e581c26
|
@ -1,13 +1,14 @@
|
||||||
use clap_sys::host::clap_host;
|
use clap_sys::host::clap_host;
|
||||||
use clap_sys::plugin::clap_plugin;
|
use clap_sys::plugin::clap_plugin;
|
||||||
use clap_sys::process::{clap_process, clap_process_status};
|
use clap_sys::process::{clap_process, clap_process_status};
|
||||||
|
use crossbeam::atomic::AtomicCell;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use super::descriptor::PluginDescriptor;
|
use super::descriptor::PluginDescriptor;
|
||||||
use crate::plugin::ClapPlugin;
|
use crate::plugin::{BufferConfig, BusConfig, ClapPlugin};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Plugin<P: ClapPlugin> {
|
pub struct Plugin<P: ClapPlugin> {
|
||||||
|
@ -17,6 +18,13 @@ pub struct Plugin<P: ClapPlugin> {
|
||||||
/// The wrapped plugin instance.
|
/// The wrapped plugin instance.
|
||||||
plugin: RwLock<P>,
|
plugin: RwLock<P>,
|
||||||
|
|
||||||
|
/// The current IO configuration, modified through the `clap_plugin_audio_ports_config`
|
||||||
|
/// extension.
|
||||||
|
current_bus_config: AtomicCell<BusConfig>,
|
||||||
|
/// 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<Option<BufferConfig>>,
|
||||||
|
|
||||||
host_callback: *const clap_host,
|
host_callback: *const clap_host,
|
||||||
/// Needs to be boxed because the plugin object is supposed to contain a static reference to
|
/// Needs to be boxed because the plugin object is supposed to contain a static reference to
|
||||||
/// this.
|
/// this.
|
||||||
|
@ -49,6 +57,11 @@ impl<P: ClapPlugin> Plugin<P> {
|
||||||
},
|
},
|
||||||
|
|
||||||
plugin: RwLock::new(P::default()),
|
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,
|
host_callback,
|
||||||
plugin_descriptor,
|
plugin_descriptor,
|
||||||
|
@ -57,41 +70,82 @@ impl<P: ClapPlugin> Plugin<P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: ClapPlugin> Plugin<P> {
|
impl<P: ClapPlugin> Plugin<P> {
|
||||||
unsafe extern "C" fn init(plugin: *const clap_plugin) -> bool {
|
// pub fn make_process_context(&self) -> WrapperProcessContext<'_, P> {
|
||||||
todo!();
|
// 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) {
|
unsafe extern "C" fn destroy(plugin: *const clap_plugin) {
|
||||||
todo!();
|
Box::from_raw(plugin as *mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn activate(
|
unsafe extern "C" fn activate(
|
||||||
plugin: *const clap_plugin,
|
plugin: *const clap_plugin,
|
||||||
sample_rate: f64,
|
sample_rate: f64,
|
||||||
min_frames_count: u32,
|
min_frames_count: u32,
|
||||||
max_frames_count: u32,
|
max_frames_count: u32,
|
||||||
) -> bool {
|
) -> 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!();
|
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(
|
unsafe extern "C" fn process(
|
||||||
plugin: *const clap_plugin,
|
plugin: *const clap_plugin,
|
||||||
process: *const clap_process,
|
process: *const clap_process,
|
||||||
) -> clap_process_status {
|
) -> clap_process_status {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn get_extension(
|
unsafe extern "C" fn get_extension(
|
||||||
plugin: *const clap_plugin,
|
plugin: *const clap_plugin,
|
||||||
id: *const c_char,
|
id: *const c_char,
|
||||||
) -> *const c_void {
|
) -> *const c_void {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn on_main_thread(plugin: *const clap_plugin) {
|
unsafe extern "C" fn on_main_thread(plugin: *const clap_plugin) {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue