--- /dev/null
+#!/bin/sh
+
+LOGFILE=${HOME}/Music/utils/jackd.log
+
+echo "Begin JACK startup script" > ${LOGFILE}
+
+PAPID=$(pidof pulseaudio)
+
+if [ -n "${PAPID}" ]; then
+ echo "pulseaudio running with pid ${PAPID}" >> ${LOGFILE}
+fi
+
+# arg 1: process name
+kill_process()
+{
+ local PID=$(pidof ${1})
+
+ if [ -n "${PID}" ]; then
+ echo "Stopping ${1}" >> ${LOGFILE}
+ kill ${PID}
+ sleep 1s
+ fi
+}
+
+# Kill all servers
+kill_process pulseaudio 1>> ${LOGFILE} 2>&1
+kill_process jackd 1>> ${LOGFILE} 2>&1
+kill_process timidity 1>> ${LOGFILE} 2>&1
+
+# The -preempt and -rt kernels are no longer being developed due to lack of
+# support. Focus has instead turned to the -lowlatency and -realtime kernels,
+# particularly for the the release of Ubuntu 11.04 Natty Narwhal. The long-term
+# goal is to have -lowlatency in the official Ubuntu repositories, while
+# maintaining -realtime in a dedicated PPA.
+#
+# jackd options:
+# -s, --softmode
+# Ignore xruns reported by the ALSA driver.
+# This makes JACK less likely to disconnect unresponsive ports when
+# running without --realtime
+# -H, --hwmon
+# Enable hardware monitoring of capture ports.
+# -z, --dither [rectangular,triangular,shaped,none]
+# Set dithering mode.
+jackd --no-realtime -dalsa -p512 -dhw:0 -r44100 --hwmon --dither s 32e213 1>> ${LOGFILE} 2>&1 &
+sleep 2s
+
+timidity -iA -Oj -B2,8 -EFreverb=0 1>> ${LOGFILE} 2>&1 &
+
+pulseaudio -DnF ${HOME}/.pulse/pulsejack.pa
+
+exit $?
--- /dev/null
+#!/bin/sh
+
+LPK25=$(aplaymidi -l | grep LPK25 | awk '{ print $1 }')
+TIMIDITY=$(aplaymidi -l | grep TiMidity | awk '{ print $1 }')
+
+# It would be best to detect existing connection using "aconnect -i -l"...
+
+if [ -n "${LPK25}" ]; then
+ for t in ${TIMIDITY}; do
+ echo "Trying port $t"
+ aconnect ${LPK25} ${t}
+ if [ $? -ne 0 ]; then
+ # Check if port is already connected. If it is, exit with success.
+ if aconnect ${LPK25} ${t} 2>&1 | grep "Connection is already subscribed" 1> /dev/null; then
+ echo "Already connected"
+ exit 0
+ fi
+ else
+ # Success
+ exit 0
+ fi
+ done
+fi