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, pub port_list: Vec, pub input_buffer: Vec, pub ui_thread: Option>, } impl LV2Plugin { const INPUT_BUFFER: usize = 1024; pub fn new (uri: &str) -> Usually { 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::>(), input_buffer: Vec::with_capacity(Self::INPUT_BUFFER), ui_thread: None, world, features, plugin, }) } } impl LV2Plugin { pub fn from_edn <'e> (jack: &Arc>, args: &[Edn<'e>]) -> Usually { 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) } }