From e967e04856f920ddec12e36e4eb3f95bc47fdddd Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 14 Jun 2022 21:43:26 +0200 Subject: [PATCH] Add auto connecting for JACK MIDI ports --- src/wrapper/standalone/backend/jack.rs | 12 +++++++++++- src/wrapper/standalone/config.rs | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/wrapper/standalone/backend/jack.rs b/src/wrapper/standalone/backend/jack.rs index c5796f3f..870d8c01 100644 --- a/src/wrapper/standalone/backend/jack.rs +++ b/src/wrapper/standalone/backend/jack.rs @@ -133,7 +133,6 @@ impl Jack { outputs.push(port); } - // TODO: CLI arguments to connect the MIDI input and output ports let midi_input = if P::MIDI_INPUT >= MidiConfig::Basic { Some(Arc::new(client.register_port("midi_input", MidiIn)?)) } else { @@ -168,6 +167,17 @@ impl Jack { } } + if let (Some(port), Some(port_name)) = (&midi_input, config.connect_jack_midi_input) { + if let Err(err) = client.connect_ports_by_name(&port_name, &port.name()?) { + nih_error!("Could not connect to '{port_name}': {err}"); + } + } + if let (Some(port), Some(port_name)) = (&midi_output, config.connect_jack_midi_output) { + if let Err(err) = client.connect_ports_by_name(&port.borrow().name()?, &port_name) { + nih_error!("Could not connect to '{port_name}': {err}"); + } + } + Ok(Self { client: Some(client), diff --git a/src/wrapper/standalone/config.rs b/src/wrapper/standalone/config.rs index 317a7bb5..16f6d967 100644 --- a/src/wrapper/standalone/config.rs +++ b/src/wrapper/standalone/config.rs @@ -37,6 +37,18 @@ pub struct WrapperConfig { #[clap(value_parser, long)] pub connect_jack_inputs: Option, + /// If set, then the plugin's MIDI input port will be connected to this JACK MIDI output port. + /// + /// This option is only used with the JACK backend. + #[clap(value_parser, long)] + pub connect_jack_midi_input: Option, + + /// If set, then the plugin's MIDI output port will be connected to this JACK MIDI input port. + /// + /// This option is only used with the JACK backend. + #[clap(value_parser, long)] + pub connect_jack_midi_output: Option, + /// The editor's DPI scaling factor. /// /// This option is ignored on macOS.