#!/bin/sh
#
# starts vkeybd assuming timidity is running as a service
#
# Author: JM. Philippe <philipjm@free.fr>
#
# This file is part of dock-session.
#
# vkeybd-timidity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# vkeybd-timidity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with vkeybd-timidity. If not, see <http://www.gnu.org/licenses/>.

# guess timidity port
# there are usually 4 ports, but both last ones
# usually do not work out of the box
k=0
for TIMIDITYID in $(aplaymidi -l | grep TiMidity | cut -d ' ' -f 1); do
	echo $TIMIDITYID
	k=$(($k+1))		# stop at nbr. 2
	if [ $k -eq 2 ]; then break; fi
done

# check timidity is on
if [ -z "$TIMIDITYID" ]; then
	MSG=$(gettext -d vkeybd-timidity -s "Unable to find a running timidity instance, exiting…")
	zenity --warning --text "$MSG"
	exit
fi

# start vkeybd connected to timidity
echo '> running: vkeybd --addr' $TIMIDITYID
vkeybd --addr $TIMIDITYID
