3.1.2 Score is a (single) compound musical expression

We saw the general organization of LilyPond input files in the previous section, Introduction to the LilyPond file structure. But we seemed to skip over the most important part: how do we figure out what to write after \score?

We didn’t skip over it at all. The big mystery is simply that there is no mystery. This line explains it all:

A \score block must contain exactly one music expression.

To understand what is meant by a music expression, you may find it useful to review the tutorial, Music expressions explained. In that section, we saw how to build big music expressions from small pieces – we started from notes, then chords, etc. Now we’re going to start from a big music expression and work our way down. For simplicity, we’ll use just a singer and piano in our example. We don’t need a StaffGroup for this ensemble, which simply groups a number of staves together with a bracket at the left, but we do need staves for a singer and a piano, though.

\score {
  <<
    \new Staff = "singer" <<
    >>
    \new PianoStaff = "piano" <<
    >>
  >>
  \layout { }
}

Here we have given names to the staves – “singer” and “piano”. This is not essential here, but it is a useful habit to cultivate so that you can see at a glance what each stave is for.

Remember that we use << … >> instead of { … } to show simultaneous music. This causes the vocal part and piano part to appear one above the other in the score. The << … >> construct would not be necessary for the Singer staff in the example above if it were going to contain only one sequential music expression, but << … >> rather than braces is necessary if the music in the Staff is to contain two or more simultaneous expressions, e.g. two simultaneous Voices, or a Voice with lyrics. We’re going to have a voice with lyrics, so angle brackets are required. We’ll add some real music later; for now let’s just put in some dummy notes and lyrics. If you’ve forgotten how to add lyrics you may wish to review \addlyrics in Setting simple songs.

\score {
  <<
    \new Staff = "singer" <<
      \new Voice = "vocal" { c'1 }
      \addlyrics { And }
    >>
    \new PianoStaff = "piano" <<
      \new Staff = "upper" { c'1 }
      \new Staff = "lower" { c'1 }
    >>
  >>
  \layout { }
}

[image of music]

Now we have a lot more details. We have the singer’s staff: it contains a Voice (in LilyPond, this term refers to a set of notes, not necessarily vocal notes – for example, a violin generally plays one voice) and some lyrics. We also have a piano staff: it contains an upper staff (right hand) and a lower staff (left hand), although the lower staff has yet to be given a bass clef.

At this stage, we could start filling in notes. Inside the curly braces next to \new Voice = "vocal", we could start writing

\relative c'' {
  r4 d8\noBeam g, c4 r
}

But if we did that, the \score section would get pretty long, and it would be harder to understand what was happening. So let’s use variables instead. These were introduced at the end of the previous section, remember? To ensure the contents of the text variable are interpreted as lyrics we preface them with \lyricmode. Like \addlyrics, this switches the input mode to lyrics. Without that, LilyPond would try to interpret the contents as notes, which would generate errors. (Several other input modes are available, see Input modes.)

So, adding a few notes and a bass clef for the left hand, we now have a piece of real music:

melody = \relative c'' { r4 d8\noBeam g, c4 r }
text   = \lyricmode { And God said, }
upper  = \relative c'' { <g d g,>2~ <g d g,> }
lower  = \relative c { b2 e }

\score {
  <<
    \new Staff = "singer" <<
      \new Voice = "vocal" { \melody }
      \addlyrics { \text }
    >>
    \new PianoStaff = "piano" <<
      \new Staff = "upper" { \upper }
      \new Staff = "lower" {
        \clef "bass"
        \lower
      }
    >>
  >>
  \layout { }
}

[image of music]

When writing (or reading) a \score section, just take it slowly and carefully. Start with the outer level, then work on each smaller level. It also really helps to be strict with indentation – make sure that each item on the same level starts on the same horizontal position in your text editor.

See also

Notation Reference: Structure of a score.


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

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