mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-04-04 05:10:44 +02:00
wip: nermalize
This commit is contained in:
parent
915e13aec8
commit
35197fb826
12 changed files with 4649 additions and 4718 deletions
150
src/plugin.rs
150
src/plugin.rs
|
|
@ -26,3 +26,153 @@
|
|||
pub window: Option<Window>
|
||||
}
|
||||
|
||||
impl_audio!(Lv2: lv2_jack_process);
|
||||
|
||||
impl Lv2 {
|
||||
const INPUT_BUFFER: usize = 1024;
|
||||
pub fn new (
|
||||
jack: &Jack<'static>,
|
||||
name: &str,
|
||||
uri: &str,
|
||||
) -> Usually<Self> {
|
||||
let lv2_world = livi::World::with_load_bundle(&uri);
|
||||
let lv2_features = lv2_world.build_features(livi::FeaturesBuilder {
|
||||
min_block_length: 1,
|
||||
max_block_length: 65536,
|
||||
});
|
||||
let lv2_plugin = lv2_world.iter_plugins().nth(0)
|
||||
.unwrap_or_else(||panic!("plugin not found: {uri}"));
|
||||
Ok(Self {
|
||||
jack: jack.clone(),
|
||||
name: name.into(),
|
||||
path: Some(String::from(uri).into()),
|
||||
selected: 0,
|
||||
mapping: false,
|
||||
midi_ins: vec![],
|
||||
midi_outs: vec![],
|
||||
audio_ins: vec![],
|
||||
audio_outs: vec![],
|
||||
lv2_instance: unsafe {
|
||||
lv2_plugin
|
||||
.instantiate(lv2_features.clone(), 48000.0)
|
||||
.expect(&format!("instantiate failed: {uri}"))
|
||||
},
|
||||
lv2_port_list: lv2_plugin.ports().collect::<Vec<_>>(),
|
||||
lv2_input_buffer: Vec::with_capacity(Self::INPUT_BUFFER),
|
||||
lv2_ui_thread: None,
|
||||
lv2_world,
|
||||
lv2_features,
|
||||
lv2_plugin,
|
||||
})
|
||||
}
|
||||
}
|
||||
fn lv2_jack_process (
|
||||
Lv2 {
|
||||
midi_ins, midi_outs, audio_ins, audio_outs,
|
||||
lv2_features, lv2_instance, lv2_input_buffer, ..
|
||||
}: &mut Lv2,
|
||||
_client: &Client,
|
||||
scope: &ProcessScope
|
||||
) -> Control {
|
||||
let urid = lv2_features.midi_urid();
|
||||
lv2_input_buffer.clear();
|
||||
for port in midi_ins.iter() {
|
||||
let mut atom = ::livi::event::LV2AtomSequence::new(
|
||||
&lv2_features,
|
||||
scope.n_frames() as usize
|
||||
);
|
||||
for event in port.iter(scope) {
|
||||
match event.bytes.len() {
|
||||
3 => atom.push_midi_event::<3>(
|
||||
event.time as i64,
|
||||
urid,
|
||||
&event.bytes[0..3]
|
||||
).unwrap(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
lv2_input_buffer.push(atom);
|
||||
}
|
||||
let mut outputs = vec![];
|
||||
for _ in midi_outs.iter() {
|
||||
outputs.push(::livi::event::LV2AtomSequence::new(
|
||||
lv2_features,
|
||||
scope.n_frames() as usize
|
||||
));
|
||||
}
|
||||
let ports = ::livi::EmptyPortConnections::new()
|
||||
.with_atom_sequence_inputs(lv2_input_buffer.iter())
|
||||
.with_atom_sequence_outputs(outputs.iter_mut())
|
||||
.with_audio_inputs(audio_ins.iter().map(|o|o.as_slice(scope)))
|
||||
.with_audio_outputs(audio_outs.iter_mut().map(|o|o.as_mut_slice(scope)));
|
||||
unsafe {
|
||||
lv2_instance.run(scope.n_frames() as usize, ports).unwrap()
|
||||
};
|
||||
Control::Continue
|
||||
}
|
||||
|
||||
impl LV2PluginUI { pub fn new () -> Usually<Self> { Ok(Self { window: None }) } }
|
||||
|
||||
impl ApplicationHandler for LV2PluginUI {
|
||||
fn resumed (&mut self, event_loop: &ActiveEventLoop) {
|
||||
self.window = Some(event_loop.create_window(Window::default_attributes()).unwrap());
|
||||
}
|
||||
fn window_event (&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => {
|
||||
self.window.as_ref().unwrap().set_visible(false);
|
||||
event_loop.exit();
|
||||
},
|
||||
WindowEvent::RedrawRequested => {
|
||||
self.window.as_ref().unwrap().request_redraw();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Draw<Tui> for Lv2 {
|
||||
fn draw(self, to: &mut Tui) {
|
||||
let area = to.area();
|
||||
let XYWH(x, y, _, height) = area;
|
||||
let mut width = 20u16;
|
||||
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) = self.lv2_port_list.get(i) {
|
||||
let value = if let Some(value) = self.lv2_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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn draw_header (state: &Lv2, to: &mut Tui, x: u16, y: u16, w: u16) {
|
||||
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 })
|
||||
}
|
||||
|
||||
#[cfg(feature = "vst2")] impl<E: Engine> ::vst::host::Host for Plugin<E> {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue