use std::os::raw::c_char;
use std::path::Path;
use std::str::Utf8Error;
use urid::Uri;
#[derive(Debug)]
pub enum PluginInfoError {
InvalidBundlePathUtf8(Utf8Error),
}
pub struct PluginInfo<'a> {
plugin_uri: &'a Uri,
bundle_path: &'a Path,
sample_rate: f64,
}
impl<'a> PluginInfo<'a> {
pub unsafe fn from_raw(
plugin_descriptor: *const crate::sys::LV2_Descriptor,
bundle_path: *const c_char,
sample_rate: f64,
) -> Result<Self, PluginInfoError> {
let bundle_path = Path::new(
Uri::from_ptr(bundle_path)
.to_str()
.map_err(PluginInfoError::InvalidBundlePathUtf8)?,
);
Ok(Self::new(
Uri::from_ptr((*plugin_descriptor).URI),
bundle_path,
sample_rate,
))
}
pub fn new(plugin_uri: &'a Uri, bundle_path: &'a Path, sample_rate: f64) -> Self {
Self {
sample_rate,
plugin_uri,
bundle_path,
}
}
pub fn plugin_uri(&self) -> &Uri {
self.plugin_uri
}
pub fn bundle_path(&self) -> &Path {
self.bundle_path
}
pub fn sample_rate(&self) -> f64 {
self.sample_rate
}
}