mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
110 lines
3.5 KiB
Rust
110 lines
3.5 KiB
Rust
use crate::*;
|
|
|
|
/// A plugin device.
|
|
pub struct Plugin<E> {
|
|
_engine: PhantomData<E>,
|
|
pub name: String,
|
|
pub path: Option<String>,
|
|
pub plugin: Option<PluginKind>,
|
|
pub selected: usize,
|
|
pub mapping: bool,
|
|
pub ports: JackPorts,
|
|
}
|
|
|
|
impl<E> Plugin<E> {
|
|
/// Create a plugin host device.
|
|
pub fn new (name: &str) -> Usually<Self> {
|
|
Ok(Self {
|
|
_engine: Default::default(),
|
|
name: name.into(),
|
|
path: None,
|
|
plugin: None,
|
|
selected: 0,
|
|
mapping: false,
|
|
ports: JackPorts::default()
|
|
})
|
|
}
|
|
}
|
|
|
|
impl Plugin<Tui> {
|
|
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)),
|
|
selected: 0,
|
|
mapping: false,
|
|
ports
|
|
}))
|
|
}
|
|
}
|
|
|
|
impl<E> Audio for Plugin<E> {
|
|
fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
|
match self.plugin.as_mut() {
|
|
Some(PluginKind::LV2(LV2Plugin {
|
|
features,
|
|
ref mut instance,
|
|
ref mut input_buffer,
|
|
..
|
|
})) => {
|
|
let urid = features.midi_urid();
|
|
input_buffer.clear();
|
|
for port in self.ports.midi_ins.values() {
|
|
let mut atom = ::livi::event::LV2AtomSequence::new(
|
|
&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(),
|
|
_ => {}
|
|
}
|
|
}
|
|
input_buffer.push(atom);
|
|
}
|
|
let mut outputs = vec![];
|
|
for _ in self.ports.midi_outs.iter() {
|
|
outputs.push(::livi::event::LV2AtomSequence::new(
|
|
&features,
|
|
scope.n_frames() as usize
|
|
));
|
|
}
|
|
let ports = ::livi::EmptyPortConnections::new()
|
|
.with_atom_sequence_inputs(
|
|
input_buffer.iter()
|
|
)
|
|
.with_atom_sequence_outputs(
|
|
outputs.iter_mut()
|
|
)
|
|
.with_audio_inputs(
|
|
self.ports.audio_ins.values().map(|o|o.as_slice(scope))
|
|
)
|
|
.with_audio_outputs(
|
|
self.ports.audio_outs.values_mut().map(|o|o.as_mut_slice(scope))
|
|
);
|
|
unsafe {
|
|
instance.run(scope.n_frames() as usize, ports).unwrap()
|
|
};
|
|
},
|
|
_ => {}
|
|
}
|
|
Control::Continue
|
|
}
|
|
}
|
|
|
|
/// Supported plugin formats.
|
|
pub enum PluginKind {
|
|
LV2(LV2Plugin),
|
|
VST2 {
|
|
instance: ::vst::host::PluginInstance
|
|
},
|
|
VST3,
|
|
}
|