mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: tek_test again
This commit is contained in:
parent
fa8282a9d5
commit
4c23aed40a
16 changed files with 190 additions and 172 deletions
|
|
@ -13,19 +13,21 @@ submod! {
|
|||
mixer
|
||||
mixer_cli
|
||||
mixer_handle
|
||||
track
|
||||
track_view
|
||||
track_handle
|
||||
plugin
|
||||
plugin_handle
|
||||
plugin_lv2
|
||||
plugin_lv2_gui
|
||||
plugin_view
|
||||
plugin_vst2
|
||||
plugin_vst3
|
||||
sample
|
||||
sample_add
|
||||
sampler
|
||||
sampler_edn
|
||||
sampler_view
|
||||
sampler_handle
|
||||
sampler_view
|
||||
track
|
||||
track_handle
|
||||
track_view
|
||||
voice
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use crate::*;
|
||||
|
||||
/// A plugin device.
|
||||
pub struct Plugin {
|
||||
pub struct Plugin<E> {
|
||||
_engine: PhantomData<E>,
|
||||
pub name: String,
|
||||
pub path: Option<String>,
|
||||
pub plugin: Option<PluginKind>,
|
||||
|
|
@ -9,63 +10,13 @@ pub struct Plugin {
|
|||
pub mapping: bool,
|
||||
pub ports: JackPorts,
|
||||
}
|
||||
impl Handle<Tui> for Plugin {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
handle_keymap(self, &from.event(), KEYMAP_PLUGIN).map(|x|Some(x))
|
||||
}
|
||||
}
|
||||
process!(Plugin = Plugin::process);
|
||||
impl Render<Tui> for Plugin {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
let [x, y, _, height] = area;
|
||||
let mut width = 20u16;
|
||||
match &self.plugin {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
|
||||
let start = self.selected.saturating_sub((height as usize / 2).saturating_sub(1));
|
||||
let end = start + height as usize - 2;
|
||||
//draw_box(buf, Rect { x, y, width, height });
|
||||
for i in start..end {
|
||||
if let Some(port) = port_list.get(i) {
|
||||
let value = if let Some(value) = instance.control_input(port.index) {
|
||||
value
|
||||
} else {
|
||||
port.default_value
|
||||
};
|
||||
//let label = &format!("C·· M·· {:25} = {value:.03}", port.name);
|
||||
let label = &format!("{:25} = {value:.03}", port.name);
|
||||
width = width.max(label.len() as u16 + 4);
|
||||
let style = if i == self.selected {
|
||||
Some(Style::default().green())
|
||||
} else {
|
||||
None
|
||||
} ;
|
||||
to.blit(&label, x + 2, y + 1 + i as u16 - start as u16, style)?;
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
};
|
||||
draw_header(self, to, x, y, width)?;
|
||||
Ok(Some([x, y, width, height]))
|
||||
}
|
||||
}
|
||||
|
||||
/// Supported plugin formats.
|
||||
pub enum PluginKind {
|
||||
LV2(LV2Plugin),
|
||||
VST2 {
|
||||
instance: ::vst::host::PluginInstance
|
||||
},
|
||||
VST3,
|
||||
}
|
||||
impl Plugin {
|
||||
impl<E> Plugin<E> {
|
||||
pub fn new_lv2 (name: &str, path: &str) -> Usually<JackDevice<Tui>> {
|
||||
let plugin = LV2Plugin::new(path)?;
|
||||
jack_from_lv2(name, &plugin.plugin)?
|
||||
.run(|ports|Box::new(Self {
|
||||
_engine: Default::default(),
|
||||
name: name.into(),
|
||||
path: Some(String::from(path)),
|
||||
plugin: Some(PluginKind::LV2(plugin)),
|
||||
|
|
@ -77,6 +28,7 @@ impl Plugin {
|
|||
/// Create a plugin host device.
|
||||
pub fn new (name: &str) -> Usually<Self> {
|
||||
Ok(Self {
|
||||
_engine: Default::default(),
|
||||
name: name.into(),
|
||||
path: None,
|
||||
plugin: None,
|
||||
|
|
@ -85,7 +37,10 @@ impl Plugin {
|
|||
ports: JackPorts::default()
|
||||
})
|
||||
}
|
||||
pub fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
}
|
||||
|
||||
impl<E> Process for Plugin<E> {
|
||||
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
match self.plugin.as_mut() {
|
||||
Some(PluginKind::LV2(LV2Plugin {
|
||||
features,
|
||||
|
|
@ -141,79 +96,12 @@ impl Plugin {
|
|||
Control::Continue
|
||||
}
|
||||
}
|
||||
fn draw_header (state: &Plugin, to: &mut Tui, x: u16, y: u16, w: u16) -> Usually<Rect> {
|
||||
let style = Style::default().gray();
|
||||
let label1 = format!(" {}", state.name);
|
||||
to.blit(&label1, x + 1, y, Some(style.white().bold()))?;
|
||||
if let Some(ref path) = state.path {
|
||||
let label2 = format!("{}…", &path[..((w as usize - 10).min(path.len()))]);
|
||||
to.blit(&label2, x + 2 + label1.len() as u16, y, Some(style.not_dim()))?;
|
||||
}
|
||||
Ok(Rect { x, y, width: w, height: 1 })
|
||||
}
|
||||
|
||||
/// Key bindings for plugin device.
|
||||
pub const KEYMAP_PLUGIN: &'static [KeyBinding<Plugin>] = keymap!(Plugin {
|
||||
[Up, NONE, "/plugin/cursor_up", "move cursor up", |s: &mut Plugin|{
|
||||
s.selected = s.selected.saturating_sub(1);
|
||||
Ok(true)
|
||||
}],
|
||||
[Down, NONE, "/plugin/cursor_down", "move cursor down", |s: &mut Plugin|{
|
||||
s.selected = (s.selected + 1).min(match &s.plugin {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => port_list.len() - 1,
|
||||
_ => unimplemented!()
|
||||
});
|
||||
Ok(true)
|
||||
}],
|
||||
[PageUp, NONE, "/plugin/cursor_page_up", "move cursor up", |s: &mut Plugin|{
|
||||
s.selected = s.selected.saturating_sub(8);
|
||||
Ok(true)
|
||||
}],
|
||||
[PageDown, NONE, "/plugin/cursor_page_down", "move cursor down", |s: &mut Plugin|{
|
||||
s.selected = (s.selected + 10).min(match &s.plugin {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => port_list.len() - 1,
|
||||
_ => unimplemented!()
|
||||
});
|
||||
Ok(true)
|
||||
}],
|
||||
[Char(','), NONE, "/plugin/decrement", "decrement value", |s: &mut Plugin|{
|
||||
match s.plugin.as_mut() {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => {
|
||||
let index = port_list[s.selected].index;
|
||||
if let Some(value) = instance.control_input(index) {
|
||||
instance.set_control_input(index, value - 0.01);
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('.'), NONE, "/plugin/decrement", "increment value", |s: &mut Plugin|{
|
||||
match s.plugin.as_mut() {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => {
|
||||
let index = port_list[s.selected].index;
|
||||
if let Some(value) = instance.control_input(index) {
|
||||
instance.set_control_input(index, value + 0.01);
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('g'), NONE, "/plugin/gui_toggle", "toggle plugin UI", |s: &mut Plugin|{
|
||||
match s.plugin {
|
||||
Some(PluginKind::LV2(ref mut plugin)) => {
|
||||
plugin.ui_thread = Some(run_lv2_ui(LV2PluginUI::new()?)?);
|
||||
},
|
||||
Some(_) => unreachable!(),
|
||||
None => {}
|
||||
}
|
||||
Ok(true)
|
||||
}],
|
||||
});
|
||||
|
||||
impl Layout<Tui> for Plugin {
|
||||
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
todo!()
|
||||
}
|
||||
/// Supported plugin formats.
|
||||
pub enum PluginKind {
|
||||
LV2(LV2Plugin),
|
||||
VST2 {
|
||||
instance: ::vst::host::PluginInstance
|
||||
},
|
||||
VST3,
|
||||
}
|
||||
|
|
|
|||
67
crates/tek_mixer/src/plugin_handle.rs
Normal file
67
crates/tek_mixer/src/plugin_handle.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
use crate::*;
|
||||
|
||||
impl Handle<Tui> for Plugin<Tui> {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
handle_keymap(self, &from.event(), KEYMAP_PLUGIN).map(|x|Some(x))
|
||||
}
|
||||
}
|
||||
|
||||
/// Key bindings for plugin device.
|
||||
pub const KEYMAP_PLUGIN: &'static [KeyBinding<Plugin>] = keymap!(Plugin {
|
||||
[Up, NONE, "/plugin/cursor_up", "move cursor up", |s: &mut Plugin|{
|
||||
s.selected = s.selected.saturating_sub(1);
|
||||
Ok(true)
|
||||
}],
|
||||
[Down, NONE, "/plugin/cursor_down", "move cursor down", |s: &mut Plugin|{
|
||||
s.selected = (s.selected + 1).min(match &s.plugin {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => port_list.len() - 1,
|
||||
_ => unimplemented!()
|
||||
});
|
||||
Ok(true)
|
||||
}],
|
||||
[PageUp, NONE, "/plugin/cursor_page_up", "move cursor up", |s: &mut Plugin|{
|
||||
s.selected = s.selected.saturating_sub(8);
|
||||
Ok(true)
|
||||
}],
|
||||
[PageDown, NONE, "/plugin/cursor_page_down", "move cursor down", |s: &mut Plugin|{
|
||||
s.selected = (s.selected + 10).min(match &s.plugin {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, .. })) => port_list.len() - 1,
|
||||
_ => unimplemented!()
|
||||
});
|
||||
Ok(true)
|
||||
}],
|
||||
[Char(','), NONE, "/plugin/decrement", "decrement value", |s: &mut Plugin|{
|
||||
match s.plugin.as_mut() {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => {
|
||||
let index = port_list[s.selected].index;
|
||||
if let Some(value) = instance.control_input(index) {
|
||||
instance.set_control_input(index, value - 0.01);
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('.'), NONE, "/plugin/decrement", "increment value", |s: &mut Plugin|{
|
||||
match s.plugin.as_mut() {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, ref mut instance, .. })) => {
|
||||
let index = port_list[s.selected].index;
|
||||
if let Some(value) = instance.control_input(index) {
|
||||
instance.set_control_input(index, value + 0.01);
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('g'), NONE, "/plugin/gui_toggle", "toggle plugin UI", |s: &mut Plugin|{
|
||||
match s.plugin {
|
||||
Some(PluginKind::LV2(ref mut plugin)) => {
|
||||
plugin.ui_thread = Some(run_lv2_ui(LV2PluginUI::new()?)?);
|
||||
},
|
||||
Some(_) => unreachable!(),
|
||||
None => {}
|
||||
}
|
||||
Ok(true)
|
||||
}],
|
||||
});
|
||||
54
crates/tek_mixer/src/plugin_view.rs
Normal file
54
crates/tek_mixer/src/plugin_view.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use crate::*;
|
||||
|
||||
impl Widget for Plugin<Tui> {
|
||||
type Engine = Tui;
|
||||
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
Ok(Some(to))
|
||||
}
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
let [x, y, _, height] = area;
|
||||
let mut width = 20u16;
|
||||
match &self.plugin {
|
||||
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
|
||||
let start = self.selected.saturating_sub((height as usize / 2).saturating_sub(1));
|
||||
let end = start + height as usize - 2;
|
||||
//draw_box(buf, Rect { x, y, width, height });
|
||||
for i in start..end {
|
||||
if let Some(port) = port_list.get(i) {
|
||||
let value = if let Some(value) = instance.control_input(port.index) {
|
||||
value
|
||||
} else {
|
||||
port.default_value
|
||||
};
|
||||
//let label = &format!("C·· M·· {:25} = {value:.03}", port.name);
|
||||
let label = &format!("{:25} = {value:.03}", port.name);
|
||||
width = width.max(label.len() as u16 + 4);
|
||||
let style = if i == self.selected {
|
||||
Some(Style::default().green())
|
||||
} else {
|
||||
None
|
||||
} ;
|
||||
to.blit(&label, x + 2, y + 1 + i as u16 - start as u16, style)?;
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
};
|
||||
draw_header(self, to, x, y, width)?;
|
||||
Ok(Some([x, y, width, height]))
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_header <E> (state: &Plugin<E>, to: &mut Tui, x: u16, y: u16, w: u16) -> Usually<Rect> {
|
||||
let style = Style::default().gray();
|
||||
let label1 = format!(" {}", state.name);
|
||||
to.blit(&label1, x + 1, y, Some(style.white().bold()))?;
|
||||
if let Some(ref path) = state.path {
|
||||
let label2 = format!("{}…", &path[..((w as usize - 10).min(path.len()))]);
|
||||
to.blit(&label2, x + 2 + label1.len() as u16, y, Some(style.not_dim()))?;
|
||||
}
|
||||
Ok(Rect { x, y, width: w, height: 1 })
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue