tek/suil/src/lib.rs

113 lines
2.8 KiB
Rust

use std::ffi::{CString, c_void};
pub mod bound;
#[cfg(test)] mod test;
pub struct Host(*mut self::bound::SuilHost);
impl Drop for Host {
fn drop (&mut self) {
unsafe {
bound::suil_host_free(self.0)
}
}
}
impl Host {
pub fn new () -> Self {
Self(unsafe {
let mut argv = [];
bound::suil_init(
&mut 0,
&mut argv as *mut *mut *mut i8,
0
);
bound::suil_host_new(
Some(write),
Some(index),
None,
None,
)
})
}
fn set_touch_func (&self) {
unimplemented!();
}
fn instance <T> (
&self,
controller: &mut T,
container_type_uri: &str,
plugin_uri: &str,
ui_uri: &str,
ui_type_uri: &str,
ui_bundle_path: &str,
ui_binary_path: &str,
features: &[*const bound::LV2_Feature],
) -> Result<Instance, Box<dyn std::error::Error>> {
let container_type_uri = CString::new(container_type_uri)?;
let plugin_uri = CString::new(plugin_uri)?;
let ui_uri = CString::new(ui_uri)?;
let ui_type_uri = CString::new(ui_type_uri)?;
let ui_bundle_path = CString::new(ui_bundle_path)?;
let ui_binary_path = CString::new(ui_binary_path)?;
Ok(Instance(unsafe {
bound::suil_instance_new(
self.0,
controller as *mut _ as *mut std::ffi::c_void,
container_type_uri.into_raw(),
plugin_uri.into_raw(),
ui_uri.into_raw(),
ui_type_uri.into_raw(),
ui_bundle_path.into_raw(),
ui_binary_path.into_raw(),
std::ptr::null_mut(),
)
}))
}
}
unsafe extern "C" fn write (
_controller: *mut c_void, _: u32, _: u32, _: u32, _: *const c_void
) {
panic!("write")
}
unsafe extern "C" fn index (
_controller: *mut c_void, _: *const i8
) -> u32 {
0
}
//unsafe extern "C" fn subscribe (
//_: *mut c_void, _: u32, _: u32, _: *const *const bound::LV2_Feature
//) -> u32 {
//panic!("subscribe");
//0
//}
//unsafe extern "C" fn unsubscribe (
//_: *mut c_void, _: u32, _: u32, _: *const *const bound::LV2_Feature
//) -> u32 {
//panic!("unsubscribe");
//0
//}
pub struct Instance(*mut self::bound::SuilInstance);
impl Drop for Instance {
fn drop (&mut self) -> () {
unsafe {
bound::suil_instance_free(self.0)
}
}
}
unsafe impl Send for Instance {}
unsafe impl Sync for Instance {}
impl Instance {
fn get_widget (&self) -> *mut c_void {
unsafe { bound::suil_instance_get_widget(self.0) }
}
}