Skip to content

Instantly share code, notes, and snippets.

@OnkelTem
Last active May 31, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OnkelTem/a9630a9a75774a7bdb5a5481fe7a3d81 to your computer and use it in GitHub Desktop.
Save OnkelTem/a9630a9a75774a7bdb5a5481fe7a3d81 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Colors
C1='\033[1;32m' # Green
C2='\033[1;33m' # Yellow
C3='\033[1;31m' # Red
C4='\033[1;37m' # White
C0='\033[0m' # No color
delay () { sleep "${1:-1}"; }
#
# Start JACK server
#
# JACK will be serving our soundcard and all its wirings.
# This soundcard however should be taken out of the PulseAudio control.
# Add corresponding ignore rules into /etc/udev/rules.d/* to achieve this.
# @see: https://jamielinux.com/blog/tell-pulseaudio-to-ignore-a-usb-device-using-udev/
echo -e $C1"Starting JACK"$C0
delay
# First lets find and kill of the instances jackd and jackdbus
killall -9 jackd
killall -9 jackdbus
delay
# Now it's time to start our own new and shiny Jack2
# I use an external mixer device (Yamaha AG03) connected via USB
jackd -ndefault -dalsa -dhw:AG06AG03 -r44100 -p256 -n3 &
JACK_PID=$!
delay 5
#
# Load PulseAudio modules
#
# First let's disable PulseAudio JACK autodetection module which creates sinks/sources
# automatically. Instead we're gonna create them manually in a moment.
pactl unload-module module-jackdbus-detect
# Now let's create our sinks/sources. They're gonna function as bridges
# between PulseAudio and JACK worlds. So I call them just cables.
# The outputs will be saved into variables to unload modules later on.
echo -e $C1"Creating virtual cables"$C0
delay
# Sinks are the PulseAudio outputs (Speakers) i.e. where you can stream audio from your
# music player or a web-browser for example
pactl load-module module-jack-sink client_name=Cable1 channels=2
# Sources are the PuleAudio inputs (Mics) i.e. from where you can record audio with
# PulseAudio compatible programs as OBS, Audacity and etc.
pactl load-module module-jack-source client_name=Cable2 channels=2
pactl load-module module-jack-source client_name=Cable3 channels=2
#
# Wiring
#
echo -e $C1"Wiring up"$C0
delay
# We're gonna wire things up now using Qjackctl PatchBay feature.
# For this to happen you first need to create PatchBay configuration.
# Let's use a constant with the path to your PatchBay configuration.
PATCHBAY=patchbay.xml
[[ "$1" == "config" ]] && {
qjackctl
delay
echo -e $C3"Shutting down jackd"$C0
delay
kill ${JACK_PID}
delay
echo -e $C2
echo -e "If you have finished editing the patchbay configuration file $C4${PATCHBAY}$C2"
echo -e "restart this script w/o ${C4}config$C2 option and you're done."
echo -e $C0
exit 1
}
[[ -f ${PATCHBAY} ]] || {
echo -e $C2
echo -e "The patchbay configuration file $C4${PATCHBAY}$C2 not found."
echo -e "Please re-run this script with ${C4}config$C2 argument to run qjackctl."
echo -e "There should you create a PatchBay configuration and export to this"
echo -e "directory with the name: $C4${PATCHBAY}$C2"
echo
echo -e "Please don't run ${C4}qjackctl$C2 manually, instead - let this script do this"
echo -e "for you, because to this point jackd should be running and cables are created."
echo -e $C0
delay
echo -e $C3"Shutting down jackd"$C0
delay
kill ${JACK_PID}
delay
exit 1
}
#echo qjackctl -a ${PATCHBAY}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment