Well, I didn't get enough info from this posting to do what I originally wanted to do (i.e. hack Lilypond itself to add this option--it would have been enough if I knew anything about programming, I guess), but I've come up with a way to specify showLastLength at the command line using the script that I normally use to invoke lilypond. This works equally well on Mac and Linux. I guess it would take something completely different to work on Windows, though. Don't really know about that.

So I've added some code that allows use of an argument that is captured and passed to a temporary file so it can be used by a lilypond source file. To make use of this function, add the following line near the top of your source file:

\include "showlast.ly"

You don't actually have to *have* the showlast.ly file anywhere on your system, as it's created on the fly by the script, so that it's present when lilypond is called, and then when the script is done, the showlast.ly file is deleted. Specify the duration of the last length the same way you would if you were putting it in your source file. R1*8 is eight whole-rest bars. R2.*8 would be 8 bars of dotted-half-rests. Here's an example of how to run it:

lily -l=R1*12 filename.ly

The R1*12 value is passed to the temporary file, and when lilypond is called, it only renders the last 12 bars.

If you just do "lily filename.ly", then the script creates an empty showlast.ly file so that no "showLastLength" variable is set and the source file is run normally.

Now, I've specified acrobat reader for previewing the file in Linux so if you prefer another viewer you can say "xdg-open" or "evince" in its place. On Mac I use the default Preview app.

Give it a try!

Jon

Jonathan Kulp wrote:
Thanks for replying, Han-Wen. I can't find showLastLength anywhere in that file, though. Searches for showlast and show-last came up empty. It looks like the file is inside the SCM directory but I can't tell where. Here's the search I did:

[EMAIL PROTECTED]:/usr/local/share/lilypond/2.11.59/scm$ cat *.scm | grep -i showlast
     LENGTHOF(\\showLastLength)
      ((show-last  (ly:parser-lookup parser 'showLastLength)))

So it shows that showLastLength is there, but it doesn't say which file it's in (my skills at the shell are such that I don't know how to make it tell me this. Sigh...). Can you tell from this output where it is?

Jon

Han-Wen Nienhuys wrote:
Can anyone point me in the right direction to accomplish this great idea?!
;)


Would it be possible technically to specify the showLastLength value
when
invoking lilypond instead of putting it in the .ly file? Something like


look at lily.scm to see where the -d options are defined.  At some
point showLastLength is initialized; that's where you should do

  (ly:get-option 'show-last-length)




--
Jonathan Kulp
http://www.jonathankulp.com
#!/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
_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to