wip: component refactor

This commit is contained in:
🪞👃🪞 2024-06-21 12:13:11 +03:00
parent 5082bf9fdf
commit c18aa2cbbd
14 changed files with 374 additions and 272 deletions

View file

@ -7,7 +7,8 @@ mod vst3;
pub struct Plugin {
name: String,
path: String,
plugin: Option<PluginKind>
plugin: Option<PluginKind>,
parameter_offset: usize,
}
enum PluginKind {
@ -24,6 +25,7 @@ impl Plugin {
name: name.into(),
path: HELM.into(),
plugin: None,
parameter_offset: 0,
});
device.state.lock().unwrap().plugin = Some(self::lv2::plug_in(HELM)?);
Ok(device)
@ -40,13 +42,13 @@ pub fn render (state: &Plugin, buf: &mut Buffer, Rect { x, y, .. }: Rect)
-> Usually<Rect>
{
let style = Style::default().gray();
buf.set_string(x + 1, y + 1, &format!(" {}", state.name), style.white().bold());
buf.set_string(x + 1, y + 1, &format!(" {}", state.name), style.white().bold());
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 + 0, y + 2, &format!("├--------------------------------------┤"), style.dim());
match &state.plugin {
Some(PluginKind::LV2(ports, instance)) => {
let mut height = 3;
for (i, port) in ports.iter().enumerate() {
for (i, port) in ports.iter().skip(state.parameter_offset).enumerate() {
if i >= 10 {
break
}
@ -56,7 +58,7 @@ pub fn render (state: &Plugin, buf: &mut Buffer, Rect { x, y, .. }: Rect)
), Style::default());
height = height + 1;
}
Ok(draw_box(buf, Rect { x, y, width: 40, height }))
Ok(draw_box(buf, Rect { x, y, width: 40, height: height.max(10) }))
},
_ => {
buf.set_string(x + 1, y + 3, &format!(" Parameter 1 0.0"), style);
@ -68,6 +70,17 @@ pub fn render (state: &Plugin, buf: &mut Buffer, Rect { x, y, .. }: Rect)
}
}
pub fn handle (_: &mut Plugin, _: &AppEvent) -> Usually<bool> {
Ok(false)
pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
handle_keymap(s, event, keymap!(Plugin {
[Up, NONE, "cursor_up", "move cursor up",
|s: &mut Plugin|{
s.parameter_offset = s.parameter_offset.saturating_sub(1);
Ok(true)
}],
[Down, NONE, "cursor_down", "move cursor down",
|s: &mut Plugin|{
s.parameter_offset = s.parameter_offset + 1;
Ok(true)
}]
}))
}