Skip to main content

clap_wrapper/
lib.rs

1#![doc = include_str!("../README.md")]
2
3/// Exports an AUv2 entrypoint named `GetPluginFactoryAUV2` that wraps a global CLAP entrypoint (`clap_entry`) exported from the resulting shared library.
4/// Currently it only reexports the first plugin available through the CLAP entrypoint, but this limitation might be lifted in the future.
5///
6/// Failure to export a CLAP entrypoint might result in linker errors or missing symbols.
7#[macro_export]
8macro_rules! export_vst3 {
9    () => {
10        #[allow(unused_imports)]
11        pub use $crate::vst3::*;
12    };
13}
14
15/// Exports a VST3 entrypoint named `GetPluginFactory` that wraps a global CLAP entrypoint (`clap_entry`) exported from the resulting shared library.
16///
17/// Failure to export a CLAP entrypoint might result in linker errors or missing symbols.
18#[macro_export]
19macro_rules! export_auv2 {
20    () => {
21        #[allow(unused_imports)]
22        pub use $crate::auv2::*;
23    };
24}
25
26#[cfg(all(target_os = "macos", feature = "auv2"))]
27#[doc(hidden)]
28pub mod auv2 {
29    use core::ffi::c_void;
30
31    #[link(name = "clap_wrapper_auv2")]
32    unsafe extern "C" {
33        pub unsafe fn wrapAsAUV2_inst0Factory(desc: *const c_void) -> *mut c_void;
34        pub unsafe fn wrapAsAUV2_inst1Factory(desc: *const c_void) -> *mut c_void;
35        pub unsafe fn wrapAsAUV2_inst2Factory(desc: *const c_void) -> *mut c_void;
36        pub unsafe fn wrapAsAUV2_inst3Factory(desc: *const c_void) -> *mut c_void;
37    }
38
39    #[unsafe(no_mangle)]
40    pub unsafe extern "C" fn GetPluginFactoryAUV2(desc: *const c_void) -> *mut c_void {
41        unsafe { wrapAsAUV2_inst0Factory(desc) }
42    }
43
44    #[unsafe(no_mangle)]
45    pub unsafe extern "C" fn GetPluginFactoryAUV2_0(desc: *const c_void) -> *mut c_void {
46        unsafe { wrapAsAUV2_inst0Factory(desc) }
47    }
48
49    #[unsafe(no_mangle)]
50    pub unsafe extern "C" fn GetPluginFactoryAUV2_1(desc: *const c_void) -> *mut c_void {
51        unsafe { wrapAsAUV2_inst1Factory(desc) }
52    }
53
54    #[unsafe(no_mangle)]
55    pub unsafe extern "C" fn GetPluginFactoryAUV2_2(desc: *const c_void) -> *mut c_void {
56        unsafe { wrapAsAUV2_inst2Factory(desc) }
57    }
58
59    #[unsafe(no_mangle)]
60    pub unsafe extern "C" fn GetPluginFactoryAUV2_3(desc: *const c_void) -> *mut c_void {
61        unsafe { wrapAsAUV2_inst3Factory(desc) }
62    }
63}
64
65#[cfg(not(all(target_os = "macos", feature = "auv2")))]
66#[doc(hidden)]
67pub mod auv2 {}
68
69#[cfg(feature = "vst3")]
70#[doc(hidden)]
71pub mod vst3 {
72    use core::ffi::c_void;
73
74    #[link(name = "clap_wrapper_vst3")]
75    unsafe extern "system" {
76        unsafe fn clap_wrapper_GetPluginFactory() -> *mut c_void;
77    }
78
79    #[link(name = "clap_wrapper_vst3")]
80    #[cfg(all(target_family = "unix", not(target_os = "macos")))]
81    unsafe extern "C" {
82        unsafe fn clap_wrapper_ModuleEntry(lib_module: *mut c_void) -> bool;
83        unsafe fn clap_wrapper_ModuleExit() -> bool;
84    }
85
86    #[link(name = "clap_wrapper_vst3")]
87    #[cfg(target_os = "macos")]
88    unsafe extern "C" {
89        unsafe fn clap_wrapper_bundleEntry(lib_module: *mut c_void) -> bool;
90        unsafe fn clap_wrapper_bundleExit() -> bool;
91    }
92
93    #[link(name = "clap_wrapper_vst3")]
94    #[cfg(target_os = "windows")]
95    unsafe extern "system" {
96        unsafe fn clap_wrapper_InitDll() -> bool;
97        unsafe fn clap_wrapper_ExitDll() -> bool;
98    }
99
100    #[unsafe(no_mangle)]
101    pub unsafe extern "system" fn GetPluginFactory() -> *mut c_void {
102        unsafe { clap_wrapper_GetPluginFactory() }
103    }
104
105    #[unsafe(no_mangle)]
106    #[cfg(all(target_family = "unix", not(target_os = "macos")))]
107    pub unsafe extern "C" fn ModuleEntry(lib_module: *mut c_void) -> bool {
108        unsafe { clap_wrapper_ModuleEntry(lib_module) }
109    }
110
111    #[unsafe(no_mangle)]
112    #[cfg(all(target_family = "unix", not(target_os = "macos")))]
113    pub unsafe extern "C" fn ModuleExit() -> bool {
114        unsafe { clap_wrapper_ModuleExit() }
115    }
116
117    #[unsafe(no_mangle)]
118    #[cfg(target_os = "macos")]
119    pub unsafe extern "C" fn bundleEntry(lib_module: *mut c_void) -> bool {
120        unsafe { clap_wrapper_bundleEntry(lib_module) }
121    }
122
123    #[unsafe(no_mangle)]
124    #[cfg(target_os = "macos")]
125    pub unsafe extern "C" fn bundleExit() -> bool {
126        unsafe { clap_wrapper_bundleExit() }
127    }
128
129    #[unsafe(no_mangle)]
130    #[cfg(target_os = "windows")]
131    pub unsafe extern "system" fn InitDll() -> bool {
132        unsafe { clap_wrapper_InitDll() }
133    }
134
135    #[unsafe(no_mangle)]
136    #[cfg(target_os = "windows")]
137    pub unsafe extern "system" fn ExitDll() -> bool {
138        unsafe { clap_wrapper_ExitDll() }
139    }
140}
141
142#[cfg(not(feature = "vst3"))]
143#[doc(hidden)]
144pub mod vst3 {}