diff --git a/plugins/diopser/src/lib.rs b/plugins/diopser/src/lib.rs index d54369b4..48e9e1d1 100644 --- a/plugins/diopser/src/lib.rs +++ b/plugins/diopser/src/lib.rs @@ -417,4 +417,5 @@ impl Vst3Plugin for Diopser { const VST3_CATEGORIES: &'static str = "Fx|Filter"; } +nih_export_clap!(Diopser); nih_export_vst3!(Diopser); diff --git a/plugins/examples/gain-gui/src/lib.rs b/plugins/examples/gain-gui/src/lib.rs index 2159d8b0..62e1b586 100644 --- a/plugins/examples/gain-gui/src/lib.rs +++ b/plugins/examples/gain-gui/src/lib.rs @@ -209,4 +209,5 @@ impl Vst3Plugin for Gain { const VST3_CATEGORIES: &'static str = "Fx|Dynamics"; } +nih_export_clap!(Gain); nih_export_vst3!(Gain); diff --git a/plugins/examples/gain/src/lib.rs b/plugins/examples/gain/src/lib.rs index 7380f30e..77f509eb 100644 --- a/plugins/examples/gain/src/lib.rs +++ b/plugins/examples/gain/src/lib.rs @@ -136,4 +136,5 @@ impl Vst3Plugin for Gain { const VST3_CATEGORIES: &'static str = "Fx|Dynamics"; } +nih_export_clap!(Gain); nih_export_vst3!(Gain); diff --git a/plugins/examples/sine/src/lib.rs b/plugins/examples/sine/src/lib.rs index bfce93fa..3f36028f 100644 --- a/plugins/examples/sine/src/lib.rs +++ b/plugins/examples/sine/src/lib.rs @@ -183,4 +183,5 @@ impl Vst3Plugin for Sine { const VST3_CATEGORIES: &'static str = "Instrument|Synth|Tools"; } +nih_export_clap!(Sine); nih_export_vst3!(Sine); diff --git a/src/wrapper.rs b/src/wrapper.rs index 10f53a18..f43089f4 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -1,6 +1,7 @@ //! Wrappers for different plugin types. Each wrapper has an entry point macro that you can pass the //! name of a type that implements `Plugin` to. The macro will handle the rest. +pub mod clap; pub(crate) mod state; pub(crate) mod util; pub mod vst3; diff --git a/src/wrapper/clap.rs b/src/wrapper/clap.rs new file mode 100644 index 00000000..c3748589 --- /dev/null +++ b/src/wrapper/clap.rs @@ -0,0 +1,54 @@ +use crate::ClapPlugin; + +/// Re-export for the wrapper. +pub use ::clap_sys::entry::clap_plugin_entry; +pub use ::clap_sys::version::CLAP_VERSION; + +/// Export a CLAP plugin from this library using the provided plugin type. +#[macro_export] +macro_rules! nih_export_clap { + ($plugin_ty:ty) => { + // We need a function pointer to a [wrapper::get_factory()] that creates a factory for + // `$plugin_ty`, so we need to generate the function inside of this macro + #[doc(hidden)] + mod clap { + // We don't need any special initialization or deinitialization handling + pub fn init(_plugin_path: *const ::std::os::raw::c_char) -> bool { + eprintln!("Init!"); + + true + } + + pub fn deinit() { + eprintln!("Deinit!"); + } + + pub fn get_factory( + factory_id: *const ::std::os::raw::c_char, + ) -> *const ::std::ffi::c_void { + eprintln!("get factory!! {factory_id:#?}"); + + std::ptr::null() + } + } + + #[no_mangle] + #[used] + pub static clap_entry: ::nih_plug::wrapper::clap::clap_plugin_entry = + ::nih_plug::wrapper::clap::clap_plugin_entry { + clap_version: ::nih_plug::wrapper::clap::CLAP_VERSION, + // These function pointers are marked as `extern "C"`but there's no reason why the symbols + // would need to be exported, so we need these transmutes + init: unsafe { + ::std::mem::transmute(clap::init as fn(*const ::std::os::raw::c_char) -> bool) + }, + deinit: unsafe { ::std::mem::transmute(clap::deinit as fn()) }, + get_factory: unsafe { + ::std::mem::transmute( + clap::get_factory + as fn(*const ::std::os::raw::c_char) -> *const ::std::ffi::c_void, + ) + }, + }; + }; +}