Skip to content

Instantly share code, notes, and snippets.

@madskjeldgaard
Created May 3, 2020 13:56
Show Gist options
  • Save madskjeldgaard/1a1e58a36f2d7526cd28524f5fd75946 to your computer and use it in GitHub Desktop.
Save madskjeldgaard/1a1e58a36f2d7526cd28524f5fd75946 to your computer and use it in GitHub Desktop.
A startup script that sets up a zita-njbridge source and transmits a sine wave using SuperCollider and Tmux
#!/bin/bash
#
# This script makes it easy to setup a source in a networked audio connection
# It uses the 'zita-j2n' (jack to network) command to send audio to the network
# (to be received using 'zita-n2j' on the other end)
#
# Usage
# njstart <target_ip> <target_port> <scfile (optional)>
# Dependencies: jack, zita-njbridge, SuperCollider, tmux
#
session="network-audio"
if [ -z $1 ]; then
echo "No arguments supplied. Exiting..."
echo "
Usage
njstart <target_ip> <target_port> <scfile (optional)>
"
else
target_ip=$1
target_port=$2
if [ -z $3 ]; then
scfile="$HOME/test.scd"
else
scfile="$3"
fi
# set up tmux
tmux start-server
tmux new-session -d -s $session
# Start jack
tmux new-window -t $session:1 -n jack
tmux send-keys -t $session:1 "/usr/bin/jackd -dalsa -dhw:1 -r48000 -p512 -n2" Enter
# Zita
tmux new-window -t $session:2 -n zita
tmux send-keys -t $session:2 "sleep 5; zita-j2n "$target_ip" "$target_port"" Enter
# Connect output of SuperCollider to the input of the zita-network connection
tmux new-window -t $session:3 -n connections
tmux send-keys -t $session:3 "sleep 6; jack_connect SuperCollider:out_1 zita-j2n:in_1 && jack_connect SuperCollider:out_2 zita-j2n:in_2 && echo 'connected supercollider to zita-j2n successfully'" Enter
# Run SuperCollider file using sclang
# Create a test file if there isn't one on the system
if [ ! -f "$scfile" ]; then
scfile="$HOME/test.scd"
echo "SuperCollider file $scfile does not exist.
Creating a simple sine wave file in $scfile instead"
# Make sc file
echo "
// Boot server and play stereo sine wave
s.waitForBoot{
play{
SinOsc.ar([440, 441], mul: 0.5).poll(1)
}
}" > "$HOME/test.scd"
fi
tmux new-window -t $session:4 -n supercollider
tmux send-keys -t $session:4 "sclang $scfile" Enter
# Open the tmux session
tmux attach-session -d -t $session
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment