LilyPond Learning Manual: A.2 Piano templates

## A.2 Piano templates

### A.2.1 Solo piano

Here is a simple piano staff with some notes.

>     upper = \relative c'' {
>       \clef treble
>       \key c \major
>       \time 4/4

>       a4 b c d
>     }

>     lower = \relative c {
>       \clef bass
>       \key c \major
>       \time 4/4

>       a2 c
>     }

>     \score {
>       \new PianoStaff <<
>         \set PianoStaff.instrumentName = #"Piano  "
>         \new Staff = "upper" \upper
>         \new Staff = "lower" \lower
>       >>
>       \layout { }
>       \midi { }
>     }

### A.2.2 Piano and melody with lyrics

Here is a typical song format: one staff with the melody and lyrics, with piano accompaniment underneath.

>     melody = \relative c'' {
>       \clef treble
>       \key c \major
>       \time 4/4

>       a b c d
>     }

>     text = \lyricmode {
>       Aaa Bee Cee Dee
>     }

>     upper = \relative c'' {
>       \clef treble
>       \key c \major
>       \time 4/4

>       a4 b c d
>     }

>     lower = \relative c {
>       \clef bass
>       \key c \major
>       \time 4/4

>       a2 c
>     }

>     \score {
>       <<
>         \new Voice = "mel" { \autoBeamOff \melody }
>         \new Lyrics \lyricsto mel \text
>         \new PianoStaff <<
>           \new Staff = "upper" \upper
>           \new Staff = "lower" \lower
>         >>
>       >>
>       \layout {
>         \context { \Staff \RemoveEmptyStaves }
>       }
>       \midi { }
>     }

### A.2.3 Piano centered lyrics

Instead of having a full staff for the melody and lyrics, lyrics can be centered between the staves of a piano staff.

>     upper = \relative c'' {
>       \clef treble
>       \key c \major
>       \time 4/4

>       a4 b c d
>     }

>     lower = \relative c {
>       \clef bass
>       \key c \major
>       \time 4/4

>       a2 c
>     }

>     text = \lyricmode {
>       Aaa Bee Cee Dee
>     }

>     \score {
>       \new GrandStaff <<
>         \new Staff = upper { \new Voice = "singer" \upper }
>         \new Lyrics \lyricsto "singer" \text
>         \new Staff = lower { \lower }
>       >>
>       \layout {
>         \context {
>           \GrandStaff
>           \accepts "Lyrics"
>         }
>         \context {
>           \Lyrics
>           \consists "Bar_engraver"
>         }
>       }
>       \midi { }
>     }

### A.2.4 Piano centered dynamics

Many piano scores have the dynamics centered between the two staves. The `Dynamics` context, if placed between staves, will automatically position dynamics correctly.

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

>     upper = \relative c'' {
>       \clef treble
>       a4 b c d
>     }

>     lower = \relative c {
>       \clef bass
>       a2 c
>     }

>     dynamics = {
>       s2\fff\> s4 s\!\pp
>     }

>     pedal = {
>       s2\sustainOn s\sustainOff
>     }

>     \score {
>       \new PianoStaff = "PianoStaff_pf" <<
>         \new Staff = "Staff_pfUpper" << \global \upper >>
>         \new Dynamics = "Dynamics_pf" \dynamics
>         \new Staff = "Staff_pfLower" << \global \lower >>
>         \new Dynamics = "pedal" \pedal
>       >>
>       \layout { }
>     }

>     \score {
>       \new PianoStaff = "PianoStaff_pf" <<
>         \new Staff = "Staff_pfUpper" << \global \upper \dynamics \pedal >>
>         \new Staff = "Staff_pfLower" << \global \lower \dynamics \pedal >>
>       >>
>       \midi { }
>     }

Other languages: česky, deutsch, español, français, italiano, 日本語, nederlands.

#### LilyPond — Learning Manual