#!/bin/bash
#
# \file        YoSeqJack
# \library     Home/Audio
# \author      Chris Ahlstrom
# \date        2016-03-21
# \update      2016-03-21
# \version     $Revision$
# \license     $XPC_SUITE_GPL_LICENSE$
#
#     This script provides a way to set up yoshimi and seq24/sequencer64
#     to run on JACK MIDI (and audio).
 
YoseqStatus="on"
DoHelp="no"

# This line is meant for starting from the Sequencer64 project root.
# The commented lines support the installed versions:
#
# Sequencer=/usr/bin/$Seq
# Sequencer=/usr/local/bin/$Seq

Seq="sequencer64"
Sequencer="./Sequencer64/$Seq"

# The installed version of Yoshimi.

Yoshi="/usr/local/bin/yoshimi"

# Process the simple script options:

if [ $# -ge 1 ] ; then

   while [ "$1" != "" ] ; do

      case "$1" in

         start | on)
            YoseqStatus="on"
            ;;

         stop | off)
            YoseqStatus="off"
            ;;

         help)
            DoHelp="yes"
            ;;

      esac
      shift
   done
fi

if [ "$DoHelp" == "yes" ] ; then

cat << E_O_F

Usage: YoSeqJack [options]

Starts or stops sequencer64 and yoshimi for usage with JACK, via QJackCtl and
a2jmidid.  Also adds klick, a command-line JACK metronome, to the mix.

Options:

   stop, off   Stop sequencer64 and yoshimi instances.
   start, on   Start sequencer64 and yoshimi.  This is the default action.
   help        Show this text.

Sequencer64 is started as JACK Master.  Yoshimi is started with JACK audio and
JACK MIDI.  QJackCtrl is started, but you still have to make the connections
between Yoshimi and JACK audio, and between a2jmidid's sequencer64 Through port
to the Yoshimi input.

E_O_F

elif [ "$YoseqStatus" == "off" ] ; then

   killall $Seq > /dev/null
   killall yoshimi > /dev/null
   killall a2jmidid > /dev/null
#  killall klick > /dev/null
   killall qjackctl > /dev/null
   echo "$Seq, Yoshimi, a2jmidid, and qjackctl stopped."

else

   echo "Starting $Seq, Yoshimi, a2jmidid, klick, and qjackctl.  Make connections"
   echo "in qjackctl, for audio and MIDI, once Yoshimi has started."
   qjackctl &
   sleep 1
   a2jmidid --export-hw &
   sleep 1
#  klick -j -P &
#  sleep 1
   $Sequencer -J &
   sleep 1
   $Yoshi -j -J

fi

# vim: ft=sh
