#!/bin/bash

# What this script does:
# * launches a2jmidid to export all available alsa sequencer ports
# * launches jalv with the amsynth LV2 plugin
# * waits for the jalv JACK ports to become available
# * launches multimidicast to start receiving MIDI messages over multicast UDP.
#   On the other end you can then control amsynth with an app like TouchDAW.
#   TouchDAW needs to be set up to send via multicast UDP.
# * waits for multicast JACK ports (exported via a2jmidid) to become available
# * makes the necessary connections

a2jmidid -eu &
jalv http://code.google.com/p/amsynth/amsynth &

until jack_lsp | grep amsynth &> /dev/null
do
  sleep 1
done

multimidicast -q &

until jack_lsp | grep multimidicast &> /dev/null
do
  sleep 1
done

jack_connect amsynth:out_l system:playback_1
jack_connect amsynth:out_r system:playback_2
jack_connect "a2j:multimidicast (capture): Port 03" amsynth:midi

exit