LilyPond Notation Reference: 2.2.1 Common notation for keyboards

### 2.2.1 Common notation for keyboards

This section discusses notation issues that may arise for most keyboard instruments.

#### References for keyboards

Keyboard instruments are usually notated with Piano staves. These are two or more normal staves coupled with a brace. The same notation is also used for other keyed instruments. Organ music is normally written with two staves inside a `PianoStaff` group and third, normal staff for the pedals.

The staves in keyboard music are largely independent, but sometimes voices can cross between the two staves. This section discusses notation techniques particular to keyboard music.

Several common issues in keyboard music are covered elsewhere:

- Keyboard music usually contains multiple voices and the number of voices may change regularly; this is described in Collision resolution.
- Keyboard music can be written in parallel, as described in Writing music in parallel.
- Dynamics may be placed in a `Dynamics` context, between the two `Staff` contexts to align the dynamic marks on a horizontal line centered between the staves; see Dynamics.
- Fingerings are indicated with Fingering instructions.
- Organ pedal indications are inserted as articulations, see List of articulations.
- Vertical grid lines can be shown with Grid lines.
- Keyboard music often contains Laissez vibrer ties as well as ties on arpeggios and tremolos, described in Ties.
- Placing arpeggios across multiple voices and staves is covered in Arpeggio.
- Tremolo marks are described in Tremolo repeats.
- Several of the tweaks that can occur in keyboard music are demonstrated in Real music example.
- Hidden notes can be used to produce ties that cross voices, as shown in Other uses for tweaks.

#### See also

Learning Manual: Real music example, Other uses for tweaks.

Notation Reference: Grouping staves, Instrument names, Collision resolution, Writing music in parallel, Fingering instructions, List of articulations, Grid lines, Ties, Arpeggio, Tremolo repeats.

Internals Reference: PianoStaff.

Snippets: Keyboards.

#### Changing staff manually

Voices can be switched between staves manually, using the command

>     \change Staff = staffname

The string staffname is the name of the staff. It switches the current voice from its current staff to the staff called staffname. Typical values for staffname are `"up"` and `"down"`, or `"RH"` and `"LH"`.

The staff to which the voice is being switched must exist at the time of the switch. If necessary, staves should be “kept alive”, see Keeping contexts alive, or explicitly instantiated, for example by using the empty chord, `<>`, see Chorded notes.

>     \new PianoStaff <<
>       \new Staff = "up" {
>         % enforce creation of all contexts at this point of time
>         <>
>         \change Staff = "down" c2
>         \change Staff = "up" c'2
>       }
>       \new Staff = "down" {
>         \clef bass
>         % keep staff alive
>         s1
>       }
>     >>

Cross-staff notes are beamed automatically:

>     \new PianoStaff <<
>       \new Staff = "up" {
>         <e' c'>8
>         \change Staff = "down"
>         g8 fis g
>         \change Staff = "up"
>         <g'' c''>8
>         \change Staff = "down"
>         e8 dis e
>         \change Staff = "up"
>       }
>       \new Staff = "down" {
>         \clef bass
>         % keep staff alive
>         s1
>       }
>     >>

If the beaming needs to be tweaked, make any changes to the stem directions first. The beam positions are then measured from the center of the staff that is closest to the beam. For a simple example of beam tweaking, see notation Fixing overlapping notation.

Overlapping notation can result when voices cross staves:

>     \new PianoStaff <<
>       \new Staff = "up" {
>         \voiceOne
>         % Make space for fingering in the cross-staff voice
>         \once\override DynamicLineSpanner.staff-padding = #4
>         e''2\p\< d''\>
>         c''1\!
>       }
>       \new Staff = "down" <<
>         {
>           \clef bass
>           s4. e,8\rest g,2\rest
>           c1
>         } \\ {
>           c8\( g c'
>           \change Staff = "up"
>           e' g' b'-3 a' g'\)
>           f'1
>         }
>       >>
>     >>

The stem and slur overlap the intervening line of dynamics because automatic collision resolution is suspended for beams, slurs and other spanners that connect notes on different staves, as well as for stems and articulations if their placement is affected by a cross-staff spanner. The resulting collisions must be resolved manually, where necessary, using the methods in Fixing overlapping notation.

#### See also

Learning Manual: Fixing overlapping notation.

Notation Reference: Stems, Automatic beams, Keeping contexts alive.

Snippets: Keyboards.

Internals Reference: Beam, ContextChange.

#### Known issues and warnings

Beam collision avoidance does not work for automatic beams that end right before a change in staff. In this case use manual beams.

#### Changing staff automatically

Voices can be made to switch automatically between the top and the bottom staff. The syntax for this is

>     \autoChange …music…

This will create two staves inside the current staff group (usually a `PianoStaff`), called `"up"` and `"down"`. The lower staff will be in the bass clef by default. The autoChanger switches on the basis of the pitch (middle C is the turning point), and it looks ahead skipping over rests to switch in advance.

>     \new PianoStaff {
>       \autoChange {
>         g4 a b c'
>         d'4 r a g
>       }
>     }

It is possible to specify other pitches for the turning point. If the staves are not instantiated explicitly, other clefs may be used.

>     music = {
>       g8 b a c' b8 d' c'8 e'
>       d'8 r f' g' a'2
>     }

>     \autoChange d' \music
>     \autoChange b \with { \clef soprano } \music
>     \autoChange d' \with { \clef alto } \with { \clef tenor } \music

A `\relative` section that is outside of `\autoChange` has no effect on the pitches of the music, so if necessary, put `\relative` inside `\autoChange`.

If additional control is needed over the individual staves, they can be created manually with the names `"up"` and `"down"`. The `\autoChange` command will then switch its voice between the existing staves.

Note: If staves are created manually, they must be named `"up"` and `"down"`.

For example, staves must be created manually in order to place a key signature in the lower staff:

>     \new PianoStaff <<
>       \new Staff = "up" {
>         \new Voice = "melOne" {
>           \key g \major
>           \autoChange \relative {
>             g8 b a c b d c e
>             d8 r fis, g a2
>           }
>         }
>       }
>       \new Staff = "down" {
>         \key g \major
>         \clef bass
>       }
>     >>

#### See also

Notation Reference: Changing staff manually.

Snippets: Keyboards.

Internals Reference: AutoChangeMusic.

#### Known issues and warnings

The staff switches may not end up in optimal places. For high quality output, staff switches should be specified manually.

Chords will not be split across the staves; they will be assigned to a staff based on the first note named in the chord construct.

#### Staff-change lines

Whenever a voice switches to another staff, a line connecting the notes can be printed automatically:

>     \new PianoStaff <<
>       \new Staff = "one" {
>         \showStaffSwitch
>         c'1
>         \change Staff = "two"
>         b2 a
>       }
>       \new Staff = "two" {
>         \clef bass
>         s1*2
>       }
>     >>

A staff-change line between chords connects the chords’ “last notes” as written in the source file; this can be used to quickly adjust the line’s vertical start and end positions.

>     \new PianoStaff <<
>       \new Staff = "one" {
>         <c' e' g'>1
>         \showStaffSwitch
>         \change Staff = "two"
>         <a c' f>1
>         \hideStaffSwitch
>         \change Staff = "one"
>         <e' g' c'>1
>         \showStaffSwitch
>         \change Staff = "two"
>         <f a c'>1
>       }
>       \new Staff = "two" {
>         \clef bass
>         s1*4
>       }
>     >>

#### Predefined commands

`\showStaffSwitch`, `\hideStaffSwitch`.

#### See also

Snippets: Keyboards.

Internals Reference: Note_head_line_engraver, VoiceFollower.

#### Selected Snippets

#### Cross staff stems

This snippet shows the use of the `Span_stem_engraver` and `\crossStaff` to connect stems across staves automatically.

The stem length need not be specified, as the variable distance between noteheads and staves is calculated automatically.

>     \layout {
>       \context {
>         \PianoStaff
>         \consists "Span_stem_engraver"
>       }
>     }

>     {
>       \new PianoStaff <<
>         \new Staff {
>           <b d'>4 r d'16\> e'8. g8 r\!
>           e'8 f' g'4 e'2
>         }
>         \new Staff {
>           \clef bass
>           \voiceOne
>           \autoBeamOff
>           \crossStaff { <e g>4 e, g16 a8. c8} d
>           \autoBeamOn
>           g8 f g4 c2
>         }
>       >>
>     }

#### Indicating cross-staff chords with arpeggio bracket

An arpeggio bracket can indicate that notes on two different staves are to be played with the same hand. In order to do this, the `PianoStaff` must be set to accept cross-staff arpeggios and the arpeggios must be set to the bracket shape in the `PianoStaff` context.

(Debussy, Les collines d’Anacapri, m. 65)

>     \new PianoStaff <<
>       \set PianoStaff.connectArpeggios = ##t
>       \override PianoStaff.Arpeggio.stencil =
>         #ly:arpeggio::brew-chord-bracket
>       \new Staff {
>         \relative c' {
>           \key b \major
>           \time 6/8
>           b8-.(\arpeggio fis'-.\> cis-.
>             e-. gis-. b-.)\!\fermata^\laissezVibrer \bar "||"
>         }
>       }
>       \new Staff {
>         \relative c' {
>           \clef bass
>           \key b \major
>           <<
>             {
>               <a e cis>2.\arpeggio
>             }
>             \\
>             {
>               <a, e a,>2.
>             }
>           >>
>         }
>       }
>     >>

#### See also

Snippets: Keyboards.

Internals Reference: Stem.

#### LilyPond — Notation Reference v2.24.4 (stable-branch).