1
0
Fork 0

Add stubs for the clap_plugin methods

This commit is contained in:
Robbert van der Helm 2022-02-28 18:55:33 +01:00
parent 2e6faaa324
commit 0511053b3b
2 changed files with 73 additions and 11 deletions

View file

@ -53,7 +53,9 @@ impl<P: ClapPlugin> Default for PluginDescriptor<P> {
.map(|s| CString::new(*s).expect("`CLAP_FEATURES` contained null bytes")) .map(|s| CString::new(*s).expect("`CLAP_FEATURES` contained null bytes"))
.collect(), .collect(),
clap_features_ptrs: MaybeUninit::uninit(), clap_features_ptrs: MaybeUninit::uninit(),
plugin_descriptor: MaybeUninit::uninit(), plugin_descriptor: MaybeUninit::uninit(),
_phantom: PhantomData, _phantom: PhantomData,
}; };

View file

@ -1,7 +1,12 @@
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 parking_lot::RwLock; 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::ClapPlugin;
#[repr(C)] #[repr(C)]
@ -13,26 +18,81 @@ pub struct Plugin<P: ClapPlugin> {
plugin: RwLock<P>, plugin: RwLock<P>,
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
/// this.
plugin_descriptor: Box<PluginDescriptor<P>>,
} }
impl<P: ClapPlugin> Plugin<P> { impl<P: ClapPlugin> Plugin<P> {
pub fn new(host_callback: *const clap_host) -> Self { pub fn new(host_callback: *const clap_host) -> Self {
let plugin_descriptor = Box::new(PluginDescriptor::default());
Self { Self {
clap_plugin: clap_plugin { clap_plugin: clap_plugin {
desc: todo!(), // This needs to live on the heap because the plugin object contains a direct
plugin_data: todo!(), // reference to the manifest as a value. We could share this between instances of
init: todo!(), // the plugin using an `Arc`, but this doesn't consume a lot of memory so it's not a
destroy: todo!(), // huge deal.
activate: todo!(), desc: plugin_descriptor.clap_plugin_descriptor(),
deactivate: todo!(), // We already need to use pointer casts in the factory, so might as well continue
start_processing: todo!(), // doing that here
stop_processing: todo!(), plugin_data: ptr::null_mut(),
process: todo!(), init: Self::init,
get_extension: todo!(), destroy: Self::destroy,
on_main_thread: todo!(), 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,
}, },
plugin: RwLock::new(P::default()), plugin: RwLock::new(P::default()),
host_callback, host_callback,
plugin_descriptor,
} }
} }
} }
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!();
}
}