mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
57 lines
1.7 KiB
Rust
57 lines
1.7 KiB
Rust
use crate::core::*;
|
|
|
|
pub struct LV2Plugin {
|
|
pub world: ::livi::World,
|
|
pub instance: ::livi::Instance,
|
|
pub plugin: ::livi::Plugin,
|
|
pub features: Arc<::livi::Features>,
|
|
pub port_list: Vec<::livi::Port>,
|
|
}
|
|
|
|
impl LV2Plugin {
|
|
pub fn new (uri: &str) -> Usually<Self> {
|
|
// Get 1st plugin at URI
|
|
let world = ::livi::World::with_load_bundle(&uri);
|
|
let features = ::livi::FeaturesBuilder { min_block_length: 1, max_block_length: 65536 };
|
|
let features = world.build_features(features);
|
|
let mut plugin = None;
|
|
for p in world.iter_plugins() {
|
|
plugin = Some(p);
|
|
break
|
|
}
|
|
let plugin = plugin.unwrap();
|
|
|
|
// Instantiate
|
|
Ok(Self {
|
|
world,
|
|
instance: unsafe {
|
|
plugin.instantiate(features.clone(), 48000.0).expect("boop")
|
|
},
|
|
port_list: {
|
|
let mut port_list = vec![];
|
|
for port in plugin.ports() {
|
|
port_list.push(port);
|
|
}
|
|
port_list
|
|
},
|
|
plugin,
|
|
features,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl super::Plugin {
|
|
pub fn lv2 (name: &str, path: &str) -> Usually<Arc<Mutex<Box<dyn Device>>>> {
|
|
let plugin = LV2Plugin::new(path)?;
|
|
Jack::new(name)?
|
|
.ports_from_lv2(&plugin.plugin)?
|
|
.run(|ports|Box::new(Self {
|
|
name: name.into(),
|
|
path: Some(String::from(path)),
|
|
plugin: Some(super::PluginKind::LV2(plugin)),
|
|
selected: 0,
|
|
mapping: false,
|
|
ports
|
|
}))
|
|
}
|
|
}
|