lilv_sys/
inline_fns.rs

1use lv2_raw::*;
2
3type LV2_Handle = LV2Handle;
4type LV2_Descriptor = LV2Descriptor;
5
6/// Connect a port to a data location.
7/// This may be called regardless of whether the plugin is activated,
8/// activation and deactivation does not destroy port connections.
9///
10/// # Safety
11/// Makes use of unsafe ffi functions.
12#[inline(always)]
13pub unsafe fn lilv_instance_get_uri(
14    instance: *const crate::LilvInstance,
15) -> *const std::os::raw::c_char {
16    instance
17        .as_ref()
18        .iter()
19        .flat_map(|i| i.lv2_descriptor.as_ref())
20        .map(|d| d.uri)
21        .next()
22        .unwrap_or(std::ptr::null())
23}
24
25/// Connect a port to a data location.
26/// This may be called regardless of whether the plugin is activated,
27/// activation and deactivation does not destroy port connections.
28///
29/// # Safety
30/// Makes use of unsafe ffi functions.
31#[inline(always)]
32pub unsafe fn lilv_instance_connect_port(
33    instance: *mut crate::LilvInstance,
34    port_index: u32,
35    data_location: *mut ::std::os::raw::c_void,
36) {
37    if let Some(instance) = instance.as_mut() {
38        if let Some(descriptor) = instance.lv2_descriptor.as_ref() {
39            (descriptor.connect_port)(instance.lv2_handle, port_index, data_location);
40        }
41    }
42}
43
44/// Activate a plugin instance.
45/// This resets all state information in the plugin, except for port data
46/// locations (as set by lilv_instance_connect_port()).  This MUST be called
47/// before calling lilv_instance_run().
48///
49/// # Safety
50/// Makes use of unsafe ffi functions.
51pub unsafe fn lilv_instance_activate(instance: *const crate::LilvInstance) {
52    if let Some(instance) = instance.as_ref() {
53        if let Some(descriptor) = instance.lv2_descriptor.as_ref() {
54            if let Some(activate_fn) = descriptor.activate {
55                (activate_fn)(instance.lv2_handle);
56            }
57        }
58    }
59}
60
61/// Run `instance` for `sample_count` frames.
62/// If the hint lv2:hardRTCapable is set for this plugin, this function is
63/// guaranteed not to block.
64///
65/// # Safety
66/// Makes use of unsafe ffi functions.
67#[inline(always)]
68pub unsafe fn lilv_instance_run(instance: *const crate::LilvInstance, sample_count: u32) {
69    if let Some(instance) = instance.as_ref() {
70        if let Some(descriptor) = instance.lv2_descriptor.as_ref() {
71            (descriptor.run)(instance.lv2_handle, sample_count);
72        }
73    }
74}
75
76/// Deactivate a plugin instance.
77/// Note that to run the plugin after this you must activate it, which will
78/// reset all state information (except port connections).
79///
80/// # Safety
81/// Makes use of unsafe ffi functions.
82#[inline(always)]
83pub unsafe fn lilv_instance_deactivate(instance: *mut crate::LilvInstance) {
84    if let Some(instance) = instance.as_ref() {
85        if let Some(descriptor) = instance.lv2_descriptor.as_ref() {
86            if let Some(deactivate_fn) = descriptor.deactivate {
87                (deactivate_fn)(instance.lv2_handle);
88            }
89        }
90    }
91}
92
93/// Get extension data from the plugin instance.
94/// The type and semantics of the data returned is specific to the particular
95/// extension, though in all cases it is shared and must not be deleted.
96///
97/// # Safety
98/// Makes use of unsafe ffi functions.
99#[inline(always)]
100pub unsafe fn lilv_instance_get_extension_data(
101    instance: *mut crate::LilvInstance,
102    uri: *const u8,
103) -> *const ::std::os::raw::c_void {
104    if let Some(instance) = instance.as_ref() {
105        if let Some(descriptor) = instance.lv2_descriptor.as_ref() {
106            return (descriptor.extension_data)(uri);
107        }
108    };
109    std::ptr::null()
110}
111
112/// Get the LV2_Descriptor of the plugin instance.
113/// Normally hosts should not need to access the LV2_Descriptor directly,
114/// use the lilv_instance_* functions.
115///
116/// # Safety
117/// Makes use of unsafe ffi functions.
118#[inline(always)]
119pub unsafe fn lilv_instance_get_descriptor(
120    instance: *const crate::LilvInstance,
121) -> *const LV2_Descriptor {
122    instance
123        .as_ref()
124        .map(|i| i.lv2_descriptor)
125        .unwrap_or(::std::ptr::null())
126}
127
128/// Get the LV2_Handle of the plugin instance.
129/// Normally hosts should not need to access the LV2_Handle directly,
130/// use the lilv_instance_* functions.
131///
132/// The returned handle is shared and must not be deleted.
133///
134/// # Safety
135/// Makes use of unsafe ffi functions.
136#[inline(always)]
137pub unsafe fn lilv_instance_get_handle(instance: *const crate::LilvInstance) -> LV2_Handle {
138    instance
139        .as_ref()
140        .map(|i| i.lv2_handle)
141        .unwrap_or(::std::ptr::null_mut())
142}