mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-10 05:36:42 +01:00
port connections; DevicePorts -> PortList
This commit is contained in:
parent
b1df7bf4e6
commit
22b44f562b
8 changed files with 117 additions and 77 deletions
|
|
@ -5,24 +5,22 @@ mod vst2;
|
|||
mod vst3;
|
||||
|
||||
pub struct Plugin {
|
||||
name: String,
|
||||
input: ::jack::Port<::jack::MidiIn>,
|
||||
outputs: [::jack::Port<::jack::AudioOut>;2],
|
||||
path: String,
|
||||
plugin: Option<PluginKind>,
|
||||
offset: usize,
|
||||
selected: usize,
|
||||
midi_map_enable: bool,
|
||||
name: String,
|
||||
path: String,
|
||||
plugin: Option<PluginKind>,
|
||||
offset: usize,
|
||||
selected: usize,
|
||||
mapping: bool,
|
||||
midi_in: ::jack::Port<::jack::MidiIn>,
|
||||
audio_out: [::jack::Port<::jack::AudioOut>;2],
|
||||
}
|
||||
|
||||
enum PluginKind {
|
||||
LV2 {
|
||||
world: ::livi::World,
|
||||
features: Arc<::livi::Features>,
|
||||
input: ::livi::event::LV2AtomSequence,
|
||||
portList: Vec<::livi::Port>,
|
||||
instance: ::livi::Instance,
|
||||
outputs: [Vec<f32>;2],
|
||||
world: ::livi::World,
|
||||
features: Arc<::livi::Features>,
|
||||
portList: Vec<::livi::Port>,
|
||||
instance: ::livi::Instance,
|
||||
},
|
||||
VST2 {
|
||||
instance: ::vst::host::PluginInstance
|
||||
|
|
@ -37,29 +35,27 @@ impl Plugin {
|
|||
let (client, _status) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
||||
DynamicDevice::new(render, handle, Self::process, Self {
|
||||
name: name.into(),
|
||||
input: client.register_port("in", MidiIn::default())?,
|
||||
outputs: [
|
||||
path: HELM.into(),
|
||||
plugin: Some(self::lv2::plug(HELM)?),
|
||||
offset: 0,
|
||||
selected: 0,
|
||||
mapping: false,
|
||||
midi_in: client.register_port("in", MidiIn::default())?,
|
||||
audio_out: [
|
||||
client.register_port("outL", AudioOut::default())?,
|
||||
client.register_port("outR", AudioOut::default())?,
|
||||
],
|
||||
path: HELM.into(),
|
||||
plugin: Some(self::lv2::plug_in(HELM)?),
|
||||
offset: 0,
|
||||
selected: 0,
|
||||
midi_map_enable: false
|
||||
}).activate(client)
|
||||
}
|
||||
|
||||
pub fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
match self.plugin.as_mut() {
|
||||
Some(PluginKind::LV2 {
|
||||
features, input, ref mut instance, ..
|
||||
}) => {
|
||||
Some(PluginKind::LV2 { features, ref mut instance, .. }) => {
|
||||
let mut input = ::livi::event::LV2AtomSequence::new(
|
||||
&features, scope.n_frames() as usize
|
||||
);
|
||||
let urid = features.midi_urid();
|
||||
for event in self.input.iter(scope) {
|
||||
for event in self.midi_in.iter(scope) {
|
||||
match event.bytes.len() {
|
||||
3 => input.push_midi_event::<3>(
|
||||
event.time as i64,
|
||||
|
|
@ -70,18 +66,9 @@ impl Plugin {
|
|||
}
|
||||
}
|
||||
let ports = ::livi::EmptyPortConnections::new()
|
||||
.with_atom_sequence_inputs(
|
||||
std::iter::once(&input)
|
||||
)
|
||||
.with_audio_outputs(
|
||||
self.outputs.iter_mut().map(|o|o.as_mut_slice(scope)),
|
||||
);
|
||||
unsafe {
|
||||
instance.run(
|
||||
scope.n_frames() as usize,
|
||||
ports
|
||||
).unwrap()
|
||||
};
|
||||
.with_atom_sequence_inputs(std::iter::once(&input))
|
||||
.with_audio_outputs(self.audio_out.iter_mut().map(|o|o.as_mut_slice(scope)));
|
||||
unsafe { instance.run(scope.n_frames() as usize, ports).unwrap() };
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -89,7 +76,19 @@ impl Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
impl ::vst::host::Host for Plugin {}
|
||||
impl PortList for Plugin {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![
|
||||
self.midi_in.name()?
|
||||
])
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![
|
||||
self.audio_out[0].name()?,
|
||||
self.audio_out[1].name()?
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
||||
-> Usually<Rect>
|
||||
|
|
@ -150,17 +149,8 @@ pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
|
|||
}],
|
||||
[Char('m'), NONE, "toggle_midi_map", "toggle midi map mode",
|
||||
|s: &mut Plugin|{
|
||||
s.midi_map_enable = !s.midi_map_enable;
|
||||
s.mapping = !s.mapping;
|
||||
Ok(true)
|
||||
}]
|
||||
}))
|
||||
}
|
||||
|
||||
impl DevicePorts for Plugin {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec!["in".into()])
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec!["outL".into(), "outR".into()])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue