2.1.2 Pitches and key signatures

Note: New users often misunderstand how LilyPond uses the key signature – please read the warning at the bottom of this page.


Pitch alterations

Music Glossary: sharp, flat, double sharp, double flat, accidental.

Note-names in LilyPond identify pitches. For example, c always means C-natural, regardless of the key signature.

A sharp pitch is made by adding is to the name, and a flat pitch by adding es. As you might expect, a double sharp or double flat is made by adding isis or eses. This syntax is derived from note naming conventions in Nordic and Germanic languages, like German and Dutch. To use other names for alterations, see Note names in other languages.

\relative { cis''4 ees fisis, aeses }

[image of music]


Key signatures

Music Glossary: key signature, major, minor.

The key signature is set with the command \key followed by a pitch and \major or \minor.

\relative {
  \key d \major
  d'4 fis a c |
  \bar "||" \key c \minor
  c,4 ees g b |
}

[image of music]



Warning: key signatures and pitches

Music Glossary: accidental, key signature, pitch, flat, natural, sharp, transposition, Pitch names.

LilyPond makes a distinction between musical content and its printed representation. Input such as d4 e fis2 defines the pitches and durations of notes, which is musical content. The key signature is part of the printed representation. The key signature also sets rules for the printed representations of notes. LilyPond compares each input pitch to the key signature to determine whether to print an accidental.

The command \key sets the key signature, which affects the printed representation, but does not change the pitch assigned to a note such as c in the input.

In this example:

\relative {
  \key d \major
  cis''4 d e fis
}

[image of music]

No note has a printed accidental, but you must still add is and type cis and fis in the input file.

The code b does not mean “print a black dot just on the middle line of the staff.” Rather, it means “there is a note with pitch B-natural.” In the key of A-flat major, it does get an accidental:

\relative {
  \key aes \major
  aes'4 c b c
}

[image of music]

Whenever you enter a pitch that is a black key on the piano, you must add -is or -es to the note name.

Adding all alterations explicitly might require a little more effort when typing, but the advantage is that transposing is easier, and accidentals can be printed according to different conventions. For some examples of how accidentals can be printed according to different rules, see Automatic accidentals.

See also

Notation Reference: Note names in other languages, Accidentals, Automatic accidentals, Key signature.


Other languages: deutsch, español, français, magyar, italiano, 日本語.
About automatic language selection.

LilyPond — Learning Manual v2.19.80 (development-branch).