makeHornInF.sh
author Jim Hague <jim.hague@laicatc.com>
Wed, 20 Feb 2013 13:03:40 +0000
changeset 216 64b84dea3337
child 217 a8a46fd79d5c
permissions -rwxr-xr-x
Add Horn in F transposition.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
216
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     1
#!/bin/bash
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     2
#
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     3
# Transpose a book for Horn in F.
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     4
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     5
if [ $# != 1 ]; then
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     6
    echo "Usage: makeFHorn.sh <book dir name>"
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     7
    exit 1
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     8
fi
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
     9
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    10
dir=`pwd`
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    11
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    12
booke=$dir/$1
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    13
outdir=$dir/$1-HornInF
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    14
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    15
mkdir -p $outdir
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    16
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    17
find $booke -name "*.abc" | sort |
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    18
    while read filename
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    19
    do
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    20
        name=`basename $filename .abc`
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    21
        tmpfile=$outdir/$name.abc.tmp
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    22
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    23
        # Strip out guitar chords first. This has the advantage of removing
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    24
        # text with arbitary lower case characters too.
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    25
        sed -e "s/\"[^\"]*\"//g" $filename > $tmpfile
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    26
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    27
        # Transpose concert pitch up a fifth.
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    28
        # If there are any notes at or above C above middle C, transpose
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    29
        # down a seventh instead.
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    30
        transpose=5
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    31
        if grep -v "^[A-Z]:" $tmpfile | sed -e 's/"[^"]*"//g' | grep -q "[a-g]"; then
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    32
            transpose=-7
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    33
        fi
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    34
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    35
        # Transpose. By default abc2abc will report errors in the output,
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    36
        # but this messes up output formatting so stop it.
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    37
        abc2abc $tmpfile -e -t $transpose > $outdir/$name.abc
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    38
        rm $tmpfile
64b84dea3337 Add Horn in F transposition.
Jim Hague <jim.hague@laicatc.com>
parents:
diff changeset
    39
    done