#!/bin/bash #************************************************************# # This script runs lilypond on a specified file, keeping all # # output files in the same directory as the source file # #************************************************************# # Usage: This script allows for the use of the "showLastLength" # function of Lilypond, where it only runs the last x number of # measures instead of the whole thing. To take advantage of this, # YOU MUST PUT THE FOLLOWING LINE NEAR THE TOP OF YOUR SOURCE FILE: # # \include "showlast.ly" # # Then use the -l flag with an argument in the following format: # # lily -l=R1*12 filename.ly (12 whole-rest bars) # lily -l=R2.*12 filename.ly (12 dotted-half-rest bars) # # Without the -l option, the file should run as usual. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # getopt_simple - Orig by Chris Morgan, stolen from # the ABS Guide and modified a bit #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ getopt_simple() { until [ -z "$1" ] ; do if [ ${1:0:1} = '-' ] ; then tmp=${1:1} # Strip off leading '-' . . . if [ ${tmp:0:1} = '-' ] ; then tmp=${tmp:1} # Allow double - fi parameter=${tmp%%=*} # Extract name. value=${tmp##*=} # Extract value. eval $parameter=$value else filename="$1" fi shift done } length='no' l='no' quiet='no' q='no' getopt_simple "$@" if [ $q != 'no' ] ; then quiet=$q fi if [ $quiet != 'no' ] ; then quiet='Y' exec >& /dev/null fi # determine whether the flag is there. If not then dump # a % into the showlast.ly file. If so, then dump the # showLastLength variable into it. if [ "$l" == "no" ] ; then echo "%" > ~/showlast.ly elif [ "$value" != "no" ] ; then LENGTH=$value echo "showLastLength=$LENGTH" > ~/showlast.ly fi #*********************************# # Get all the filename info here # #*********************************# # determines the source filename srcfile=$(basename "$filename") # removes the extension from source filename STEM=$(basename "$filename" .ly) # determines directory OUTDIR=$(dirname "$filename") # determines whether running Mac or Linux OS=$(uname) # If viewer is open, close it if [ "$OS" == "Darwin" ] then killall Preview else wmctrl -c "Adobe Reader" fi # set Lilypond PATH if OS is Darwin if [ "$OS" == "Darwin" ] ; then export PATH="$PATH:/Applications/LilyPond.app/Contents/Resources/bin/" fi # changes to correct directory cd "$OUTDIR" # run lilypond on source file # add the option to include $HOME b/c that's where the temporary # showlast.ly is stored. lilypond --include=$HOME "$srcfile" # opens pdf and returns to command prompt if [ "$OS" == "Darwin" ] then open "$STEM".pdf else acroread "$STEM".pdf & fi # removes .ps file rm "$STEM".ps # removes showlast.ly file rm ~/showlast.ly