mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
plugin ins/outs
This commit is contained in:
parent
da1d3220f9
commit
9351887ae6
9 changed files with 187 additions and 64 deletions
|
|
@ -121,16 +121,35 @@ impl Launcher {
|
|||
],
|
||||
chains: vec![
|
||||
Chain::new("Chain#0000", vec![
|
||||
Box::new(Plugin::new("Plugin#000")?),
|
||||
Plugin::lv2(
|
||||
"Plugin#000",
|
||||
"file:///home/user/.lv2/ChowKick.lv2",
|
||||
&[1, 1, 0, 2]
|
||||
)?.boxed(),
|
||||
])?,
|
||||
|
||||
Chain::new("Chain#0000", vec![
|
||||
Box::new(Plugin::new("Plugin#001")?),
|
||||
Plugin::lv2(
|
||||
"Plugin#001",
|
||||
"file:///home/user/.lv2/Helm.lv2",
|
||||
&[1, 0, 0, 2]
|
||||
)?.boxed(),
|
||||
])?,
|
||||
|
||||
Chain::new("Chain#0000", vec![
|
||||
Box::new(Plugin::new("Plugin#002")?),
|
||||
Plugin::lv2(
|
||||
"Plugin#002",
|
||||
"file:///home/user/.lv2/Helm.lv2",
|
||||
&[1, 0, 0, 2]
|
||||
)?.boxed(),
|
||||
])?,
|
||||
|
||||
Chain::new("Chain#0000", vec![
|
||||
Box::new(Plugin::new("Plugin#003")?),
|
||||
Plugin::lv2(
|
||||
"Plugin#003",
|
||||
"file:///home/user/.lv2/Odin2.lv2",
|
||||
&[1, 0, 0, 2]
|
||||
)?.boxed(),
|
||||
])?,
|
||||
],
|
||||
timebase,
|
||||
|
|
@ -506,18 +525,27 @@ fn play_toggle (s: &mut Launcher) -> Usually<bool> {
|
|||
};
|
||||
Ok(true)
|
||||
}
|
||||
fn play_start (s: &mut Launcher) -> Usually<bool> {
|
||||
fn play_start (_: &mut Launcher) -> Usually<bool> {
|
||||
unimplemented!()
|
||||
}
|
||||
fn record_toggle (s: &mut Launcher) -> Usually<bool> {
|
||||
s.recording = !s.recording;
|
||||
for sequencer in s.tracks.iter() {
|
||||
sequencer.state().recording = s.recording;
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
fn overdub_toggle (s: &mut Launcher) -> Usually<bool> {
|
||||
s.overdub = !s.overdub;
|
||||
for sequencer in s.tracks.iter() {
|
||||
sequencer.state().overdub = s.overdub;
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
fn monitor_toggle (s: &mut Launcher) -> Usually<bool> {
|
||||
s.monitoring = !s.monitoring;
|
||||
for sequencer in s.tracks.iter() {
|
||||
sequencer.state().monitoring = s.monitoring;
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,16 @@ mod vst2;
|
|||
mod vst3;
|
||||
|
||||
pub struct Plugin {
|
||||
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],
|
||||
name: String,
|
||||
path: Option<String>,
|
||||
plugin: Option<PluginKind>,
|
||||
offset: usize,
|
||||
selected: usize,
|
||||
mapping: bool,
|
||||
midi_ins: Vec<Port<MidiIn>>,
|
||||
midi_outs: Vec<Port<MidiOut>>,
|
||||
audio_ins: Vec<Port<AudioIn>>,
|
||||
audio_outs: Vec<Port<AudioOut>>,
|
||||
}
|
||||
|
||||
enum PluginKind {
|
||||
|
|
@ -31,44 +33,100 @@ enum PluginKind {
|
|||
const HELM: &'static str = "file:///nix/store/ij3sz7nqg5l7v2dygdvzy3w6cj62bd6r-helm-0.9.0/lib/lv2/helm.lv2";
|
||||
|
||||
impl Plugin {
|
||||
pub fn new (name: &str) -> Result<DynamicDevice<Self>, Box<dyn Error>> {
|
||||
/// Load a LV2 plugin.
|
||||
pub fn lv2 (name: &str, path: &str, ports: &[usize;4]) -> Usually<DynamicDevice<Self>> {
|
||||
let plugin = Self::new(name, ports)?;
|
||||
let mut state = plugin.state();
|
||||
state.plugin = Some(self::lv2::plug(path)?);
|
||||
state.path = Some(String::from(path));
|
||||
std::mem::drop(state);
|
||||
Ok(plugin)
|
||||
}
|
||||
pub fn new (name: &str, ports: &[usize;4]) -> Usually<DynamicDevice<Self>> {
|
||||
let (client, _status) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
||||
let [midi_ins, midi_outs, audio_ins, audio_outs] = ports;
|
||||
DynamicDevice::new(render, handle, Self::process, Self {
|
||||
name: name.into(),
|
||||
path: HELM.into(),
|
||||
plugin: Some(self::lv2::plug(HELM)?),
|
||||
path: None,
|
||||
plugin: None,
|
||||
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())?,
|
||||
],
|
||||
midi_ins: {
|
||||
let mut ports = vec![];
|
||||
for i in 0..*midi_ins {
|
||||
ports.push(client.register_port(&format!("midi-in-{i}"), MidiIn::default())?)
|
||||
}
|
||||
ports
|
||||
},
|
||||
midi_outs: {
|
||||
let mut ports = vec![];
|
||||
for i in 0..*midi_outs {
|
||||
ports.push(client.register_port(&format!("midi-out-{i}"), MidiOut::default())?)
|
||||
}
|
||||
ports
|
||||
},
|
||||
audio_ins: {
|
||||
let mut ports = vec![];
|
||||
for i in 0..*audio_ins {
|
||||
ports.push(client.register_port(&format!("audio-in-{i}"), AudioIn::default())?)
|
||||
}
|
||||
ports
|
||||
},
|
||||
audio_outs: {
|
||||
let mut ports = vec![];
|
||||
for i in 0..*audio_outs {
|
||||
ports.push(client.register_port(&format!("audio-out-{i}"), AudioOut::default())?)
|
||||
}
|
||||
ports
|
||||
},
|
||||
}).activate(client)
|
||||
}
|
||||
|
||||
pub fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
|
||||
match self.plugin.as_mut() {
|
||||
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.midi_in.iter(scope) {
|
||||
match event.bytes.len() {
|
||||
3 => input.push_midi_event::<3>(
|
||||
event.time as i64,
|
||||
urid,
|
||||
&event.bytes[0..3]
|
||||
).unwrap(),
|
||||
_ => {}
|
||||
let mut inputs = vec![];
|
||||
for port in self.midi_ins.iter() {
|
||||
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(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
inputs.push(atom);
|
||||
}
|
||||
let mut outputs = vec![];
|
||||
for port in self.midi_outs.iter() {
|
||||
outputs.push(::livi::event::LV2AtomSequence::new(
|
||||
&features,
|
||||
scope.n_frames() as usize
|
||||
));
|
||||
}
|
||||
let ports = ::livi::EmptyPortConnections::new()
|
||||
.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() };
|
||||
.with_atom_sequence_inputs(
|
||||
inputs.iter()
|
||||
)
|
||||
.with_atom_sequence_outputs(
|
||||
outputs.iter_mut()
|
||||
)
|
||||
.with_audio_inputs(
|
||||
self.audio_ins.iter().map(|o|o.as_slice(scope))
|
||||
)
|
||||
.with_audio_outputs(
|
||||
self.audio_outs.iter_mut().map(|o|o.as_mut_slice(scope))
|
||||
);
|
||||
unsafe {
|
||||
instance.run(scope.n_frames() as usize, ports).unwrap()
|
||||
};
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -77,16 +135,33 @@ impl Plugin {
|
|||
}
|
||||
|
||||
impl PortList for Plugin {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![
|
||||
self.midi_in.name()?
|
||||
])
|
||||
fn audio_ins (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.audio_ins.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
fn audio_outs (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![
|
||||
self.audio_out[0].name()?,
|
||||
self.audio_out[1].name()?
|
||||
])
|
||||
let mut ports = vec![];
|
||||
for port in self.audio_outs.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.midi_ins.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
let mut ports = vec![];
|
||||
for port in self.midi_outs.iter() {
|
||||
ports.push(port.name()?);
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,10 +175,13 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
|||
match &state.plugin {
|
||||
Some(PluginKind::LV2 { portList, instance, .. }) => {
|
||||
for i in 0..height - 4 {
|
||||
let port = &portList[i as usize];
|
||||
let label = &format!("C·· M·· {:25} = {:03}", port.name, port.default_value);
|
||||
width = width.max(label.len() as u16);
|
||||
label.blit(buf, x + 2, y + 3 + i as u16, None);
|
||||
if let Some(port) = portList.get(i as usize) {
|
||||
let label = &format!("C·· M·· {:25} = {:03}", port.name, port.default_value);
|
||||
width = width.max(label.len() as u16);
|
||||
label.blit(buf, x + 2, y + 3 + i as u16, None);
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
draw_box(buf, Rect { x, y, width, height });
|
||||
},
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ pub struct Sequencer {
|
|||
notes_on: Vec<bool>,
|
||||
|
||||
/// Play sequence to output.
|
||||
playing: TransportState,
|
||||
pub playing: TransportState,
|
||||
/// Play input through output.
|
||||
monitoring: bool,
|
||||
pub monitoring: bool,
|
||||
/// Write input to sequence.
|
||||
recording: bool,
|
||||
pub recording: bool,
|
||||
/// Don't delete when recording.
|
||||
overdub: bool,
|
||||
pub overdub: bool,
|
||||
|
||||
/// Display mode
|
||||
mode: SequencerView,
|
||||
|
|
@ -171,7 +171,7 @@ impl Sequencer {
|
|||
frame.push(event.bytes.into())
|
||||
}
|
||||
}
|
||||
if self.recording {
|
||||
if self.recording && self.playing == TransportState::Rolling {
|
||||
let contains = sequence.contains_key(&tick);
|
||||
if contains {
|
||||
sequence.get_mut(&tick).unwrap().push(message.clone());
|
||||
|
|
@ -191,7 +191,7 @@ impl Sequencer {
|
|||
frame.push(event.bytes.into())
|
||||
}
|
||||
}
|
||||
if self.recording {
|
||||
if self.recording && self.playing == TransportState::Rolling {
|
||||
let contains = sequence.contains_key(&tick);
|
||||
if contains {
|
||||
sequence.get_mut(&tick).unwrap().push(message.clone());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue