How do I edit a LilyPond file?

With any text editor, as long as you know the rules.

Learn the words

LilyPond does take some learning.  Fortunately it is well-documented.  Read at least the first two links at lilypond.org/manuals.html.  Before you dive into a massive score, try notating a few short tunes.  At any time, I have at least a dozen 32-bar folk tunes I can’t actually play because they’re bad photocopies of bad handwriting ((If you don’t have any scrappy folk tunes that need rewriting, try hanging around at disreputable folk sessions and you’ll soon acquire some.)).

Minor corrections

This section discusses an error in two notes of the score for an entire opera.  It is used here for illustrative purposes, and should not be taken as an indictment of the copyist.  The entire score contains tens of thousands of notes, so the error rate is perhaps 0.01%.

The “King Arthur” score as typeset in 2011 contains an oddity in Act 2, “Come, follow me”, violin 2:

Crotchet - Crotchet - Dotted crotchet - Crotchet - Quaver - Crotchet

Usually we’d compare this against the score, but LilyPond generates the score and parts from the same sources.  This is why we downloaded the 1843 printing from IMSLP/Petrucci.  The corresponding section looks like this:

Crotchet - Crotchet - Crotchet - Dotted crotchet - Quaver - Crotchet

How do we change the LilyPond file to match the original printing.  The “King Arthur” sources are stored in separate folders for each act, with subfolders for each movement.  This is Act 2, Movement 6, so we go to Act2/F/violonII.ily ((You may find that your LilyPond application will only recognize “.ly” files, not “.ily” files. If so, open this one in Notepad (Windows) or TextEdit (Mac OS).)).  Right at the end is this segment:

%% 80
  fs2. fs2 fs8 g
  a4 a b a2 a4
  a4 g fs4. g4 g 8 a4  |
  fs2. fs2.

This is a rhythm problem, so we change the numbers and dots. There is even an example of the “correct” version of this bar on the previous line:

a4 g fs g4. g8 a4  |

Copy it into place:

%% 80
  fs2. fs2 fs8 g
  a4 a b a2 a4
  a4 g fs g4. g8 a4  |
  fs2. fs2.

Now compile the main “Arthur-Violin_II.ly” and see how it looks:

Crotchet - Crotchet - Crotchet - Dotted crotchet - Quaver - Crotchet

Success!

Substitute parts

It’s all too common to find an excess of violins and a shortage of violas ((If you have this problem, try telling less viola jokes.)).  Can we turn the viola part into a third violin part, with less work than writing it out by hand?  We can indeed.

Duplication time

The obvious first step is to duplicate “Arthur-Viola.ly” and rename it to “Arthur-Violin_III.ly”.  However, that file doesn’t actually contain much. It’s easy enough to change this:

    instrument = \LViola

To this:

    instrument = \markup { \LViolin \char ##x2162 }

But that just changes the title page ((The weird “\char ##x2162” bit creates a roman numeral III as a single character, for consistency with the first and second violin parts.)). The rest of the file just retrieves the files for each act, using lines like this:

  \include "Act0/A_Viola.ily"
[...]
  \include "Act1/Viola.ily"
[...]
  \include "Act2/Viola.ily"
[...]
[...]
  \include "Act0/Z_Viola.ily"

We need to change the files included, and their contents. Wherever a “Viola.ily” file is included, we need to change that to “Violin_III.ily”, and create a file of that name to be included. For instance, “Act1/Viola.ily” contains lines like this:

  \new Staff = "Viola" <<
     \clef alto \MAC
     \include "A/global.ily" \include "A/indication.ily"
     \include "A/instrumental.ily" \include "A/viola.ily"
  >>

So we copy the file to “Act1/Violin_III.ily” and change the content staff names, clefs and includes:

  \new Staff = "Violon 3" <<
    \clef treble \MAC
    \include "A/global.ily" \include "A/indication.ily"
    \include "A/instrumental.ily" \include "A/violonIII.ily"
  >>

Once again, “Act1/A/viola.ily” must be duplicated and renamed to “Act1/A/violinIII.ily”, and so on for every movement ((I used Mac OS Automator to duplicate the files, and TextWrangler to search and replace content. However, it’s not that hard to do this work manually.)).

Staying in range

Now we have a part titled “Violin III”, and in treble clef, but any notes that used the viola C string will be out of range.  You could just pencil these in when you find them, but you can also fix them in the LilyPond source.

Here is an early example in Act 1:

That F is playable on a viola, but not a violin.

The hardest part with fixing notes like this is often finding the correct file. In this case it’s Act1/A/violinIII.ily:

%% 5
  r4 bf bf r  |
  r4 a a r  |
  r4 g g r  |
  r4 a g2  |
  f4\p f' f r  |

We could just take it up an octave, but that would duplicate the first violin part.  This looks like an F major chord, so make the viola play a C.  This section uses relative octave entry, so remember to change the note after the change as well.

%% 5
  r4 bf bf r  |
  r4 a a r  |
  r4 g g r  |
  r4 a g2  |
  c4\p f f r  |

That was simple enough, but we have to repeat the process perhaps a hundred times, wherever the viola part goes below violin range.

The singer will no longer have an F to match, but violins simply can’t play that pitch. If it really matters, the cello part could be re-written to play the F instead.

More LilyPond

  1. What is a LilyPond file?
  2. How do I read this LilyPond file?
  3. How do I edit a LilyPond file?
  4. How do I transpose a LilyPond part?
  5. Can I import a LilyPond file into my graphical notation editor?

Leave a Reply

Your e-mail address will not be published or shared with third parties.

First comments from new name/e-mail combinations will be held in moderation.