Engraving Scores In Lilypond

The personal computer has given every composer and arranger the facility to produce handsome musical scores. Most composers and arrangers at the moment use one of the well known graphical applications, Finale or Sibelius. In these programs you are presented with a display of a blank musical score, and the musical symbols you add to your score appear directly on the score, as if on a printed page.

It is certainly possible to do good work with these applications, but they have some disadvantages. One is that they are expensive to purchase. Another is that, from what I have read, their default output sometimes requires tweaking from the user to look really good. Not all users have the skill to do this tweaking well and may in fact make matters worse.

Lilypond, an open source music engraving program, takes a different approach. Lilypond is a compiler that takes a source file written in plain text and turns it into a musical score in pdf or svg graphic. In this Lilypond is much like a C compiler that turns a text file of C code into a computer program, or the Tex compiler that turns a marked up text file into a nicely typeset document.

Advantages Of Lilypond

Lilypond offers some important advantages. The most important advantage that Lilypond offers is that its default output is generally good enough that it requires no tweaking from the user.

Another important advantage of Lilypond is that, being open source, it is completely free for anyone to download and use. It is not a crippled version of anything, nor does it carry hidden malware or advertising. It is simply free software, to be taken and used. Lilypond is available for all major platforms: Windows, Apple Macintosh, Linux, and BSD.

Lilypond, like many other open source programs, uses modest resources and runs well on older computers. I use several old Mac ppc copmputers and Lilypond is the only music typesetter that will run on them. It runs well.

How Lilypond Works

In Lilypond note values are entered into a text file with a plain text editor. Notes are written as a b c, d and so on, and sharps and flats as s and f. Note durations are written as numbers. A simple melody might look like this: {e4 d c d e e e2}. (Mary had a little lamb). In e flat this melody would look like: {g4 f ef f g g g2}. Note: a duration in Lilypond, once written, applies to all subsequent notes until changed.

You can write a Lilypond score using any basic editor, but you should not use a word processor which will insert unseen markup that will spoil the Lilypond file. The actual structure of the Lilypond code can be a little confusing to wrap your head around at first, but it rewards study. I will not attempt to describe Lilypond syntax in any detail here; you are better to turn to some of the excellent tutorials that are available on the internet, and especially the the Sounds From Sound video tutorials that are currently posted (2016) on Youtube.

The Lilypond project provides extensive and indeed exhaustive documentation, including a library of Lilypond code snippets that will show you how to handle many common tasks, and some templates.

Frescobaldi: A Lilypond IDE

As the Sounds From Sound tutorials will explain you can also use Frescobaldi, a fine integrated development environment that provides you with an interface to Lilypond. Frescobaldi provides you with a typical two pane display, with your code written in the left pane, and the result produced by the Lilypond engraving engine

Frescobaldi provides you with wizards for setting up your score, with all the instruments you want, titles, key and time signatures. It provides you with snippets that you can insert, and even a graphical palette like other graphical engraving programs for inserting special symbols. When you begin to type a Lilypond tag in the editor Frescobaldi will suggest a completion. Using this feature will save time and prevent many spelling errors. Frescobaldi can be set to auto-engrave, so that every time you make a change to your Lilypond code file, Lilypond will be called to re-engrave it.

Midi and Lilypond

Lilypond will produce midi output if requested, and offers a large range of intruments that it will simulate (i.e. oboe, flute, grand piano, vocal ohs). Frescobaldi even offers midi playback. You can also tell Frescobaldi to accept midi input from a midi source, usually a keyboard, and will transcribe that input into a Lilypond score, and thence to pdf or svg graphic.

Conclusion

I have been using Lilypond for several years, and after some initial ups and downs, have come to enjoy using it as my only music engraving program. I generally use Lilypond through Frescobaldi now, although Lilypond can be invoked simply at the command line on a plain text file. If you like to use an advanced text editor like Vim, rather than the rather simple editor in Frescobaldi, you might just choose the latter approach, invoking Lilypond from within your editor.

Adjusting Margins In Lilypond

In putting together a "song-book", actually a book of dance directions and tunes, I had to add a little extra margin to the top and left side of the tunes, which I engraved in Lilypond. The pages in question were 5.5 inches by 8.5 inches.

I searched online, because the Lilypond documentation is enormous and no doubt complete, but it can be very difficult to locate a clear answer to a simple question. The answer is to add the following lines to the "paper" block in your lilypond text file. If your file doesn't have a paper block, you can simply write one as follows:


paper {

#(define top-margin (* 12 mm))
#(define left-margin (* 12 mm))
#(define right-margin (* 12 mm))
#(define bottom-margin (* 12 mm))

}


Obviously you will have to experiment with different values in the parentheses to get the effect you want. Other interesting instructions can be written into the paper block, I will discuss these in following posts.

Creating A Custom Page Size In Lilypond

To define a custom page size in Lilypond, in this case 5.5 inches by 8.5 inches for our book of dances, the command is a bit complicated and has to be letter perfect. The command defining "my size" is:

  
#(set! paper-alist (cons '("my size" . 

(cons (* 5.5 in) (* 8.5 in))) paper-alist))

The above two segments are togther all on one line.

To use the size defined put the following line in the "paper" block:


#(set-paper-size "my size")

Reducing the size of the Lilypond score

In addition to controlling the margin size, you can use the "paper" block to reduce the size of the lilypond score, by reducing the space between the staves. In the song-book I mentioned above some of the tunes were excessively long and difficult to fit on one page, as you usually want to do in books of this type.

The magic incantation that reduced the length of my lilypond score was this, placed inside the "paper" block:


system-system-spacing = #'((basic-distance .10) (padding . 1))

Of course you can play with these values a little bit and observe the result.

For some of the tunes in our book there was some text below the score, called "markup" in Lilypond terminology, and the whole sometimes overflowed onto another page, despite ample white space still being available on the first page. Since we wanted the tunes and markup to occupy no more than one page it was necessary to force Lilypond to fit all the material onto one page, This I did with this in the "paper" block:


page-count = #1 

I don't suppose Lilypond can work miracles, but this simple command seems the most obvious way to tell Lilypond to make the best use of the available space, when space is at a premium.

Snippets In Frescobaldi

One of Frescobaldi's valuable features is its snippet file, which is available in an optional pane under the "tools" menu. Frescobaldi comes with a number of preinstalled snippets, but it also allows you to extract your own from your score. Select the section of your score that you want to extract to a snippet, and right click on the highlighted selection. A menu will appear offering the option of extracting the selection to a snippet. You can name these snippets and even create keyboard shortcuts to them.

If you have a great deal of repetition in your music, with certain motifs recurring a number of times, writing these motifs once and making snippets of them will great speed entering them when they occur again. A double click of the mouse on the the corresponding snippet name will write the snippet into your file.

The same effect can be produced with copy and paste, but snippets are much faster and more convenient.

Housekeeping With Snippets

If you create too many snippets of your own, you may become confused about what they all are. If you create a snippet for use in only one composition, you can delete it from your snippets file when it is no longer needed.

Snippets In Composition

It has been common for centuries for composers to use recurring motifs to construct a piece of music with both interesting length and unity.