Create a clap_plugin instance stub
This commit is contained in:
parent
0b0876e4a5
commit
32a640acf7
|
@ -1,4 +1,5 @@
|
|||
mod factory;
|
||||
mod plugin;
|
||||
|
||||
/// Re-export for the wrapper.
|
||||
pub use self::factory::Factory;
|
||||
|
|
|
@ -2,12 +2,13 @@ use clap_sys::host::clap_host;
|
|||
use clap_sys::plugin::{clap_plugin, clap_plugin_descriptor};
|
||||
use clap_sys::plugin_factory::clap_plugin_factory;
|
||||
use clap_sys::version::CLAP_VERSION;
|
||||
use std::ffi::CString;
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::os::raw::c_char;
|
||||
use std::ptr;
|
||||
|
||||
use super::plugin::Plugin;
|
||||
use crate::ClapPlugin;
|
||||
|
||||
/// The plugin's factory. Initialized using a lazy_static from the entry poiunt's `get_factory()`
|
||||
|
@ -127,6 +128,12 @@ impl<P: ClapPlugin> Factory<P> {
|
|||
host: *const clap_host,
|
||||
plugin_id: *const c_char,
|
||||
) -> *const clap_plugin {
|
||||
todo!()
|
||||
let factory = &*(factory as *const Self);
|
||||
|
||||
if !plugin_id.is_null() && CStr::from_ptr(plugin_id) == factory.clap_id.as_c_str() {
|
||||
&Box::leak(Box::new(Plugin::<P>::new(host))).clap_plugin
|
||||
} else {
|
||||
ptr::null()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
38
src/wrapper/clap/plugin.rs
Normal file
38
src/wrapper/clap/plugin.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use clap_sys::host::clap_host;
|
||||
use clap_sys::plugin::clap_plugin;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
impl<P: ClapPlugin> Plugin<P> {
|
||||
pub fn new(host_callback: *const clap_host) -> Self {
|
||||
Self {
|
||||
clap_plugin: clap_plugin {
|
||||
desc: todo!(),
|
||||
plugin_data: todo!(),
|
||||
init: todo!(),
|
||||
destroy: todo!(),
|
||||
activate: todo!(),
|
||||
deactivate: todo!(),
|
||||
start_processing: todo!(),
|
||||
stop_processing: todo!(),
|
||||
process: todo!(),
|
||||
get_extension: todo!(),
|
||||
on_main_thread: todo!(),
|
||||
},
|
||||
plugin: RwLock::new(P::default()),
|
||||
host_callback,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue