1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
mod plugin;
pub mod ports;
pub mod raw;
pub mod uris;
pub use plugin::*;
pub use raw::{Descriptor, Feature};
#[macro_export]
macro_rules! lv2_main {
($c:ident, $s:ty, $u:expr) => {
const PLUGIN_URI: &'static [u8] = $u;
const PLUGIN_DESCRIPTOR: $c::raw::Descriptor = $c::raw::Descriptor {
uri: PLUGIN_URI.as_ptr() as *const std::os::raw::c_char,
instantiate: instantiate,
connect_port: connect_port,
activate: activate,
run: run,
deactivate: deactivate,
cleanup: cleanup,
extension_data: extension_data,
};
unsafe extern "C" fn instantiate(
descriptor: *const $c::raw::Descriptor,
rate: f64,
bundle_path: *const std::os::raw::c_char,
features: *const *const $c::raw::Feature,
) -> $c::raw::Handle {
$c::instantiate::<$s>(descriptor, rate, bundle_path, features)
}
unsafe extern "C" fn connect_port(
instance: $c::raw::Handle,
port: u32,
data: *mut std::os::raw::c_void,
) {
$c::connect_port::<$s>(instance, port, data);
}
unsafe extern "C" fn activate(instance: $c::raw::Handle) {
$c::activate::<$s>(instance);
}
unsafe extern "C" fn run(instance: $c::raw::Handle, n_samples: u32) {
$c::run::<$s>(instance, n_samples);
}
unsafe extern "C" fn deactivate(instance: $c::raw::Handle) {
$c::deactivate::<$s>(instance);
}
unsafe extern "C" fn cleanup(instance: $c::raw::Handle) {
$c::cleanup::<$s>(instance);
}
unsafe extern "C" fn extension_data(
uri: *const std::os::raw::c_char,
) -> *const std::os::raw::c_void {
$c::extension_data::<$s>(uri)
}
#[no_mangle]
pub unsafe extern "C" fn lv2_descriptor(index: u32) -> *const $c::raw::Descriptor {
if index == 0 {
&PLUGIN_DESCRIPTOR
} else {
std::ptr::null()
}
}
};
}