From ce1c28edb9de2b3bdc2208c191e9e10ddb56ea05 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Thu, 20 Jun 2024 21:08:35 +0300 Subject: [PATCH] fetching lv2 parameters --- src/device/plugin.rs | 41 +++++++++++++++++++++++++++++----------- src/device/plugin/lv2.rs | 14 ++++++++++---- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/device/plugin.rs b/src/device/plugin.rs index 68d8f279..daeb9324 100644 --- a/src/device/plugin.rs +++ b/src/device/plugin.rs @@ -6,24 +6,26 @@ mod vst3; pub struct Plugin { name: String, + path: String, plugin: Option } 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, Box> { 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 { 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 { diff --git a/src/device/plugin/lv2.rs b/src/device/plugin/lv2.rs index 85e1ac17..413334e3 100644 --- a/src/device/plugin/lv2.rs +++ b/src/device/plugin/lv2.rs @@ -1,9 +1,9 @@ use crate::prelude::*; use super::*; -pub fn plug_in (path: &str) -> Usually { - let world = ::livi::World::with_load_bundle(&path); - world.build_features(::livi::FeaturesBuilder { +pub fn plug_in (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, }); @@ -12,6 +12,12 @@ pub fn plug_in (path: &str) -> Usually { 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) }