mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
40 lines
1.2 KiB
Rust
40 lines
1.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)
|
|
.unwrap_or_else(||panic!("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,
|
|
})
|
|
}
|
|
}
|