mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
67 lines
2 KiB
Rust
67 lines
2 KiB
Rust
use crate::*;
|
|
|
|
/// A LV2 plugin.
|
|
#[derive(Debug)]
|
|
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>,
|
|
pub input_buffer: Vec<livi::event::LV2AtomSequence>,
|
|
pub ui_thread: Option<JoinHandle<()>>,
|
|
}
|
|
|
|
impl LV2Plugin {
|
|
const INPUT_BUFFER: usize = 1024;
|
|
pub fn new (uri: &str) -> Usually<Self> {
|
|
let world = livi::World::with_load_bundle(&uri);
|
|
let features = world
|
|
.build_features(livi::FeaturesBuilder {
|
|
min_block_length: 1,
|
|
max_block_length: 65536,
|
|
});
|
|
let plugin = world
|
|
.iter_plugins()
|
|
.nth(0)
|
|
.expect(&format!("plugin not found: {uri}"));
|
|
Ok(Self {
|
|
instance: unsafe {
|
|
plugin
|
|
.instantiate(features.clone(), 48000.0)
|
|
.expect(&format!("instantiate failed: {uri}"))
|
|
},
|
|
port_list: plugin.ports().collect::<Vec<_>>(),
|
|
input_buffer: Vec::with_capacity(Self::INPUT_BUFFER),
|
|
ui_thread: None,
|
|
world,
|
|
features,
|
|
plugin,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl LV2Plugin {
|
|
pub fn from_edn <'e> (jack: &Arc<RwLock<JackClient>>, args: &[Edn<'e>]) -> Usually<Self> {
|
|
let mut name = String::new();
|
|
let mut path = String::new();
|
|
edn!(edn in args {
|
|
Edn::Map(map) => {
|
|
if let Some(Edn::Str(n)) = map.get(&Edn::Key(":name")) {
|
|
name = String::from(*n);
|
|
}
|
|
if let Some(Edn::Str(p)) = map.get(&Edn::Key(":path")) {
|
|
path = String::from(*p);
|
|
}
|
|
},
|
|
_ => panic!("unexpected in lv2 '{name}'"),
|
|
});
|
|
Plugin::new_lv2(jack, &name, &path)
|
|
}
|
|
}
|
|
|
|
impl Audio for LV2Plugin {
|
|
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
|
Control::Continue
|
|
}
|
|
}
|