fetching lv2 parameters

This commit is contained in:
🪞👃🪞 2024-06-20 21:08:35 +03:00
parent 1e395274f6
commit ce1c28edb9
2 changed files with 40 additions and 15 deletions

View file

@ -6,24 +6,26 @@ mod vst3;
pub struct Plugin {
name: String,
path: String,
plugin: Option<PluginKind>
}
enum PluginKind {
VST2(::vst::host::PluginInstance),
VST3,
LV2(::livi::Plugin),
LV2(Vec<::livi::Port>, ::livi::Instance),
}
const HELM: &'static str = "file:///nix/store/ij3sz7nqg5l7v2dygdvzy3w6cj62bd6r-helm-0.9.0/lib/lv2/helm.lv2";
impl Plugin {
pub fn new (name: &str) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
let device = DynamicDevice::new(render, handle, process, Self {
name: name.into(),
path: HELM.into(),
plugin: None,
});
device.state.lock().unwrap().plugin = Some(self::lv2::plug_in(
"file:///nix/store/ij3sz7nqg5l7v2dygdvzy3w6cj62bd6r-helm-0.9.0/lib/lv2/helm.lv2"
)?);
device.state.lock().unwrap().plugin = Some(self::lv2::plug_in(HELM)?);
Ok(device)
}
}
@ -38,15 +40,32 @@ pub fn render (state: &Plugin, buf: &mut Buffer, Rect { x, y, .. }: Rect)
-> Usually<Rect>
{
let style = Style::default().gray();
draw_box(buf, Rect { x, y, width: 40, height: 8 });
buf.set_string(x + 1, y + 1, &format!(" {}", state.name), style.white().bold());
buf.set_string(x + 13, y + 1, &format!("Plugin Name"), style.not_dim());
buf.set_string(x + 13, y + 1, &format!("...{}...", &HELM[13..30]), style.not_dim());
buf.set_string(x + 0, y + 2, &format!("├--------------------------------------┤"), style.dim());
buf.set_string(x + 1, y + 3, &format!(" Parameter 1 0.0"), style);
buf.set_string(x + 1, y + 4, &format!(" Parameter 2 0.0"), style);
buf.set_string(x + 1, y + 5, &format!(" Parameter 3 0.0"), style);
buf.set_string(x + 1, y + 6, &format!(" Parameter 4 0.0"), style);
Ok(Rect { x, y, width: 40, height: 7 })
match &state.plugin {
Some(PluginKind::LV2(ports, instance)) => {
let mut height = 3;
for (i, port) in ports.iter().enumerate() {
if i >= 10 {
break
}
buf.set_string(x + 2, y + 3 + i as u16, &format!("{:20} = {:03}",
port.name,
port.default_value
), Style::default());
height = height + 1;
}
Ok(draw_box(buf, Rect { x, y, width: 40, height }))
},
_ => {
buf.set_string(x + 1, y + 3, &format!(" Parameter 1 0.0"), style);
buf.set_string(x + 1, y + 4, &format!(" Parameter 2 0.0"), style);
buf.set_string(x + 1, y + 5, &format!(" Parameter 3 0.0"), style);
buf.set_string(x + 1, y + 6, &format!(" Parameter 4 0.0"), style);
Ok(draw_box(buf, Rect { x, y, width: 40, height: 7 }))
}
}
}
pub fn handle (_: &mut Plugin, _: &AppEvent) -> Usually<bool> {

View file

@ -1,9 +1,9 @@
use crate::prelude::*;
use super::*;
pub fn plug_in (path: &str) -> Usually<PluginKind> {
let world = ::livi::World::with_load_bundle(&path);
world.build_features(::livi::FeaturesBuilder {
pub fn plug_in (uri: &str) -> Usually<PluginKind> {
let world = ::livi::World::with_load_bundle(&uri);
let features = world.build_features(::livi::FeaturesBuilder {
min_block_length: 1,
max_block_length: 65536,
});
@ -12,6 +12,12 @@ pub fn plug_in (path: &str) -> Usually<PluginKind> {
plugin = Some(p);
break
}
let result = PluginKind::LV2(plugin.unwrap());
let plugin = plugin.unwrap();
let mut ports = vec![];
for port in plugin.ports() {
ports.push(port);
}
let instance = unsafe { plugin.instantiate(features.clone(), 48000.0).expect("boop") };
let result = PluginKind::LV2(ports, instance);
Ok(result)
}