4.2.1 I’m hearing Voices

The lowest, most fundamental or innermost layers in a LilyPond score are called ‘Voice contexts’ or just ‘Voices’ for short. Voices are sometimes called ‘layers’ in other notation packages.

In fact, a Voice layer or context is the only one which can contain music. If a Voice context is not explicitly declared one is created automatically, as we saw at the beginning of this chapter. Some instruments such as an Oboe can play only one note at a time. Music written for such instruments requires just a single voice. Instruments which can play more than one note at a time like the piano will often require multiple voices to encode the different concurrent notes and rhythms they are capable of playing.

A single voice can contain many notes in a chord, of course, so when exactly are multiple voices needed? Look first at this example of four chords:

\relative {
  \key g \major
  <d' g>4 <d fis> <d a'> <d g>
}

[image of music]

This can be expressed using just the single angle bracket chord symbols, < … >, and for this just a single voice is needed. But suppose the F-sharp were actually an eighth-note followed by an eighth-note G, a passing note on the way to the A? Now we have two notes which start at the same time but have different durations: the quarter-note D and the eighth-note F-sharp. How are these to be coded? They cannot be written as a chord because all the notes in a chord must have the same duration. And they cannot be written as two sequential notes as they need to start at the same time. This is when two voices are required.

Let us see how this is done in LilyPond input syntax.

The easiest way to enter fragments with more than one voice on a staff is to enter each voice as a sequence (with { … }), and combine them simultaneously with angle brackets, << … >>. The fragments must also be separated with double backward slashes, \\, to place them in separate voices. Without these, the notes would be entered into a single voice, which would usually cause errors. This technique is particularly suited to pieces of music which are largely homophonic with occasional short sections of polyphony.

Here’s how we split the chords above into two voices and add both the passing note and a slur:

\relative {
  \key g \major
  %    Voice = "1"             Voice = "2"
  << { g'4 fis8( g) a4 g } \\ { d4 d d d }  >>
}

[image of music]

Notice how the stems of the second voice now point down.

Here’s another simple example:

\relative {
  \key d \minor
  %    Voice = "1"           Voice = "2"
  << { r4 g' g4. a8 }   \\ { d,2 d4 g }       >> |
  << { bes4 bes c bes } \\ { g4 g g8( a) g4 } >> |
  << { a2. r4 }         \\ { fis2. s4 }       >> |
}

[image of music]

It is not necessary to use a separate << \\ >> construct for each bar. For music with few notes in each bar this layout can help the legibility of the code, but if there are many notes in each bar it may be better to split out each voice separately, like this:

<<
  \key d \minor
  \relative { % Voice = "1"
    r4 g' g4. a8 |
    bes4 bes c bes |
    a2. r4 |
  } \\
  \relative { % Voice = "2"
    d'2 d4 g |
    g4 g g8( a) g4 |
    fis2. s4 |
  }
>>

[image of music]

This example has just two voices, but the same construct may be used to encode three or more voices by adding more back-slash separators.

The Voice contexts bear the names "1", "2", etc. The first contexts set the outer voices, the highest voice in context "1" and the lowest voice in context "2". The inner voices go in contexts "3" and "4". In each of these contexts, the vertical direction of slurs, stems, ties, dynamics etc., is set appropriately.

\new Staff \relative {
  % Main voice
  c'16 d e f
  %  Voice = "1"   Voice = "2"             Voice = "3"
  << { g4 f e } \\ { r8 e4 d c8~ } >> |
  << { d2 e }   \\ { c8 b16 a b8 g~ 2 } \\ { s4 b c2 } >> |
}

[image of music]

If you prefer entering the voices in a different order, like top to bottom, you can specify the respective voice numbers in front of one << … >> construct using the \voices command, like

\new Staff \relative {
  % Main voice
  c'16 d e f
  %  Voice = "1"   Voice = "2"
  << { g4 f e } \\ { r8 e4 d c8~ } >> |
  \voices 1,3,2
  %  Voice = "1"   Voice = "3"    Voice = "2"
  << { d2 e }   \\ { s4 b c2 } \\ { c8 b16 a b8 g~ 2 } >> |
}

[image of music]

These voices are all separate from the main voice that contains the notes just outside the << … >> construct. Let’s call this the simultaneous construct. Slurs and ties may only connect notes within the same voice, so slurs and ties cannot go into or out of a simultaneous construct. Conversely, parallel voices from separate simultaneous constructs on the same staff are the same voice. Other voice-related properties also carry across simultaneous constructs. Here is the same example, with different colors and note heads for each voice. Note that changes in one voice do not affect other voices, but they do persist in the same voice later. Note also that tied notes may be split across the same voices in two constructs, shown here in the blue triangle voice.

\new Staff \relative {
  % Main voice
  c'16 d e f
  <<  % Bar 1
    {
      \voiceOneStyle
      g4 f e
    }
  \\
    {
      \voiceTwoStyle
      r8 e4 d c8~
    }
  >> |
  <<  % Bar 2
     % Voice 1 continues
    { d2 e }
  \\
     % Voice 2 continues
    { c8 b16 a b8 g~ 2 }
  \\
    {
      \voiceThreeStyle
      s4 b c2
    }
  >> |
}

[image of music]

The commands \voiceXXXStyle are mainly intended for use in educational documents such as this one. They modify the color of the note head, the stem and the beams, and the style of the note head, so that the voices may be easily distinguished. Voice one is set to red diamonds, voice two to blue triangles, voice three to green crossed circles, and voice four (not used here) to magenta crosses; \voiceNeutralStyle (also not used here) reverts the style back to the default. We shall see later how commands like these may be created by the user. See Visibility and color of objects and Using variables for layout adjustments.

Polyphony does not change the relationship of notes within a \relative block. Each note is still calculated relative to the note immediately preceding it, or to the first note of the preceding chord. So in

\relative { noteA << < noteB noteC > \\ noteD >> noteE }

noteB is relative to noteA
noteC is relative to noteB, not noteA;
noteD is relative to noteB, not noteA or noteC;
noteE is relative to noteD, not noteA.

An alternative way, which may be clearer if the notes in the voices are widely separated, is to place a \relative command at the start of each voice:

\relative { noteA … }
<<
  \relative { < noteB noteC > … }
\\
  \relative { noteD … }
>>
\relative { noteE … }

Let us finally analyze the voices in a more complex piece of music. Here are the notes from the first two bars of the second of Chopin’s Deux Nocturnes, Op 32. This example will be used at later stages in this and the next chapter to illustrate several techniques for producing notation, so please ignore for now anything in the underlying code which looks mysterious and concentrate just on the music and the voices – the complications will all be explained in later sections.

[image of music]

The direction of the stems is often used to indicate the continuity of two simultaneous melodic lines. Here the stems of the highest notes are all pointing up and the stems of the lower notes are all pointing down. This is the first indication that more than one voice is required.

But the real need for multiple voices arises when notes which start at the same time have different durations. Look at the notes which start at beat three in the first bar. The A-flat is a dotted quarter note, the F is a quarter note and the D-flat is a half note. These cannot be written as a chord as all the notes in a chord must have the same duration. Neither can they be written as sequential notes, as they must start at the same time. This section of the bar requires three voices, and the normal practice would be to write the whole bar as three voices, as shown below, where we have used different note heads and colors for the three voices. Again, the code behind this example will be explained later, so ignore anything you do not understand.

[image of music]

Let us try to encode this music from scratch. As we shall see, this encounters some difficulties. We begin as we have learnt, using the << \\ >> construct to enter the music of the first bar in three voices:

\new Staff \relative {
  \key aes \major
  <<
    { c''2 aes4. bes8 } \\ { <ees, c>2 des } \\ { aes'2 f4 fes }
  >> |
  <c ees aes c>1 |
}

[image of music]

The stem directions are automatically assigned with the odd-numbered voices taking upward stems and the even-numbered voices downward ones. The stems for voices 1 and 2 are right, but the stems in voice 3 should go down in this particular piece of music. We can correct this by skipping voice three and placing the music in voice four. This could be done by simply adding another pair of \\, but we use the \voices command instead (which would also allow us to enter the voices in different order if we preferred doing that):

\new Staff \relative {
  \key aes \major
  \voices 1,2,4   % Omit Voice three
  <<  % Voice one
    { c''2 aes4. bes8 }
  \\  % Voice two
    { <ees, c>2 des }
  \\  % Voice four
    { aes'2 f4 fes }
  >> |
  <c ees aes c>1 |
}

[image of music]

We see that this fixes the stem direction, but the horizontal placement of notes is not what we want. LilyPond shifts the inner notes when they or their stems would collide with outer voices, but this is not appropriate for piano music. In other situations, the shifts LilyPond applies might fail to clear the collisions. LilyPond provides several ways to adjust the horizontal placing of notes. We are not quite ready yet to see how to correct this, so we shall leave this problem until a later section — see the force-hshift property in Fixing overlapping notation.

Note: Lyrics, spanners (such as slurs, ties, hairpins, etc.) cannot be created ‘across’ voices.

See also

Notation Reference: Multiple voices.


LilyPond — Learning Manual v2.24.4 (stable-branch).