1
0
Fork 0
nih-plug/src/wrapper/clap/plugin.rs

99 lines
3.1 KiB
Rust
Raw Normal View History

2022-03-01 04:27:57 +11:00
use clap_sys::host::clap_host;
use clap_sys::plugin::clap_plugin;
2022-03-01 04:55:33 +11:00
use clap_sys::process::{clap_process, clap_process_status};
2022-03-01 04:27:57 +11:00
use parking_lot::RwLock;
2022-03-01 04:55:33 +11:00
use std::ffi::c_void;
use std::os::raw::c_char;
use std::ptr;
2022-03-01 04:27:57 +11:00
2022-03-01 04:55:33 +11:00
use super::descriptor::PluginDescriptor;
2022-03-01 04:27:57 +11:00
use crate::plugin::ClapPlugin;
#[repr(C)]
pub struct Plugin<P: ClapPlugin> {
// Keep the vtable as the first field so we can do a simple pointer cast
pub clap_plugin: clap_plugin,
/// The wrapped plugin instance.
plugin: RwLock<P>,
host_callback: *const clap_host,
2022-03-01 04:55:33 +11:00
/// Needs to be boxed because the plugin object is supposed to contain a static reference to
/// this.
plugin_descriptor: Box<PluginDescriptor<P>>,
2022-03-01 04:27:57 +11:00
}
impl<P: ClapPlugin> Plugin<P> {
pub fn new(host_callback: *const clap_host) -> Self {
2022-03-01 04:55:33 +11:00
let plugin_descriptor = Box::new(PluginDescriptor::default());
2022-03-01 04:27:57 +11:00
Self {
clap_plugin: clap_plugin {
2022-03-01 04:55:33 +11:00
// This needs to live on the heap because the plugin object contains a direct
// reference to the manifest as a value. We could share this between instances of
// the plugin using an `Arc`, but this doesn't consume a lot of memory so it's not a
// huge deal.
desc: plugin_descriptor.clap_plugin_descriptor(),
// We already need to use pointer casts in the factory, so might as well continue
// doing that here
plugin_data: ptr::null_mut(),
init: Self::init,
destroy: Self::destroy,
activate: Self::activate,
deactivate: Self::deactivate,
start_processing: Self::start_processing,
stop_processing: Self::stop_processing,
process: Self::process,
get_extension: Self::get_extension,
on_main_thread: Self::on_main_thread,
2022-03-01 04:27:57 +11:00
},
2022-03-01 04:55:33 +11:00
2022-03-01 04:27:57 +11:00
plugin: RwLock::new(P::default()),
2022-03-01 04:55:33 +11:00
2022-03-01 04:27:57 +11:00
host_callback,
2022-03-01 04:55:33 +11:00
plugin_descriptor,
2022-03-01 04:27:57 +11:00
}
}
}
2022-03-01 04:55:33 +11:00
impl<P: ClapPlugin> Plugin<P> {
unsafe extern "C" fn init(plugin: *const clap_plugin) -> bool {
todo!();
}
unsafe extern "C" fn destroy(plugin: *const clap_plugin) {
todo!();
}
unsafe extern "C" fn activate(
plugin: *const clap_plugin,
sample_rate: f64,
min_frames_count: u32,
max_frames_count: u32,
) -> bool {
todo!();
}
unsafe extern "C" fn deactivate(plugin: *const clap_plugin) {
todo!();
}
unsafe extern "C" fn start_processing(plugin: *const clap_plugin) -> bool {
todo!();
}
unsafe extern "C" fn stop_processing(plugin: *const clap_plugin) {
todo!();
}
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!();
}
}