lilypond-learning: Multiple staves

 
 2.2.2 Multiple staves
 ---------------------
 
 LilyPond input files are constructed out of music expressions, as we saw
 in SeeMusic expressions explained.  If the score begins with
 simultaneous music expressions, LilyPond creates multiples staves.
 However, it is easier to see what happens if we create each staff
 explicitly.
 
    To print more than one staff, each piece of music that makes up a
 staff is marked by adding ‘\new Staff’ before it.  These ‘Staff’
 elements are then combined in parallel with ‘<<’ and ‘>>’:
 
      \relative c'' {
        <<
          \new Staff { \clef "treble" c4 }
          \new Staff { \clef "bass" c,,4 }
        >>
      }
      [image src="" alt="[image of music]" text="image of music"]
 
    The command ‘\new’ introduces a ‘notation context.’ A notation
 context is an environment in which musical events (like notes or ‘\clef’
 commands) are interpreted.  For simple pieces, such notation contexts
 are created automatically.  For more complex pieces, it is best to mark
 contexts explicitly.
 
    There are several types of contexts.  ‘Score’, ‘Staff’, and ‘Voice’
 handle melodic notation, while ‘Lyrics’ sets lyric texts and
 ‘ChordNames’ prints chord names.
 
    In terms of syntax, prepending ‘\new’ to a music expression creates a
 bigger music expression.  In this way it resembles the minus sign in
 mathematics.  The formula (4+5) is an expression, so -(4+5) is a bigger
 expression.
 
    Time signatures entered in one staff affect all other staves by
 default.  On the other hand, the key signature of one staff does _not_
 affect other staves.  This different default behavior is because scores
 with transposing instruments are more common than polyrhythmic scores.
 
      \relative c'' {
        <<
          \new Staff { \clef "treble" \key d \major \time 3/4 c4 }
          \new Staff { \clef "bass" c,,4 }
        >>
      }
      [image src="" alt="[image of music]" text="image of music"]