Next: , Up: Multiple notes at once


2.3.1 Music expressions explained

In LilyPond input files, music is represented by music expressions. A single note is a music expression, although it is not valid input all on its own.

     
     a4

[image of music]

Enclosing a group of notes in braces creates a new music expression:

     
     { a4 g4 }

[image of music]

Putting a group of music expressions (e.g. notes) in braces means that they are in sequence (i.e. each one follows the previous one). The result is another music expression:

     
     { { a4 g } f g }

[image of music]

Simultaneous music expressions: multiple staves

This technique is useful for polyphonic music. To enter music with more voices or more staves, we combine expressions in parallel. To indicate that two voices should play at the same time, simply enter a simultaneous combination of music expressions. A ‘simultaneous’ music expression is formed by enclosing expressions inside << and >>. In the following example, three sequences (all containing two separate notes) are combined simultaneously:

     
     \relative c'' {
       <<
         { a4 g }
         { f e }
         { d b }
       >>
     }

[image of music]

Note that we have indented each level of the input with a different amount of space. LilyPond does not care how much (or little) space there is at the beginning of a line, but indenting LilyPond code like this makes it much easier for humans to read.

Warning: each note is relative to the previous note in the input, not relative to the c'' in the initial \relative command.

Simultaneous music expressions: single staff

To determine the number of staves in a piece, LilyPond looks at the first expression. If it is a single note, there is one staff; if there is a simultaneous expression, there is more than one staff.

     
     \relative c'' {
       c2 <<c e>>
       << { e f } { c <<b d>> } >>
     }

[image of music]

Analogy: mathematical expressions

This mechanism is similar to mathematical formulas: a big formula is created by composing small formulas. Such formulas are called expressions, and their definition is recursive so you can make arbitrarily complex and large expressions. For example,

1

1 + 2

(1 + 2) * 3

((1 + 2) * 3) / (4 * 5)

This is a sequence of expressions, where each expression is contained in the next (larger) one. The simplest expressions are numbers, and larger ones are made by combining expressions with operators (like `+', `*' and `/') and parentheses. Like mathematical expressions, music expressions can be nested arbitrarily deep, which is necessary for complex music like polyphonic scores.


Next: , Up: Multiple notes at once

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

Report errors to http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs.

Other languages: French.