2022-03-01 02:31:49 +11:00
|
|
|
mod factory;
|
2022-03-01 00:45:31 +11:00
|
|
|
|
|
|
|
/// Re-export for the wrapper.
|
2022-03-01 02:31:49 +11:00
|
|
|
pub use self::factory::Factory;
|
|
|
|
pub use clap_sys::entry::clap_plugin_entry;
|
|
|
|
pub use clap_sys::plugin_factory::CLAP_PLUGIN_FACTORY_ID;
|
|
|
|
pub use clap_sys::version::CLAP_VERSION;
|
|
|
|
pub use lazy_static::lazy_static;
|
2022-03-01 00:45:31 +11:00
|
|
|
|
|
|
|
/// 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 {
|
2022-03-01 02:31:49 +11:00
|
|
|
// Because `$plugin_ty` is likely defined in the enclosing scope
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
// We don't use generics inside of statics, so this lazy_static is used as kind of an
|
|
|
|
// escape hatch
|
|
|
|
::nih_plug::wrapper::clap::lazy_static! {
|
|
|
|
static ref factory: ::nih_plug::wrapper::clap::Factory<$plugin_ty> = ::nih_plug::wrapper::clap::Factory::default();
|
|
|
|
}
|
|
|
|
|
2022-03-01 00:45:31 +11:00
|
|
|
// We don't need any special initialization or deinitialization handling
|
|
|
|
pub fn init(_plugin_path: *const ::std::os::raw::c_char) -> bool {
|
2022-03-01 01:48:26 +11:00
|
|
|
nih_log!("clap::init()");
|
2022-03-01 00:45:31 +11:00
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn deinit() {
|
2022-03-01 01:48:26 +11:00
|
|
|
nih_log!("clap::deinit()");
|
2022-03-01 00:45:31 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_factory(
|
|
|
|
factory_id: *const ::std::os::raw::c_char,
|
|
|
|
) -> *const ::std::ffi::c_void {
|
2022-03-01 02:31:49 +11:00
|
|
|
if !factory_id.is_null()
|
|
|
|
&& unsafe { ::std::ffi::CStr::from_ptr(factory_id) }
|
|
|
|
== unsafe { ::std::ffi::CStr::from_ptr(
|
|
|
|
::nih_plug::wrapper::clap::CLAP_PLUGIN_FACTORY_ID,
|
|
|
|
) }
|
|
|
|
{
|
|
|
|
&(*factory).clap_plugin_factory() as *const _ as *const ::std::ffi::c_void
|
|
|
|
} else {
|
|
|
|
std::ptr::null()
|
|
|
|
}
|
2022-03-01 00:45:31 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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 {
|
2022-03-01 01:48:26 +11:00
|
|
|
::std::mem::transmute(
|
|
|
|
self::clap::init as fn(*const ::std::os::raw::c_char) -> bool,
|
|
|
|
)
|
2022-03-01 00:45:31 +11:00
|
|
|
},
|
2022-03-01 01:48:26 +11:00
|
|
|
deinit: unsafe { ::std::mem::transmute(self::clap::deinit as fn()) },
|
2022-03-01 00:45:31 +11:00
|
|
|
get_factory: unsafe {
|
|
|
|
::std::mem::transmute(
|
2022-03-01 01:48:26 +11:00
|
|
|
self::clap::get_factory
|
2022-03-01 00:45:31 +11:00
|
|
|
as fn(*const ::std::os::raw::c_char) -> *const ::std::ffi::c_void,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|