4.2.1 I’m hearing voices (LilyPond Learning Manual)

#### 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 that 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 that 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>
>     }

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 was 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 } >>
>     }

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. r4 }       >> |
>     }

It is not necessary to use a separate `<< \\ >>` construct for each bar. For music with few notes in each bar this layout can help improve 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. r4 |
>       }
>     >>

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 implicitly created by `<< \\ >>` 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 } >> |
>     }

Note the use of `s4` to insert an invisible spacer rest, thus delaying the (visible) start of voice `"3"`.

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 } >> |
>     }

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 }
>       >> |
>     }

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 that looks mysterious and concentrate just on the music and the voices – the complications will all be explained in later sections.

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 starting at the same time have different durations. Look at the notes that 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.

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 |
>     }

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 |
>     }

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 always 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.26.0 (stable-branch).

- 1 Installing
  - 1.1 Graphical setup
  - 1.2 Command line setup
- 2 Tutorial
  - 2.1 Compiling a file
  - 2.2 How to write input files
    - 2.2.1 Input characters
    - 2.2.2 Simple notation
      - Pitches
      - Durations (rhythms)
      - Rests
      - Time signature
      - Tempo marks
      - Clef
      - All together
    - 2.2.3 Working on input files
  - 2.3 Dealing with errors
  - 2.4 How to read the manuals
    - 2.4.1 Omitted material
    - 2.4.2 Clickable examples
    - 2.4.3 Overview of manuals
- 3 Common notation
  - 3.1 Single-staff notation
    - 3.1.1 Bar lines and bar checks
      - Bar lines
      - Bar checks
    - 3.1.2 Pitches and key signatures
      - Pitch alterations
      - Key signatures
      - Warning: key signatures and pitches
    - 3.1.3 Ties and slurs
      - Ties
      - Slurs
      - Phrasing slurs
      - Warnings: slurs vs. ties
    - 3.1.4 Articulations and dynamics
      - Articulations
      - Fingerings
      - Dynamics
    - 3.1.5 Adding text
    - 3.1.6 Automatic and manual beams
    - 3.1.7 Advanced rhythmic commands
      - Partial measure
      - Tuplets
      - Grace notes
  - 3.2 Multiple notes at once
    - 3.2.1 Music expressions explained
      - Analogy: mathematical expressions
      - Simultaneous music expressions: multiple staves
      - Simultaneous music expressions: single-staff
    - 3.2.2 Multiple staves
    - 3.2.3 Staff groups
    - 3.2.4 Combining notes into chords
    - 3.2.5 Single-staff polyphony
  - 3.3 Songs
    - 3.3.1 Setting simple songs
    - 3.3.2 Aligning lyrics to a melody
    - 3.3.3 Lyrics to multiple staves
  - 3.4 Final touches
    - 3.4.1 Organizing pieces with variables
    - 3.4.2 Adding titles
    - 3.4.3 Absolute note names
    - 3.4.4 After the tutorial
- 4 Fundamental concepts
  - 4.1 How LilyPond input files work
    - 4.1.1 Introduction to the LilyPond file structure
    - 4.1.2 A score is a (single) compound musical expression
    - 4.1.3 Nesting music expressions
    - 4.1.4 Structure of a note entry
    - 4.1.5 On the un-nestedness of brackets and ties
  - 4.2 Voices contain music
    - 4.2.1 I’m hearing voices
    - 4.2.2 Explicitly instantiating voices
    - 4.2.3 Voices and vocals
  - 4.3 Contexts and engravers
    - 4.3.1 Contexts explained
    - 4.3.2 Creating contexts
    - 4.3.3 Engravers explained
    - 4.3.4 Modifying context properties
    - 4.3.5 Adding and removing engravers
  - 4.4 Extending the templates
    - 4.4.1 Soprano and cello
    - 4.4.2 Four-part SATB vocal score
    - 4.4.3 Building a score from scratch
    - 4.4.4 Saving typing with variables and functions
    - 4.4.5 Scores and parts
- 5 Tweaking output
  - 5.1 Tweaking basics
    - 5.1.1 Objects and interfaces
    - 5.1.2 Naming conventions of objects and properties
    - 5.1.3 Tweaking methods
      - The `\override` command
      - The `\revert` command
      - The `\once` prefix
      - The `\tweak` and `\offset` commands
      - The `\single` prefix
  - 5.2 The Internals Reference manual
    - 5.2.1 Properties of layout objects
    - 5.2.2 Properties found in interfaces
    - 5.2.3 Types of properties
  - 5.3 Appearance of objects
    - 5.3.1 Visibility and color of objects
      - The `stencil` property
      - The `break-visibility` property
      - The `transparent` property
      - The `color` property
    - 5.3.2 Size of objects
    - 5.3.3 Length and thickness of objects
  - 5.4 Offsets and alignments
  - 5.5 Placement of objects
    - 5.5.1 Automatic behavior
    - 5.5.2 Within-staff objects
      - The `direction` property
      - Fingering
    - 5.5.3 Outside-staff objects
      - The `outside-staff-priority` property
      - The `\textLengthOn` command
      - Dynamics placement
      - Grob sizing
  - 5.6 Vertical spacing
  - 5.7 Collisions of objects
    - 5.7.1 Moving objects
    - 5.7.2 Fixing overlapping notation
      - The `padding` property
      - The `right-padding` property
      - The `staff-padding` property
      - The `self-alignment-X` property
      - The `staff-position` property
      - The `extra-offset` property
      - The `positions` property
      - The `force-hshift` property
    - 5.7.3 Real music example
  - 5.8 Further tweaking
    - 5.8.1 Other uses for tweaks
      - Tying notes across voices
      - Simulating a fermata in MIDI
    - 5.8.2 Using variables for layout adjustments
    - 5.8.3 Style sheets
    - 5.8.4 Other sources of information
    - 5.8.5 Advanced tweaks with Scheme
- Appendix A Templates
  - A.1 Built-in templates
    - A.1.1 SATB template
    - A.1.2 SSAATTBB template
  - A.2 Single staff templates
    - A.2.1 Notes only
    - A.2.2 Notes and lyrics
    - A.2.3 Notes and chords
    - A.2.4 Notes, lyrics, and chords
  - A.3 Piano templates
    - A.3.1 Solo piano
    - A.3.2 Piano and melody with lyrics
    - A.3.3 Piano-centered lyrics
  - A.4 String quartet templates
    - A.4.1 String quartet
    - A.4.2 String quartet parts
  - A.5 Vocal ensembles templates
    - A.5.1 SATB vocal score
    - A.5.2 SATB vocal score and automatic piano reduction
    - A.5.3 SATB with aligned contexts
    - A.5.4 SATB on four staves
    - A.5.5 Solo verse and two-part refrain
    - A.5.6 Hymn tunes
    - A.5.7 Psalms
  - A.6 Orchestral templates
    - A.6.1 Orchestra, choir and piano
  - A.7 Ancient notation templates
    - A.7.1 Transcription of mensural music
    - A.7.2 Gregorian transcription template
  - A.8 Other templates
    - A.8.1 Jazz combo
- Appendix B GNU Free Documentation License
- Appendix C Index