It's not really clear in the LilyPond documentation (or at least, I haven't found it) as to when you should use << something >>
or { something }
. It does seem to matter, since when I used braces for my staff group I got one part, then the other in sequence, but when I used the double arrows it engraved correctly. Is there a guide somewhere for when to use each type of container?
2 Answers
It’s really just what these each mean in and of themselves that counts:
In LilyPond input files, music is represented by music expressions. A single note is a music expression.
(source)
Ergo, a'4
is a music expression.
Enclosing a note in braces creates a compound music expression.
(source)
Ergo, { a'4 b'4 }
is a compound music expression. Everything in between those braces will be processed sequentially.
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>>
.
(source)
Ergo, << a'4 b'4 >>
is a simultaneous music expression.
The documentation in that last section usefully provides more than one example of what you can combine. You can produce multiple lines of music in parallel within a single staff.
Here are some examples of these in practice (although with practice you will find more efficient ways of implementing these):
{
\relative { a'4 b }
\relative { c''4 d }
}
because these two music expressions are surrounded by braces, it means, “display everything in the first music expression before moving on to the second.”
<<
\relative { a'4 b }
\relative { c''4 d }
>>
because these two music expressions are surrounded by chevrons, it means, “display both of these at the same time.”
(Note: the music expressions are only of single notes here, but you'll see that a staff, clef, key, and time signature are created automatically. LilyPond provides those as defaults if the user does not explicitly enter them.)
How you choose to combine these is entirely up to you. Some will become apparent through practice:
\new Staff <<
\new Voice
\new Voice
>>
\new Staff {
\new Voice
\new Voice
}
The first expression above is attempting to create one staff with two “Voices” (lines of music) that occur simultaneously. The second expression is attempting to create one staff with two Voices that occur one after another. There are various use cases for doing one or another. For instance, if for some reason you want to write variables of music separately that will all go together in sequence eventually, you can do something like this:
first_section = \relative c' {
music goes here
}
second_section \relative c' {
more music
}
\score {
\new Staff { <------------------- because these two Voices
\new Voice { \first_section } are surrounded by braces,
\new Voice { \second_section } they will occur sequentially.
} <------------------------------
}
Or, another much more common use case is multiple instruments playing together:
first_instrument = \relative c' {
music goes here
}
second_instrument \relative c' {
more music
}
\score {
<< <---------------------------- because these two Staves are
\new Staff { surrounded by chevrons,
\new Voice { \first_instrument } they will occur simultaneously.
}
\new Staff {
\new Voice { \second_instrument }
}
>> <----------------------------
}
You can even start to come up with more complex use cases:
monophonic_section = \relative c' {
music goes here
}
polyphonic_section_first_voice = \relative c' {
more music
}
polyphonic_section_second_voice = \relative c' {
even more music
}
\score {
\new Staff {
\new Voice { <------------------- This starts a sequential music expression.
\monophonic_section < ---------- Ergo, this comes first.
<< <---------------------------- This follows, which is a new simultaneous music expression...
\polyphonic_section_first_voice <-- Which means that these two
\polyphonic_section_second_voice <- happen simultaneously.
>> <---------------------------- This closes the simultaneous music expression.
} <-------------------------------- This closes the sequential music expression.
}
}
I've been puzzled by that too, and didn't find a reference either, but this is the way I look at it (which may be incomplete or even partially wrong):
<<
and>>
for things that happen simultaneously (in time){
and}
for everything else
Examples of the first are:
- two or more parts (voices, or melody + chords) in a staff, as you already noted
- polyphony
Both are listed in the cheat sheet.