Use command line to start jack and set connections

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Post Reply
bobby.calamari
Established Member
Posts: 33
Joined: Fri Apr 21, 2017 10:52 am
Has thanked: 3 times
Been thanked: 2 times

Use command line to start jack and set connections

Post by bobby.calamari »

Hi everyone

I hope this is the right place for this question. I would like to write a bash script which can start jack (or qjackctl; I'm not fussy) and set a bunch of connections. I know the commands to start jack or qjackctl and I know the commands to create JACK audio and ALSA MIDI connections.

The problem is the command to start jack does not finish (it runs as long as jack is running), so the following commands in my script don't execute. I can understand what's going on but I haven't a clue what to do about it. Is there a way in bash I can get a script to proceed past an unfinished command?

User avatar
LAM
Established Member
Posts: 992
Joined: Thu Oct 08, 2020 3:16 pm
Has thanked: 141 times
Been thanked: 349 times

Re: Use command line to start jack and set connections

Post by LAM »

Try to use an " &" at the end of your command. It will fork your process and continue execution.

in mix, nobody can hear your screen

bobby.calamari
Established Member
Posts: 33
Joined: Fri Apr 21, 2017 10:52 am
Has thanked: 3 times
Been thanked: 2 times

Re: Use command line to start jack and set connections

Post by bobby.calamari »

Okay, thank you so much for your quick reply.

I think what you suggested has worked, but it just leads to a different problem: the JACK server has not finished initialising before the jack_connect commands run, so they fail.

I need to either find a kind of callback from the JACK initialisation to hook into, or look at using a post-startup script in qjackctl to set my connections (which I've failed miserably to do so far).

Thanks a lot!

User avatar
LAM
Established Member
Posts: 992
Joined: Thu Oct 08, 2020 3:16 pm
Has thanked: 141 times
Been thanked: 349 times

Re: Use command line to start jack and set connections

Post by LAM »

bobby.calamari wrote: Tue Dec 13, 2022 10:57 pm

Okay, thank you so much for your quick reply.

I think what you suggested has worked, but it just leads to a different problem: the JACK server has not finished initialising before the jack_connect commands run, so they fail.

I need to either find a kind of callback from the JACK initialisation to hook into, or look at using a post-startup script in qjackctl to set my connections (which I've failed miserably to do so far).

Thanks a lot!

jack_wait is your friend then:

Code: Select all

$ jack_wait --help

Usage: jack_wait [options]
Check for jack existence, or wait, until it either quits, or gets started
options:
        -s, --server <name>   Connect to the jack server named <name>
        -n, --name <name>     Set client name to <name>
        -w, --wait            Wait for server to become available
        -q, --quit            Wait until server is quit
        -c, --check           Check whether server is running
        -t, --timeout         Wait timeout in seconds
        -h, --help            Display this help message
For more information see http://jackaudio.org/

in mix, nobody can hear your screen

User avatar
LAM
Established Member
Posts: 992
Joined: Thu Oct 08, 2020 3:16 pm
Has thanked: 141 times
Been thanked: 349 times

Re: Use command line to start jack and set connections

Post by LAM »

Using the Qjackctl's

Setup > Options > Execute script after Startup

option should work too.

in mix, nobody can hear your screen

bobby.calamari
Established Member
Posts: 33
Joined: Fri Apr 21, 2017 10:52 am
Has thanked: 3 times
Been thanked: 2 times

Re: Use command line to start jack and set connections

Post by bobby.calamari »

:D I'm not sure how you could be more helpful!

I've managed to get the post-startup script working from qjackctl now (I was blocked by the fact qjackctl gives you a GUI to choose a path to the script, then won't run it if it contains a space...)

I will bookmark this for all your helpful tips. Thanks!

User avatar
sunrat
Established Member
Posts: 926
Joined: Wed Jul 22, 2020 2:08 pm
Has thanked: 152 times
Been thanked: 247 times

Re: Use command line to start jack and set connections

Post by sunrat »

Generally when running more than one command together, placing two ampersands between them means to wait until one command is completed before starting the next.

Code: Select all

command1 && command2
User avatar
Linuxmusician01
Established Member
Posts: 1548
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland (Europe)
Has thanked: 784 times
Been thanked: 144 times

Re: Use command line to start jack and set connections

Post by Linuxmusician01 »

@bobby.calamari: Do you want to post your script here? I like to start things w/ a shell script too. I'm curious how you've set Jack connections via the command line. :)

User avatar
khz
Established Member
Posts: 1648
Joined: Thu Apr 17, 2008 6:29 am
Location: German
Has thanked: 42 times
Been thanked: 92 times

Re: Use command line to start jack and set connections

Post by khz »

LAM wrote: Tue Dec 13, 2022 10:59 pm
bobby.calamari wrote: Tue Dec 13, 2022 10:57 pm

Okay, thank you so much for your quick reply.

I think what you suggested has worked, but it just leads to a different problem: the JACK server has not finished initialising before the jack_connect commands run, so they fail.

I need to either find a kind of callback from the JACK initialisation to hook into, or look at using a post-startup script in qjackctl to set my connections (which I've failed miserably to do so far).

Thanks a lot!

jack_wait is your friend then:

Code: Select all

$ jack_wait --help

Usage: jack_wait [options]
Check for jack existence, or wait, until it either quits, or gets started
options:
        -s, --server <name>   Connect to the jack server named <name>
        -n, --name <name>     Set client name to <name>
        -w, --wait            Wait for server to become available
        -q, --quit            Wait until server is quit
        -c, --check           Check whether server is running
        -t, --timeout         Wait timeout in seconds
        -h, --help            Display this help message
For more information see http://jackaudio.org/

Or: sleep - sleep for the specified number of seconds https://linux.die.net/man/3/sleep.

. . . FZ - Does humor belongs in Music?
. . GNU/LINUX@AUDIO ~ /Wiki $ Howto.Info && GNU/Linux Debian installing >> Linux Audio Workstation LAW
  • I don't care about the freedom of speech because I have nothing to say.
bobby.calamari
Established Member
Posts: 33
Joined: Fri Apr 21, 2017 10:52 am
Has thanked: 3 times
Been thanked: 2 times

Re: Use command line to start jack and set connections

Post by bobby.calamari »

Linuxmusician01 wrote: Wed Dec 14, 2022 9:52 am

@bobby.calamari: Do you want to post your script here? I like to start things w/ a shell script too. I'm curious how you've set Jack connections via the command line. :)

Oh, sure. I have a Focusrite Scarlett 18i8 soundcard, so lots of inputs:

Code: Select all

#!/bin/bash
echo "Setting up connections for general use..."
jack_connect system:capture_1 system:playback_1
jack_connect system:capture_2 system:playback_2
jack_connect system:capture_3 system:playback_
jack_connect system:capture_3 system:playback_
jack_connect system:capture_4 system:playback_
jack_connect system:capture_4 system:playback_2
jack_connect system:capture_5 system:playback_1
jack_connect system:capture_6 system:playback_2
jack_connect system:capture_7 system:playback_1
jack_connect system:capture_8 system:playback_2
jack_connect system:capture_13 system:playback_1
jack_connect system:capture_13 system:playback_2
jack_connect system:capture_14 system:playback_1
jack_connect system:capture_14 system:playback_2
jack_connect system:capture_15 system:playback_1
jack_connect system:capture_15 system:playback_2
jack_connect system:capture_16 system:playback_1
jack_connect system:capture_16 system:playback_2
jack_connect system:capture_17 system:playback_1
jack_connect system:capture_17 system:playback_2
jack_connect system:capture_18 system:playback_1
jack_connect system:capture_18 system:playback_2
jack_connect system:capture_19 system:playback_1
jack_connect system:capture_20 system:playback_2
aconnect 28:0 20:0
aconnect 32:0 20:0
echo "Connections set up successfully!"

I wasn't sure whether hardcoding numbers for the MIDI ports was a good idea, but it seems to work fine across number computer restarts. And hey, it's a file. It's easy to update.

User avatar
Linuxmusician01
Established Member
Posts: 1548
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland (Europe)
Has thanked: 784 times
Been thanked: 144 times

Re: Use command line to start jack and set connections

Post by Linuxmusician01 »

@bobby.calamari: thanks for posting the script.

Post Reply