4.2.2 Explicitly instantiating voices (LilyPond Learning Manual)

#### 4.2.2 Explicitly instantiating voices

Voice contexts can also be created manually inside a `<< >>` block to create polyphonic music, using `\voiceOne` to `\voiceFour` to indicate the required directions of stems, slurs, etc. In longer scores this method is clearer, as it permits the voices to be separated and to be given more descriptive names.

Specifically, the construct `<< \\ >>` which we used in the previous section:

    \new Staff {
      \relative {
        << { e'4 f g a } \\ { c,4 d e f } >>
      }
    }

is equivalent to

    \new Staff <<
      \new Voice = "1" { \voiceOne \relative { e'4 f g a } }
      \new Voice = "2" { \voiceTwo \relative { c'4 d e f } }
    >>

Both of the above would produce

The `\voiceXXX` commands set the direction of stems, slurs, ties, articulations, text annotations, augmentation dots of dotted notes, and fingerings. `\voiceOne` and `\voiceThree` make these objects point upwards, while `\voiceTwo` and `\voiceFour` make them point downwards. These commands also generate a horizontal shift for each voice when this is required to avoid clashes of note heads. The command `\oneVoice` reverts the settings back to the normal values for a single voice.

Let us see in some simple examples exactly what effect `\oneVoice`, `\voiceOne`, and `voiceTwo` have on markup, ties, slurs, and dynamics:

>     \relative {
>       % Default behavior or behavior after \oneVoice
>       c'4 d8~ 8 e4( f | g4 a) b-> c |
>     }

>     \relative {
>       \voiceOne
>       c'4 d8~ 8 e4( f | g4 a) b-> c |
>       \oneVoice
>       c,4 d8~ 8 e4( f | g4 a) b-> c |
>     }

>     \relative {
>       \voiceTwo
>       c'4 d8~ 8 e4( f | g4 a) b-> c |
>       \oneVoice
>       c,4 d8~ 8 e4( f | g4 a) b-> c |
>     }

Now let’s look at four different ways to notate the same passage of polyphonic music, each of which is advantageous in different circumstances, using the example from the previous section.

An expression that appears directly inside a `<< >>` belongs to the main voice (but, note, not in a `<< \\ >>` construct). This is useful when extra voices appear while the main voice is playing. Here is an improved rendition of our example. The red diamond-shaped notes demonstrate that the main melody is now in a single voice context, permitting a phrasing slur to be drawn over them.

>     \new Staff \relative {
>       \voiceOneStyle
>       % This section is homophonic
>       c'16^( d e f
>       % Start simultaneous section of three voices
>       <<
>         % Continue the main voice in parallel
>         { g4 f e | d2 e) | }
>         % Initiate second voice
>         \new Voice {
>           % Set stems, etc., down
>           \voiceTwo r8 e4 d c8~ | 8 b16 a b8 g~ 2 |
>         }
>         % Initiate third voice
>         \new Voice {
>           % Set stems, etc, up
>           \voiceThree s2. | s4 b c2 |
>         }
>       >>
>     }

The `\voices` command can also be used for continuing a main voice into the simultaneous construct:

>     \new Staff \relative {
>       \new Voice = "main" {
>         \voiceOneStyle
>         % This section is homophonic
>         c'16^( d e f
>         % Start simultaneous section of three voices
>         \voices "main",2,3
>         <<
>           % Continue the main voice in parallel
>           { g4 f e | d2 e) | }
>           % Initiate second voice
>         \\
>           % Set stems, etc., down
>           { r8 e4 d c8~ | 8 b16 a b8 g~ 2 | }
>         \\
>           % Initiate third voice
>           % Set stems, etc, up
>           { s2. | s4 b c2 | }
>         >>
>       }
>     }

More deeply nested polyphony constructs are possible, and if a voice appears only briefly this might be a more natural way to typeset the music:

>     \new Staff \relative {
>       c'16^( d e f
>       <<
>         { g4 f e | d2 e) | }
>         \new Voice {
>           \voiceTwo r8 e4 d c8~ |
>           <<
>             { c8 b16 a b8 g~ 2 | }
>             \new Voice {
>               \voiceThree s4 b c2 |
>             }
>           >>
>         }
>       >>
>     }

This method of nesting new voices briefly is useful when only small sections of the music are polyphonic, but when the whole staff is largely polyphonic it can be clearer to use multiple voices throughout, using spacer rests to step over sections where the voice is silent, as here:

>     \new Staff \relative <<
>       % Initiate first voice
>       \new Voice {
>         \voiceOne c'16^( d e f g4 f e | d2 e) |
>       }
>       % Initiate second voice
>       \new Voice {
>         % Set stems, etc, down
>         \voiceTwo s4 r8 e4 d c8~ | 8 b16 a b8 g~ 2 |
>       }
>       % Initiate third voice
>       \new Voice {
>         % Set stems, etc, up
>         \voiceThree s1 | s4 b c2 |
>       }
>     >>

#### Note columns

Closely spaced notes in a chord, or notes occurring at the same time in different voices, are arranged in two, occasionally more, columns to prevent the note heads overlapping. These are called note columns. There are separate columns for each voice, and the currently specified, voice-dependent shift is applied to the note column if there would otherwise be a collision. This can be seen in the example above. In bar 2 the C in voice two is shifted to the right relative to the D in voice one, and in the final chord the C in voice three is also shifted to the right relative to the other notes.

The `\shiftOn`, `\shiftOnn`, `\shiftOnnn`, and `\shiftOff` commands specify the degree to which notes and chords of the voice should be shifted if a collision would otherwise occur. By default, the outer voices (normally voices one and two) have `\shiftOff` specified, while the inner voices (three and four) have `\shiftOn` specified. When a shift is applied, voices one and three are shifted to the right and voices two and four to the left.

`\shiftOnn` and `\shiftOnnn` define further shift levels which may be specified temporarily to resolve collisions in complex situations – see Real music example.

A note column can contain just one note (or chord) from a voice with stems up and one note (or chord) from a voice with stems down. If notes from two voices that have their stems in the same direction are placed at the same position and both voices have no shift or the same shift specified, the error message “This voice needs a `\voiceXx` or `\shiftXx` setting” will be produced.

#### See also

Learning Manual: Moving objects.

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