2

I know it's possible to route audio between applications with Cadence and qjackctl, but is it possible to do so on the command line? I only ever have a couple of use cases and would prefer to have a simple alias to start JACK, the audio software, and make the connections.

3
  • If you're referencing Cadence, chances are you have installed the KXStudio repositories. Ubuntu Studio policy is that you no longer have Ubuntu Studio at that point. Please seek support from KXStudio. Jun 24, 2019 at 23:25
  • I am referencing either cadence or qjackctl. I understand that qjackctl is part of Ubuntu Studio.
    – Lxvb Wqrm
    Jun 25, 2019 at 0:21
  • I think it's to much for an alias, to start jack, load applications and make the connections you need a lot of commands, that would better fit in a small script.
    – mook765
    Jun 25, 2019 at 11:13

3 Answers 3

5

Bash's Tab-completion is a helpful feature when trying to find available commands, so in this case:

~$ jackTab
jack_alias                  jack_multiple_metro
jack_bufsize                jack_net_master
jack_capture                jack_net_slave
jack_capture_gui            jack_netsource
jack_connect                jack-osc
jack_control                jack-play
jack_cpu                    jack-plumbing
jack_cpu_load               jack-rack
jackd                       jack_rec
jackdbus                    jack-record
jack_disconnect             jack_samplerate
jack-dl                     jack-scope
jack-dssi-host              jack_server_control
jack_evmon                  jack_session_notify
jack_freewheel              jack_showtime
jack_iodelay                jack_simdtests
jack-keyboard               jack_simple_client
jack_latent_client          jack_simple_session_client
jack_load                   jack_test
jack_lsp                    jack_thru
jack_metro                  jack_transport
jack_midi_dump              jack-transport
jack_midi_latency_test      jack-udp
jack_midiseq                jack_unload
jack_midisine               jack_wait
jack_monitor_client         jack_zombie

jack_connect and jack_disconnect sound promising, let's take a look at man jack_connect:

NAME
       jack_connect,  jack_disconnect  - JACK toolkit clients for connecting &
       disconnecting ports

SYNOPSIS
        jack_connect [ -s | --server servername ] [-h | --help ] port1 port2
        jack_disconnect [ -s | --server servername ]  [-h  |  --help  ]  port1
       port2

DESCRIPTION
       jack_connect  connects the two named ports. jack_disconnect disconnects
       the two named ports.

We need to know the port-names, the jack_lsp-command will deliver the existing ports and connections, take a look at man jack_lsp. I started the jackd-server with pulseaudio and MIDI routed to jackd, here the output from jack_lsp -c:

~$ jack_lsp -c
system:capture_1
   PulseIn:front-left
system:capture_2
   PulseIn:front-right
system:playback_1
   PulseOut:front-left
system:playback_2
   PulseOut:front-right
PulseOut:front-left
   system:playback_1
PulseOut:front-right
   system:playback_2
PulseIn:front-left
   system:capture_1
PulseIn:front-right
   system:capture_2
a2j:Midi Through [14] (capture): Midi Through Port-0
a2j:Midi Through [14] (playback): Midi Through Port-0

Example commands:

~$ jack_disconnect PulseOut:front-left system:playback_1
~$ jack_connect PulseOut:front-left system:playback_1

With these commands I could successfully disconnect and reconnect this connection observing the connection dis- and reappearing in Carla which was running in the background while issuing the commands.

2
  • 1
    This is brilliant. I'm writing a bash script now which does this automatically.
    – Onkeltem
    May 31, 2020 at 19:42
  • jack_lsp -A gave me more practical names/aliases than -c did
    – Joost
    Feb 7, 2021 at 0:36
1

jack_connect and jack_disconnect work well, but has limitations

easy to work out connection commands from GUI packages qjackctl+patchage (or cadence+carla)
copy text from messages/status to a text file to get the connection names
can also to test commands one at a time by pasting into terminal

limited Linux command skills at the time couldn't get me equivalent of 'disconnect all' button in QjackCtl,
but i found an alternative solution:

http://aj-snapshot.sourceforge.net/

that has command to disconnect everything in JACK:

aj-snapshot -jx

but also had 'store' and 'restore' options like alsactl so command:

aj-snapshot -rjx filename

will clear JACK connections and load all connections saved in 'filename'

0

Yes, it is possible to do everything you would do in the qjackctl GUI, but from the command line instead. This includes creating new connections. Challenge yourself by automating your entire JACK workflow!

(Beyond that, you can do everything both can do, but with the libjack C library instead.)

Here is a GIF demo. It shows me running the example commands below, with the qjackctl connections window showing. You can see the lines being drawn as the jack_connect commands are executed. After all the connections have been made, jack_lsp --connections will show the new connections under each named port.

Here are the example commands.

<0.o>jack_lsp --connections

system:playback_1
system:playback_2
PulseAudio JACK Sink:front-left
PulseAudio JACK Sink:front-right
PulseAudio JACK Source:front-left
PulseAudio JACK Source:front-right
gst-launch-1.0:in_jackaudiosrc0_1

<0.o>jack_connect 'PulseAudio JACK Sink:front-right' gst-launch-1.0:in_jackaudiosrc0_1

<0.o>jack_connect 'PulseAudio JACK Sink:front-left' gst-launch-1.0:in_jackaudiosrc0_1

<0.o>jack_connect 'PulseAudio JACK Sink:front-left' system:playback_1

<0.o>jack_connect 'PulseAudio JACK Sink:front-right' system:playback_2

<0.o>jack_lsp --connections

system:playback_1
   PulseAudio JACK Sink:front-left
system:playback_2
   PulseAudio JACK Sink:front-right
PulseAudio JACK Sink:front-left
   gst-launch-1.0:in_jackaudiosrc0_1
   system:playback_1
PulseAudio JACK Sink:front-right
   gst-launch-1.0:in_jackaudiosrc0_1
   system:playback_2
PulseAudio JACK Source:front-left
PulseAudio JACK Source:front-right
gst-launch-1.0:in_jackaudiosrc0_1
   PulseAudio JACK Sink:front-right
   PulseAudio JACK Sink:front-left

You can also remove all connections. Here is a GIF demo. In the demo I try to connect every pair of named ports, and then I try to disconnect every pair of named ports. This will create a warning or error for every invalid pair of ports, so I combine standard output and error, and redirect them to the null device. You can see the lines being drawn/erased for valid connections.

Here are the example commands for removing all connections.

<0.o>jack_lsp | while read a; do jack_lsp | while read b; do jack_connect "$a" "$b"; done; done > /dev/null 2>&1
<0.o>jack_lsp | while read a; do jack_lsp | while read b; do jack_disconnect "$a" "$b"; done; done > /dev/null 2>&1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.