🥳 Join the Blues Challenge! 🎉
Frazier Piano Studio

Getting Started with Lilypond

Lilypond is an excellent alternative to music notation software like Sibelius and Finale. This tutorial will give you everything you need to know to get started writing music in Lilypond.

Lilypond is radically different in it's approach. It reads a text file to produce a score instead of utilizing a point and click application. Lilypond gives you a lot of power to customize your music scores.

Pros and Cons of Lilypond #

Pros #

Cons #

Although a little outdated (being last updated in 2011), a more detailed comparison between Finale and Lilypond can be found here.

Your first score #

Here is the most basic Lilypond score:

\score{
  {
    c'
  }
  
  \layout{}
  \midi{}
}

Let's walk through every line in this first example.

Line 1 – Everything preceded by a % is a comment that will be ignored by LilyPond

Line 2 – Every directive in Lilypond is preceded by a \. In this example there is \score \layout and \midi. Each of these are instructions to LilyPond about what to render. Most directives mark a block and are enclosed with curly braces.

\score{
  % stuff
  % inside a block
}

Line 4 – Here are the notes to be rendered. Try adding some notes here and see what happens. The ' means to go up an octave and , means to go down an octave. Try this:

\score{
  {
    \clef bass
    c' c c,
  }

  \layout{}
  \midi{}
}

Your first piano score #

Now let's add some more things to this to get a full piano score.

\version "2.18.2"

global = {
  \key c \major
  \time 4/4
}

right = \relative c' {
  \global
  \clef treble
  c4 d e f g1 \bar "|."
}

left = \relative c {
  \global
  \clef bass
  c2 g' c,1
}

\score {
  \new PianoStaff \with {
    instrumentName = "Piano"
  } <<
    \new Staff = "right" \right
    \new Staff = "left" \left
  >>
  \layout { }
}
Piano

Again, let's walk through this line by line.

Line 1 – This specifies the version of Lilypond with which the file is compatible. Sometimes something that will work in version 2.19 won't work in version 2.18. Mostly this is for others when you share the file to let them know what version you were using.

Line 3 – A variable name. There are 3 variables in this file: global, right (line 8), and left (line 14). Variables are a handy way of saving you from typing out the same things multiple times. After the variable has been defined, you reference it with a \ then the variable name. So in line 9 \global is the same thing as writing out

right = \relative c' {
  \key c \major
  \time 4/4
  \clef treble
  c4 d e f g1 \bar "|."
}

A warning! Don't use keywords for variable names, such as key or time. Lilypond needs these words so you shouldn't redefine them.

Line 8 – \relative c' This sets all the notes in the block as relative to C4 or middle C. The other way of writing notes is absolute, meaning all notes are relative to C3. See the documentation for more on writing pitches.

Line 11 – The numbers following the note are the rhythmic value of the note. The note will stay the same value as the ones preceding it until the value is changed. So c4 d4 e4 f2 g2 c1 is the same as writing c4 d e f2 g c1.

Also the ordering matters. Don't write c4,, instead write c,4. The , alters the c not the rhythm.

Rests, Rhythm, Ties, and Chords #

Here's a silly example with a bunch of random stuff in it for reference. I put this here partially for myself to have an easy reference.

\version "2.18.2"

\header {
  title = "Oh! Susanna"
  subtitle = "Don't you cry for me"
  instrument = "piano"
  composer = "Stephen Foster"
  copyright = "Public Domain"
  tagline = "This is a tagline"
}

global = {
  \key c \major
  \time 4/4
}

right = \relative c' {
  \global
  \clef treble
  \partial 4
  c8( d |
  e4) g g4. a8 |
  g4 e ~c4 ~c8 d8 |
  ees4 e d cis |
  d1 \bar "|."
}

left = \relative c {
  \global
  \clef bass
  r4 |
  <c e g>2 g4 a8-. b-. |
  c2 g4 \tuplet 3/2 {g8 a b} |
  c2 d4 s |
  g1
}

\score {
  \new PianoStaff \with {
    instrumentName = "Piano"
  } <<
    \new Staff = "right" \right
    \new Staff = "left" \left
  >>
  \layout { }
}
Oh! SusannaDon't you cry for mepianoStephen Foster3Piano

After you have played with the example a bit, here are some thoughts.

Slurs (line 21 - 22) begin at the end of a note c8( and go until the note preceding the closing paren e4).

Ties (line 23) are marked with ~.

Chords (line 32) are placed within angle brackets <c e g>. If you are writing polyphonic music you will need to split up the voices for more control. See the documentation for more information.

Staccatos (line 32) are put in here with a shorthand a8-.. You could also do a8\staccato. See the documentation for more information.

Triplets (line 33) are enclosed in a new block. Be sure to give the note inside a note value and remember to restate the rhythm value after the tuplet is over.

Measure marks are denoted with |. This is the pipe character usually found in the upper right hand of the keyboard with the forward slash key. Lilypond will put bars in for you but this is just a convenient way to keep track of where you are visually in the code. If you place it in the wrong spot nothing bad will happen though.

Rests and spacers are denoted with r and s and are treated just like notes. I often use spacers for worksheets where I don't want to show rests or notes.

Accidentals (line 24) are denoted by default with Dutch note naming convention as es (flat) or is (sharp). You can use other naming conventions with the \language setting. With \language english you could use flat or sharp (or shorthand f and s) like this:

\language english

\score {
  {
    \clef bass
    bflat c dsharp
  }
  \layout{}
}

With Frescobaldi you can use a midi keyboard for input. There is a Finale-like Score Wizard in Frescobaldi for quickly getting your scores started. Frescobaldi will also catch and highlight errors in your score so you can fix them.

That should get you started with making scores. Things I haven't covered are dynamics, lyrics, chord analysis, lead sheets, and figured bass. Lilypond does this all very well. That will wait for another post.