LilyPond Learning Manual: 3.2.2 Explicitly instantiating voices

### 3.2.2 Explicitly instantiating voices

Voice contexts can also be created manually inside a `<< >>` block to create polyphonic music, using `\voiceOne` ... `\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 c' {
>         << { e4 f g a } \\ { c,4 d e f } >>
>       }
>     }

is equivalent to

>     \new Staff <<
>       \new Voice = "1" { \voiceOne \relative c' { e4 f g a } }
>       \new Voice = "2" { \voiceTwo \relative c' { c4 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 c' {
>       % Default behavior or behavior after \oneVoice
>       c4 d8~ d e4( f | g4 a) b-> c |
>     }

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

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

Now let’s look at three 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 a more correct 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 c' {
>       \voiceOneStyle
>       % The following notes are monophonic
>       c16^( 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~ | c8 b16 a b8 g~ g2 |
>         }
>         % Initiate third voice
>         \new Voice {
>           % Set stems, etc, up
>           \voiceThree
>           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' {
>       c16^( d e f
>       <<
>         { g4 f e | d2 e) | }
>         \new Voice {
>           \voiceTwo
>           r8 e4 d c8~ |
>           <<
>             { c8 b16 a b8 g~ g2 | }
>             \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 spacing notes to step over sections where the voice is silent, as here:

>     \new Staff \relative c' <<
>       % Initiate first voice
>       \new Voice {
>         \voiceOne
>         c16^( d e f g4 f e | d2 e) |
>       }
>       % Initiate second voice
>       \new Voice {
>         % Set stems, etc, down
>         \voiceTwo
>         s4 r8 e4 d c8~ | c8 b16 a b8 g~ g2 |
>       }
>       % 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 which 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 “Too many clashing note columns” will be produced.

#### See also

Notation Reference: Multiple voices.

其它语言：česky, deutsch, español, français, magyar, italiano, 日本語, nederlands。

#### LilyPond — Learning Manual