#!/bin/sh
#
# mkcfg.sh.txt v0.0.2 20040320 freepats@opensrc.org
# Create a Timidity compatible config file for FreePats
#
# Usage: sh mkcfg.sh.txt
# Source: http://freepats.opensrc.org/mkcfg.sh.txt
# License: http://www.gnu.org/licenses/gpl.txt

DIR="$(pwd)/freepats"
cat << EOM > $DIR/freepats.cfg
# Automatically generated on $(date)
# by http://freepats.opensrc.org/mkcfg.sh.txt

EOM
cd $DIR
for i in $(/bin/ls *_??? -d); do
    BANKNUM=$(echo $i|awk -F_ '{printf "%d",$2}')
    if [ $(echo $i|grep Tone) ];then
        echo "bank $BANKNUM" >> $DIR/freepats.cfg
    else
        echo "drumset $BANKNUM" >> $DIR/freepats.cfg
    fi
    echo >> $DIR/freepats.cfg
    cd $DIR/$i
    for j in $(/bin/ls *.pat); do
        TXT=$(echo $j|sed s/\.pat/.txt/)
        EXTRA=
        [ -s $TXT ] && EXTRA="$(head -1 $TXT)"
        echo $j|awk -F_ \
         '{printf " %d\t%s/%s %s\n",$1,"'$i'",$0,"'"$EXTRA"'"}' \
         >> $DIR/freepats.cfg
    done
    echo >> $DIR/freepats.cfg
done
