Score is a single musical expression - GNU LilyPond
Description: GNU LilyPond

Previous: How LilyPond files work, Up: Putting it all together

### 3.3 Score is a single musical expression

In the previous section, How LilyPond files work, we saw the general organization of LilyPond input files. 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` must begin with a single music expression.

You may find it useful to review 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.

    \score {
      {   % this brace begins the overall music expression
        \new GrandStaff <<
          insert the whole score of a Wagner opera in here
        >>
      }   % this brace ends the overall music expression
      \layout { }
    }

A whole Wagner opera would easily double the length of this manual, so let's just do a singer and piano. We don't need a `GrandStaff` for this ensemble, so we shall remove it. We do need a singer and a piano, though.

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

Remember that we use `<<` and `>>` to show simultaneous music. And we definitely want to show the vocal part and piano part at the same time!

    \score {
      {
        <<
          \new Staff = "singer" <<
            \new Voice = "vocal" { }
          >>
          \new Lyrics \lyricsto vocal \new Lyrics { }
          \new PianoStaff = "piano" <<
            \new Staff = "upper" { }
            \new Staff = "lower" { }
          >>
        >>
      }
      \layout { }
    }

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).

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

    \relative c'' {
      a4 b c d
    }

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 identifiers (or variables) instead.

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

Remember that you can use almost any name you like. The limitations on identifier names are detailed in File structure.

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

This page is for LilyPond-2.8.8 (stable-branch).

Other languages: English.
Using automatic language selection.