Eyes, JAPAN Blog > A Brief Introduction to LilyPond

A Brief Introduction to LilyPond

LyEdward

この記事は1年以上前に書かれたもので、内容が古い可能性がありますのでご注意ください。

Introduction


When you think about software for producing sheet music, the first ones that come to mind may be the more popular options such as Sibelius or Finale, all of which include a GUI that is intended to make the process of producing sheet music easier and more accessible to all users. Indeed, one would initially believe that a GUI would actually be a de facto requirement to produce a document as visual and graphical as sheet music. Today, however, I want to introduce LilyPond, a different option that can generate sheet music with just a few lines of code. And unlike Sibelius or Finale, LilyPond is free and open-source under the GNU license! While “LilyPond” technically refers to the software that “compiles” text into a sheet music document, LilyPond can also be described as its own typesetting language similar to LaTeX. Indeed, the LilyPond project started as an extension of TeX, and it is possible to embed LilyPond code into a LaTeX document to create anything from research papers to lesson books as well. In this blog post, I will briefly introduce the basic syntax that makes up the “language” of LilyPond so that you can get started making your own sheet music from scratch.

Basic Syntax


Comments

Single-line comments start with the reserved character “%” and last until the end of the line. Block comments, or multi-line comments, are enclosed between “%{” and “%}”.

Commands

Commands are functions whose names always begin with a backslash (\). Command arguments, if any, may be placed before or after each command declaration depending on the command in question. Some of the most commonly used commands include:

  • \version – specifies the LilyPond version that should be used to parse the text
  • \clef – specifies the clef of a staff, usually “treble” or “bass”
  • \time – specifies the time signature (for example, “4/4”, “3/4”, or “5/8”)
  • \key – specifies the key signature, which consists of a note pitch followed by “\major” or “\minor”

Pitch & Rhythms

Specifying the pitch of each note is based on the Helmholtz pitch notation: each of the lowercase letters “c d e f g a b” represent the seven notes below middle C (an “r” is used to indicate a “rest”, or no note is played). Adding a flat or sharp to the note is as simple as appending “es” or “is”, respectively (these are the Dutch names which are used by default in LilyPond, but other languages including English are available as well). One or more commas (,) after the resulting note decreases the pitch by that many octaves, while one or more apostrophes (‘) increases the pitch by that many octaves instead. Two or more notes can then be enclosed in brackets (<>) to make a chord (multiple notes played simultaneously).

Specifying the duration of a note is done by appending an integer power of two to the desired note, rest, or chord. A “1” indicates a whole note (four beats), a “2” indicates a half note, “4” for quarter note, and so on. One or more periods (.) after the number creates a dotted note with an equal number of dots. If no number is given to a note, the duration of the previous note is implied. Triplets and other tuples are denoted by “\tuplet x/y {n_1 n_2 …}”, where “x” is the number of notes, “y” is the duration of the tuplet relative to “x”, and “n_1 n_2 …” is the list of notes (or rests) in the tuple.

Putting it all together, here are some examples of notes that you can create:

  • “des’4.” – a dotted quarter note (1.5 beats) on the D-flat just above middle C.
  • “<c e g>2” – a C major chord played a half note long
  • “\tuplet 3/2 {c8 c r}” – two Cs each played a 12th note long, followed by a 12th note rest

Conclusion


Now that you know how LilyPond works, you now have the basic tools to generate beautiful sheet music, practice recreating your favorite melodies, or even create your own music composition! There is so much more to the LilyPond language than what I can cover here, all of which is entirely free and community-driven. If you are interested in learning more, you can visit the LilyPond Documentation or browse the Mutopia Project for examples of real classical music engraved with LilyPond.

Comments are closed.