Sunday, February 28, 2010

LilyPond: abusing \glissando to indicate scale runs on parallel strings


Fingering indications are ubiquitous in most written music, and this is especially true for Guitar music. There are seldom fewer than two or three solutions for a given passage of music and with all the editorial markings in common usage, Guitar music can quickly become cluttered. The job of the engraver is to creatively use a minimum of editorial markings to convey the maximum amount of information. For example, in the case of a scale run in thirds or sixths, it's more useful to indicate the strings the notes are played on rather than print each individual fingering for each individual note. Marking the strings intended for the scale run rather than the fingers used eliminates clutter on the page and concisely shows the composer's or arranger's intent. In this post, I'll demonstrate how to notate scale runs on parallel strings in Guitar music by using the \glissando command in invisible voices, along with \tweak and some other LilyPond magic.


First, open your favorite text editor and create your new LilyPond input file. Save it to a convenient location with the name “string_run.ly” For this demonstration, I use GNU Emacs, which has good LilyPond syntax highlighting. Syntax highlighting is useful for quickly spotting mistakes in the code. (Ctrl+click on images to display them in a separate window at full size.)
Go ahead and set up your input file by first typing a version statement, and setting up the basic structure of the file. In the examples, pay close attention to the comments (text following a %), as they tell you how each of the elements in the input file affects the output. Take a look at Example 1, and see the what the structure of the input file is like. Example 2 shows in more detail what each of the commands and and context indicators does in LilyPond.

Example 1


Example 2


Now, let's set up our staff for Guitar by putting in the clef, key signature and time signature commands in the Staff context. I'm writing the example in A Minor with a meter of 4/4. Next, it's time to add our scale run. Type in a run in thirds or sixths. I've chosen a short run in sixths. Let's compile the example and take a look (from here on out, Ctrl.+click on the images of music to view the source code in a separate tab or window).

That's beautiful isn't it? Now, let's get to work on the string indicators. For that, we're going to add a voice above and a voice below. Eventually, these voices will be invisible, leaving only a string number indication, and a long glissando line for each voice. To position the glissando line and set its angle, we'll set the notes strategically. The glissando line should be parallel to the overall trajectory of the line of music. You'll arrive at your own solutions through experimentation. Take a look.

Let's move the string number so that it appears right on the notehead, using the \tweak command. Put the command between the note and string number. This \tweak will affect the extra-offset of the string number, which is expressed as a pair of values—one each for the horizontal and vertical placement relative to the mark's normal default position. View the source code to see how this is done.

So far, so good. Now let's add the lower string indicator in the same manner. Since the string number's default placement is above the note, even when the note is below the staff, we'll need to specify a different default placement for it in LilyPond. I've told LilyPond to put the string number below the note for this voice, so that it will appear below the staff. This is done with \set stringNumberOrientations before the string number is called.

Great. Now let's clean it up. You'll notice that LilyPond shifts voices left or right to avoid collisions in multi-voice textures. This is usually the desired behavior. However, here we want the voices to all align vertically, so we'll add an \override to the first voice to tell LilyPond to ignore the note collisions. Also, in the “glissando” voices, add the \hideNotes command before the notes. And there you have it.

1 comment: