Next: , Previous: Clef, Up: Displaying pitches


1.1.3.2 Key signature

Note: New users are sometimes confused about accidentals and key signatures. In LilyPond, note names are the raw input; key signatures and clefs determine how this raw input is displayed. An unaltered note like c means ‘C natural’, regardless of the key signature or clef. For more information, see Accidentals and key signatures.

The key signature indicates the tonality in which a piece is played. It is denoted by a set of alterations (flats or sharps) at the start of the staff. Setting or changing the key signature is done with the \key command:

\key pitch mode

Here, mode should be \major or \minor to get a key signature of pitch-major or pitch-minor, respectively. You may also use the standard mode names, also called ‘church modes’: \ionian, \dorian, \phrygian, \lydian, \mixolydian, \aeolian, and \locrian.

     
     \key g \major
     fis1
     f
     fis

[image of music]

Selected Snippets

When the key signature changes, natural signs are automatically printed to cancel any accidentals from previous key signatures. This may be altered by setting to "false" the printKeyCancellation property in the Staff context.

     
     \relative {
       \key d \major
       a b cis d
       \key g \minor
       a bes c d
       \set Staff.printKeyCancellation = ##f
       \key d \major
       a b cis d
       \key g \minor
       a bes c d
     }

[image of music]

The commonly used \key command sets the keySignature property, in the Staff context. However, non-standard key signatures can be specified by setting this property directly. The format of this command is a list: \set Staff.keySignature = #'(((octave . step) . alter) ((octave . step) . alter) ...) where, for each element in the list, octave specifies the octave (0 being the octave from middle C to the B above), step specifies the note within the octave (0 means C and 6 means B), and alter is ,SHARP ,FLAT ,DOUBLE-SHARP etc. (Note the leading comma.)

However, for each item in the list, you can also use the alternative format (step . alter), which specifies that the same alteration should hold in all octaves.

Here is an example of a possible key signature for generating a whole-tone scale:

     
     \relative c' {
       \set Staff.keySignature =
         #`(((0 .  3) . ,SHARP) ((0 . 5) . ,FLAT) ((0 . 6) . ,FLAT))
       c d e fis aes bes c2
     }
     

[image of music]

See also

Music Glossary: church mode, scordatura.

Learning Manual: Accidentals and key signatures.

Snippets: Pitches .

Internals Reference: KeyCancellation, KeySignature, Key_engraver.


Next: , Previous: Clef, Up: Displaying pitches

This page is for LilyPond-2.11.40 (development-branch).

Report errors to http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs.

Your suggestions for the documentation are welcome.

Other languages: français, español, deutsch.