]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/simultaneous.itely
Issue 5114/4: Document \voices
[lilypond.git] / Documentation / notation / simultaneous.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @ignore
3     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
4
5     When revising a translation, copy the HEAD committish of the
6     version that you are working on.  For details, see the Contributors'
7     Guide, node Updating translation committishes..
8 @end ignore
9
10 @c \version "2.19.29"
11
12
13 @node Simultaneous notes
14 @section Simultaneous notes
15
16 @lilypondfile[quote,ragged-right,line-width=16\cm]{simultaneous-headword.ly}
17
18 Polyphony in music refers to having more than one voice occurring
19 in a piece of music.  Polyphony in LilyPond refers to having more
20 than one voice on the same staff.
21
22 @menu
23 * Single voice::
24 * Multiple voices::
25 @end menu
26
27
28 @node Single voice
29 @subsection Single voice
30
31 This section discusses simultaneous notes inside the same voice.
32
33 @menu
34 * Chorded notes::
35 * Chord repetition::
36 * Simultaneous expressions::
37 * Clusters::
38 @end menu
39
40
41 @node Chorded notes
42 @unnumberedsubsubsec Chorded notes
43
44 @cindex chords
45 @cindex brackets, angle
46
47 @funindex <
48 @funindex >
49 @funindex <...>
50
51 A chord is formed by enclosing a set of pitches between @code{<}
52 and @code{>}.  A chord may be followed by a duration just like simple
53 notes.
54
55 @lilypond[verbatim,quote]
56 \relative {
57   <a' c e>1 <a c e>2 <f a c e>4 <a c>8. <g c e>16
58 }
59 @end lilypond
60
61 Chords may also be followed by articulations, again just like simple
62 notes.
63
64 @lilypond[verbatim,quote]
65 \relative {
66   <a' c e>1\fermata <a c e>2-> <f a c e>4\prall <a c>8.^! <g c e>16-.
67 }
68 @end lilypond
69
70 The notes within the chord themselves can also be followed by articulation
71 and ornamentation.
72
73 @lilypond[verbatim,quote]
74 \relative {
75   <a' c\prall e>1 <a-> c-^ e>2 <f-. a c-. e-.>4
76   <a-+ c-->8. <g\fermata c e\turn>16
77 }
78 @end lilypond
79
80 However some notation, such as dynamics and hairpins must be
81 attached to the chord rather than to notes within the chord,
82 otherwise they will not print.  Other notation like fingerings and
83 slurs will get placed markedly different when attached to notes
84 within a chord rather than to whole chords or single notes.
85
86 @lilypond[verbatim,quote]
87 \relative {
88   <a'\f c( e>1 <a c) e>\f <a\< c e>( <a\! c e>)
89   <a c e>\< <a c e> <a c e>\!
90 }
91 @end lilypond
92
93 @cindex chords, empty
94 @cindex placeholder events
95
96 A chord acts merely as a container for its notes, its articulations and
97 other attached elements.  Consequently, a chord without notes inside
98 does not actually have a duration.  Any attached articulations will
99 happen at the same musical time as the next following note or chord and
100 be combined with them (for more complex possibilities of combining such
101 elements, see @ref{Simultaneous expressions}):
102
103 @lilypond[verbatim,quote]
104 \relative {
105   \grace { g'8( a b }
106   <> ) \p \< -. -\markup \italic "sempre staccato"
107   \repeat unfold 4 { c4 e }  c1\f
108 }
109 @end lilypond
110
111 @cindex relative pitch, chords
112 @cindex chords, relative pitch
113
114 Relative mode can be used for pitches in chords.  The first note of
115 each chord is always relative to the first note of the chord that
116 came before it, or in the case where no preceding chord exists, the
117 pitch of the last note that came before the chord.  All remaining notes
118 in the chord are relative to the note that came before it
119 @emph{within the same chord}.
120
121 @lilypond[verbatim,quote]
122 \relative {
123   <a' c e>1 <f a c> <a c e> <f' a c> <b, e b,>
124 }
125 @end lilypond
126
127 For more information about chords, see @ref{Chord notation}.
128
129 @seealso
130 Music Glossary:
131 @rglos{chord}.
132
133 Learning Manual:
134 @rlearning{Combining notes into chords}.
135
136 Notation Reference:
137 @ref{Chord notation},
138 @ref{Articulations and ornamentations},
139 @ref{Relative octave entry},
140 @ref{Multiple voices}.
141
142 Snippets:
143 @rlsr{Simultaneous notes}.
144
145 @knownissues
146 Chords containing more than two pitches within a staff space,
147 such as @samp{<e f! fis!>}, create overlapping noteheads.
148 Depending on the situation, better representations might involve
149
150 @itemize
151
152 @item
153 temporary use of @ref{Multiple voices},
154 @samp{<< f! \\ <e fis!> >>},
155
156 @item
157 enharmonic transcription of one or more pitches,
158 @samp{<e f ges>}, or
159
160 @item
161 @ref{Clusters}.
162
163 @end itemize
164
165
166 @node Chord repetition
167 @unnumberedsubsubsec Chord repetition
168
169 @cindex chord, repetition
170 @cindex repetition, using @code{q}
171 @cindex @code{q}, chord repetition
172
173 In order to save typing, a shortcut can be used to repeat the preceding
174 chord.  The chord repetition symbol is @code{q}:
175
176 @lilypond[verbatim,quote]
177 \relative {
178   <a' c e>1 q <f a c>2 q
179 }
180 @end lilypond
181
182 As with regular chords, the chord repetition symbol can be used with
183 durations, articulations, markups, slurs, beams, etc., as only the
184 pitches of the previous chord are duplicated.
185
186 @lilypond[verbatim,quote]
187 \relative {
188   <a' c e>1\p^"text" q2\<( q8)[-! q8.]\! q16-1-2-3 q8\prall
189 }
190 @end lilypond
191
192 The chord repetition symbol always remembers the last instance of
193 a chord so it is possible to repeat the most recent chord even if
194 other non-chorded notes or rests have been added since.
195
196 @lilypond[verbatim,quote]
197 \relative {
198   <a' c e>1 c'4 q2 r8 q8 |
199   q2 c, |
200 }
201 @end lilypond
202
203 However, the chord repetition symbol does not retain any dynamics,
204 articulation or ornamentation within, or attached to, the previous
205 chord.
206
207 @lilypond[verbatim,quote]
208 \relative {
209   <a'-. c\prall e>1\sfz c'4 q2 r8 q8 |
210   q2 c, |
211 }
212 @end lilypond
213
214 To have some of them retained, the @code{\chordRepeats} function can be
215 be called explicitly with an extra argument specifying a list of
216 @var{event types} to keep unless events of that type are already
217 present on the @code{q} chord itself.
218
219 @lilypond[verbatim,quote]
220 \relative {
221   \chordRepeats #'(articulation-event)
222   { <a'-. c\prall e>1\sfz c'4 q2 r8 q8-. } |
223   q2 c, |
224 }
225 @end lilypond
226
227 Here using @code{\chordRepeats} inside of a @code{\relative} construction
228 produces unexpected results: once chord events have been expanded, they
229 are indistinguishable from having been entered as regular chords, making
230 @code{\relative} assign an octave based on their current context.
231
232 Since nested instances of @code{\relative} don't affect one another,
233 another @code{\relative} inside of @code{\chordRepeats} can be used for
234 establishing the octave relations before expanding the repeat chords.
235 In that case, the whole content of the inner @code{\relative} does not
236 affect the outer one; hence the different octave entry of the final note
237 in this example.
238
239 @lilypond[verbatim,quote]
240 \relative {
241   \chordRepeats #'(articulation-event)
242   \relative
243   { <a'-. c\prall e>1\sfz c'4 q2 r8 q8-. } |
244   q2 c'' |
245 }
246 @end lilypond
247
248 Interactions with @code{\relative} occur only with explicit calls of
249 @code{\chordRepeats}: the implicit expansion at the start of typesetting
250 is done at a time where all instances of @code{\relative} have already
251 been processed.
252
253 @seealso
254 Notation Reference:
255 @ref{Chord notation},
256 @ref{Articulations and ornamentations}.
257
258 Installed Files:
259 @file{ly/chord-repetition-init.ly}.
260
261
262 @node Simultaneous expressions
263 @unnumberedsubsubsec Simultaneous expressions
264
265 One or more music expressions enclosed in double angle brackets are
266 taken to be simultaneous.  If the first expression begins with a
267 single note or if the whole simultaneous expression appears
268 explicitly within a single voice, the whole expression is placed on
269 a single staff; otherwise the elements of the simultaneous
270 expression are placed on separate staves.
271
272 The following examples show simultaneous expressions on one staff:
273
274 @lilypond[quote,verbatim]
275 \new Voice {  % explicit single voice
276   << \relative { a'4 b g2 }
277      \relative { d'4 g c,2 } >>
278 }
279 @end lilypond
280
281 @lilypond[quote,verbatim]
282 \relative {
283   % single first note
284   a' << \relative { a'4 b g }
285        \relative { d'4 g c, } >>
286 }
287 @end lilypond
288
289 This can be useful if the simultaneous sections have identical
290 rhythms, but attempts to attach notes with different durations to
291 the same stem will cause errors.  Notes, articulations, and property
292 changes in a @emph{single} @samp{Voice} are collected and engraved in
293 musical order:
294
295 @lilypond[quote,verbatim]
296 \relative {
297   <a' c>4-.  <>-. << c a >>  << { c-. <c a> } { a s-. } >>
298 }
299 @end lilypond
300
301 Multiple stems or beams or different note durations or properties at
302 the same musical time require the use of multiple voices.
303
304 The following example shows how simultaneous expressions can
305 generate multiple staves implicitly:
306
307 @lilypond[quote,verbatim]
308 % no single first note
309 << \relative { a'4 b g2 }
310    \relative { d'4 g2 c,4 } >>
311 @end lilypond
312
313 Here different rhythms cause no problems because they are
314 interpreted in different voices.
315
316 @cindex collisions, ignoring
317
318 @knownissues
319 If notes from two or more voices, with no shifts specified,
320 have stems in the same direction, the message
321
322 @example
323 warning: This voice needs a \voiceXx or \shiftXx setting
324 @end example
325
326 will appear during compilation.  This message can be suppressed by:
327
328 @example
329 \override NoteColumn.ignore-collision = ##t
330 @end example
331
332 However, this not only suppresses the warning but will prevent any
333 collision resolution whatsover and may have other unintended effects
334 (also see @emph{Known Issues} in @ref{Collision resolution}).
335
336
337 @node Clusters
338 @unnumberedsubsubsec Clusters
339
340 @cindex cluster
341 @cindex note cluster
342
343 @funindex \makeClusters
344
345 A cluster indicates a continuous range of pitches to be played.
346 They can be denoted as the envelope of a set of notes.  They are
347 entered by applying the function @code{\makeClusters} to a sequence
348 of chords, e.g.,
349
350 @lilypond[quote,verbatim]
351 \relative \makeClusters { <g' b>2 <c g'> }
352 @end lilypond
353
354 Ordinary notes and clusters can be put together in the same staff,
355 even simultaneously.  In such a case no attempt is made to
356 automatically avoid collisions between ordinary notes and clusters.
357
358 @seealso
359 Music Glossary:
360 @rglos{cluster}.
361
362 Snippets:
363 @rlsr{Simultaneous notes}.
364
365 Internals Reference:
366 @rinternals{ClusterSpanner},
367 @rinternals{ClusterSpannerBeacon},
368 @rinternals{Cluster_spanner_engraver}.
369
370 @knownissues
371 Clusters look good only if they span at least two chords; otherwise
372 they appear too narrow.
373
374 Clusters do not have a stem and cannot indicate durations by
375 themselves, but the length of the printed cluster is determined by
376 the durations of the defining chords.  Separate clusters need a
377 separating rest between them.
378
379 Clusters do not produce MIDI output.
380
381
382 @node Multiple voices
383 @subsection Multiple voices
384
385 This section discusses simultaneous notes in multiple voices or
386 multiple staves.
387
388 @menu
389 * Single-staff polyphony::
390 * Voice styles::
391 * Collision resolution::
392 * Automatic part combining::
393 * Writing music in parallel::
394 @end menu
395
396
397 @node Single-staff polyphony
398 @unnumberedsubsubsec Single-staff polyphony
399
400 @cindex single-staff polyphony
401 @cindex polyphony, single-staff
402 @cindex voice
403 @cindex lyrics assigned to one voice
404
405 @funindex \voiceOne
406 @funindex \voiceOne ... \voiceFour
407 @funindex Voice
408 @funindex \oneVoice
409
410 @subsubsubheading Explicitly instantiating voices
411
412 The basic structure needed to achieve multiple independent
413 voices in a single staff is illustrated in the following example:
414
415 @lilypond[quote,verbatim]
416 \new Staff <<
417   \new Voice = "first"
418     \relative { \voiceOne r8 r16 g'' e8. f16 g8[ c,] f e16 d }
419   \new Voice= "second"
420     \relative { \voiceTwo d''16 c d8~ 16 b c8~ 16 b c8~ 16 b8. }
421 >>
422 @end lilypond
423
424 @noindent
425 Here, voices are instantiated explicitly and are given names.  The
426 @code{\voiceOne} @dots{} @code{\voiceFour} commands set up the voices
427 so that first and third voices get stems up, second and fourth
428 voices get stems down, third and fourth voice note heads are
429 horizontally shifted, and rests in the respective voices are
430 automatically moved to avoid collisions.  The @code{\oneVoice}
431 command returns all the voice settings to the neutral default
432 directions.
433
434 @subsubsubheading Temporary polyphonic passages
435
436 A temporary polyphonic passage can be created with the following
437 construct:
438
439 @example
440 << @{ \voiceOne @dots{} @}
441   \new Voice @{ \voiceTwo @dots{} @}
442 >> \oneVoice
443 @end example
444
445 @noindent
446 Here, the first expression within a temporary polyphonic passage is
447 placed into the @code{Voice} context which was in use immediately
448 before the polyphonic passage, and that same @code{Voice} context
449 continues after the temporary section.  Other expressions within
450 the angle brackets are assigned to distinct temporary voices.
451 This allows lyrics to be assigned to one continuing voice before,
452 during and after a polyphonic section:
453
454 @lilypond[quote,verbatim]
455 \relative <<
456   \new Voice = "melody" {
457     a'4
458     <<
459       {
460         \voiceOne
461         g f
462       }
463       \new Voice {
464         \voiceTwo
465         d2
466       }
467     >>
468     \oneVoice
469     e4
470   }
471   \new Lyrics \lyricsto "melody" {
472   This is my song.
473   }
474 >>
475 @end lilypond
476
477 @noindent
478 Here, the @code{\voiceOne} and @code{\voiceTwo} commands are
479 required to define the settings of each voice.
480
481 @subsubsubheading The double backslash construct
482
483 The @code{<< @{@dots{}@} \\ @{@dots{}@} >>} construct, where the two (or
484 more) expressions are separated by double backslashes, behaves
485 differently to the similar construct without the double backslashes:
486 @emph{all} the expressions within this construct are assigned
487 to new @code{Voice} contexts.  These new @code{Voice} contexts
488 are created implicitly and are given the fixed names @code{"1"},
489 @code{"2"}, etc.
490
491 The first example could be typeset as follows:
492
493 @lilypond[quote,verbatim]
494 <<
495   \relative { r8 r16 g'' e8. f16 g8[ c,] f e16 d }
496   \\
497   \relative { d''16 c d8~ 16 b c8~ 16 b c8~ 16 b8. }
498 >>
499 @end lilypond
500
501 This syntax can be used where it does not matter that temporary
502 voices are created and then discarded.  These implicitly created
503 voices are given the settings equivalent to the effect of the
504 @code{\voiceOne} @dots{} @code{\voiceFour} commands, in the order in
505 which they appear in the code.
506
507 In the following example, the intermediate voice has stems up,
508 therefore we enter it in the third place, so it becomes voice
509 three, which has the stems up as desired.  Spacer rests are
510 used to avoid printing doubled rests.
511
512 @lilypond[quote,verbatim]
513 <<
514   \relative { r8 g'' g  g g f16 ees f8 d }
515   \\
516   \relative { ees'8 r ees r d r d r }
517   \\
518   \relative { d''8 s c s bes s a s }
519 >>
520 @end lilypond
521
522 In all but the simplest works it is advisable to create explicit
523 @code{Voice} contexts as explained in @rlearning{Contexts and engravers} and
524 @rlearning{Explicitly instantiating voices}.
525
526 @subsubsubheading Voice order
527
528 When entering multiple voices in the input file, use the following
529 order:
530
531 @example
532 Voice 1: highest
533 Voice 2: lowest
534 Voice 3: second highest
535 Voice 4: second lowest
536 Voice 5: third highest
537 Voice 6: third lowest
538 etc.
539 @end example
540
541 Though this may seem counterintuitive, it simplifies the automatic
542 layout process.  Note that the odd-numbered voices are given
543 upstems, and the even-numbered voices are given downstems:
544
545 @lilypond[quote,verbatim]
546 \new Staff <<
547   \time 2/4
548   { f''2 }  % 1: highest
549   \\
550   { c'2  }  % 2: lowest
551   \\
552   { d''2 }  % 3: second-highest
553   \\
554   { e'2  }  % 4: second-lowest
555   \\
556   { b'2  }  % 5: third-highest
557   \\
558   { g'2  }  % 6: third-lowest
559 >>
560 @end lilypond
561
562 @funindex \voices
563 When a different voice entry order is desired, the command
564 @code{\voices} may be convenient:
565
566 @lilypond[quote,verbatim]
567 \new Staff \voices 1,3,5,6,4,2 <<
568   \time 2/4
569   { f''2 }  % 1: highest
570   \\
571   { d''2 }  % 3: second-highest
572   \\
573   { b'2  }  % 5: third-highest
574   \\
575   { g'2  }  % 6: third-lowest
576   \\
577   { e'2  }  % 4: second-lowest
578   \\
579   { c'2  }  % 2: lowest
580 >>
581 @end lilypond
582
583
584 @warning{Lyrics and spanners (such as slurs, ties, hairpins, etc.) cannot
585 be created @q{across} voices.}
586
587 @subsubsubheading Identical rhythms
588
589 In the special case that we want to typeset parallel pieces of music
590 that have the same rhythm, we can combine them into a single
591 @code{Voice} context, thus forming chords.  To achieve this, enclose
592 them in a simple simultaneous music construct within an explicit voice:
593
594 @lilypond[quote,verbatim]
595 \new Voice <<
596   \relative { e''4 f8 d e16 f g8 d4 }
597   \relative { c''4 d8 b c16 d e8 b4 }
598 >>
599 @end lilypond
600
601 This method leads to strange beamings and warnings if the pieces of
602 music do not have the same rhythm.
603
604
605 @predefined
606 @code{\voiceOne},
607 @code{\voiceTwo},
608 @code{\voiceThree},
609 @code{\voiceFour},
610 @code{\oneVoice}.
611 @endpredefined
612
613 @seealso
614 Learning Manual:
615 @rlearning{Voices contain music},
616 @rlearning{Explicitly instantiating voices}.
617
618 Notation Reference:
619 @ref{Percussion staves},
620 @ref{Invisible rests},
621 @ref{Stems}.
622
623 Snippets:
624 @rlsr{Simultaneous notes}.
625
626
627 @node Voice styles
628 @unnumberedsubsubsec Voice styles
629
630 @cindex voice styles
631 @cindex styles, voice
632 @cindex coloring voices
633 @funindex \voiceOneStyle
634 @funindex \voiceTwoStyle
635 @funindex \voiceThreeStyle
636 @funindex \voiceFourStyle
637 @funindex \voiceNeutralStyle
638
639 Voices may be given distinct colors and shapes, allowing them to be
640 easily identified:
641
642 @lilypond[quote,verbatim]
643 <<
644   \relative { \voiceOneStyle d''4 c2 b4 }
645   \\
646   \relative { \voiceTwoStyle e'2 e }
647   \\
648   \relative { \voiceThreeStyle b2. c4 }
649   \\
650   \relative { \voiceFourStyle g'2 g }
651 >>
652 @end lilypond
653
654 The @code{\voiceNeutralStyle} command is used to revert to the
655 standard presentation.
656
657
658 @predefined
659 @code{\voiceOneStyle},
660 @code{\voiceTwoStyle},
661 @code{\voiceThreeStyle},
662 @code{\voiceFourStyle},
663 @code{\voiceNeutralStyle}.
664 @endpredefined
665
666 @seealso
667 Learning Manual:
668 @rlearning{I'm hearing Voices},
669 @rlearning{Other sources of information}.
670
671 Snippets:
672 @rlsr{Simultaneous notes}.
673
674
675 @node Collision resolution
676 @unnumberedsubsubsec Collision resolution
677
678 @cindex merging notes
679 @cindex note collisions
680 @cindex collisions
681 @cindex shift note
682 @cindex multiple voices
683 @cindex voices, multiple
684 @cindex polyphonic music
685 @cindex shifting voices
686 @cindex voices, multiple
687 @cindex shift rest, automatic
688 @funindex \shiftOn
689 @funindex \shiftOnn
690 @funindex \shiftOnnn
691 @funindex \shiftOff
692 @funindex \mergeDifferentlyDottedOn
693 @funindex \mergeDifferentlyDottedOff
694 @funindex \mergeDifferentlyHeadedOn
695 @funindex \mergeDifferentlyHeadedOff
696
697 The note heads of notes in different voices with the same pitch,
698 same note head and opposite stem direction are automatically
699 merged, but notes with different note heads or the same stem
700 direction are not.  Rests opposite a stem in a different voice
701 are shifted vertically.  The following example shows three
702 different circumstances, on beats 1 and 3 in bar 1 and beat 1
703 in bar 2, where the automatic merging fails.
704
705 @lilypond[quote,verbatim]
706 <<
707   \relative {
708     c''8 d e d c d c4
709     g'2 fis
710   } \\
711   \relative {
712     c''2 c8. b16 c4
713     e,2 r
714   } \\
715   \relative {
716     \oneVoice
717     s1
718     e'8 a b c d2
719   }
720 >>
721 @end lilypond
722
723 Notes with different note heads may be merged as shown
724 below.  In this example the note heads on beat 1 of bar 1 are now merged:
725
726 @lilypond[quote,verbatim]
727 <<
728   \relative {
729     \mergeDifferentlyHeadedOn
730     c''8 d e d c d c4
731     g'2 fis
732   } \\
733   \relative {
734     c''2 c8. b16 c4
735     e,2 r
736   } \\
737   \relative {
738     \oneVoice
739     s1
740     e'8 a b c d2
741   }
742 >>
743 @end lilypond
744
745 Quarter and half notes are not merged in this way, since it would be difficult
746 to tell them apart.
747
748 Note heads with different dots as shown in beat 3 of bar 1 may be
749 also be merged:
750
751 @lilypond[quote,verbatim]
752 <<
753   \relative {
754     \mergeDifferentlyHeadedOn
755     \mergeDifferentlyDottedOn
756     c''8 d e d c d c4
757     g'2 fis
758   } \\
759   \relative {
760     c''2 c8. b16 c4
761     e,2 r
762   } \\
763   \relative {
764     \oneVoice
765     s1
766     e'8 a b c d2
767   }
768 >>
769 @end lilypond
770
771 The half note and eighth note at the start of the second measure
772 are incorrectly merged because the automatic merge cannot
773 successfully complete the merge when three or more notes line up in
774 the same note column, and in this case the merged note head is
775 incorrect.  To allow the merge to select the correct note head
776 a @code{\shift} must be applied to the note that should not be
777 merged.  Here, @code{\shiftOn} is applied to move the top
778 @notation{g} out of the column, and @code{\mergeDifferentlyHeadedOn}
779 then works properly.
780
781 @lilypond[quote,verbatim]
782 <<
783   \relative {
784     \mergeDifferentlyHeadedOn
785     \mergeDifferentlyDottedOn
786     c''8 d e d c d c4
787     \shiftOn
788     g'2 fis
789   } \\
790   \relative {
791     c''2 c8. b16 c4
792     e,2 r
793   } \\
794   \relative {
795     \oneVoice
796     s1
797     e'8 a b c d2
798   }
799 >>
800 @end lilypond
801
802 The @code{\shiftOn} command allows (but does not force) the notes
803 in a voice to be shifted.  When @code{\shiftOn} is applied to a
804 voice, a note or chord in that voice is shifted only if its stem
805 would otherwise collide with a stem from another voice, and only
806 if the colliding stems point in the same direction.  The
807 @code{\shiftOff} command prevents this type of shifting from
808 occurring.
809
810 By default, the outer voices (normally voices one and two) have
811 @code{\shiftOff} specified, while the inner voices (three and
812 above) have @code{\shiftOn} specified.  When a shift is applied,
813 voices with upstems (odd-numbered voices) are shifted to the
814 right, and voices with downstems (even-numbered voices) are
815 shifted to the left.
816
817 Here is an example to help you visualize how an abbreviated
818 polyphonic expression would be expanded internally.
819
820 @warning{Note that with three or more voices, the vertical order
821 of voices in your input file should not be the same as the
822 vertical order of voices on the staff!}
823
824 @lilypond[quote,verbatim]
825 \new Staff \relative {
826   %% abbreviated entry
827   <<
828     { f''2  }  % 1: highest
829     \\
830     { g,2 }  % 2: lowest
831     \\
832     { d'2 }  % 3: upper middle
833     \\
834     { b2  }  % 4: lower middle
835   >>
836   %% internal expansion of the above
837   <<
838     \new Voice = "1" { \voiceOne   \shiftOff f'2 }
839     \new Voice = "2" { \voiceTwo   \shiftOff g,2 }
840     \new Voice = "3" { \voiceThree \shiftOn  d'2 } % shifts right
841     \new Voice = "4" { \voiceFour  \shiftOn  b2  } % shifts left
842   >>
843 }
844 @end lilypond
845
846 Two additional commands, @code{\shiftOnn} and @code{\shiftOnnn}
847 provide further shift levels which may be specified temporarily to
848 resolve collisions in complex situations -- see
849 @rlearning{Real music example}.
850
851 Notes are only merged if they have opposing stem directions (as
852 they have, for example, in voices one and two by default or when
853 the stems are explicitly set in opposite directions).
854
855 @predefined
856 @code{\mergeDifferentlyDottedOn},
857 @code{\mergeDifferentlyDottedOff},
858 @code{\mergeDifferentlyHeadedOn},
859 @code{\mergeDifferentlyHeadedOff}.
860
861 @code{\shiftOn},
862 @code{\shiftOnn},
863 @code{\shiftOnnn},
864 @code{\shiftOff}.
865 @endpredefined
866
867 @snippets
868 @lilypondfile[verbatim,quote,texidoc,doctitle]
869 {additional-voices-to-avoid-collisions.ly}
870
871 @lilypondfile[verbatim,quote,texidoc,doctitle]
872 {forcing-horizontal-shift-of-notes.ly}
873
874 @seealso
875 Music Glossary:
876 @rglos{polyphony}.
877
878 Learning Manual:
879 @rlearning{Multiple notes at once},
880 @rlearning{Voices contain music},
881 @rlearning{Real music example}.
882
883 Snippets:
884 @rlsr{Simultaneous notes}.
885
886 Internals Reference:
887 @rinternals{NoteColumn},
888 @rinternals{NoteCollision},
889 @rinternals{RestCollision}.
890
891 @cindex collisions, ignoring
892
893 @knownissues
894 Using @code{\override NoteColumn.ignore-collision = ##t} will cause
895 differently headed notes in different voices to merge incorrectly.
896
897 @lilypond[quote,verbatim,fragment]
898 \mergeDifferentlyHeadedOn
899 << \relative { c'16 a' b a } \\ \relative { c'2 } >>
900 \override NoteColumn.ignore-collision = ##t
901 << \relative { c'16 a' b a } \\ \relative { c'2 } >>
902 @end lilypond
903
904 @ignore
905 @knownissues
906 @c TODO investigate! Sometimes it works, sometimes not. --FV
907 The requirements for successfully merging different note heads that
908 are at the same time differently dotted are not clear.
909 @end ignore
910
911
912 @node Automatic part combining
913 @unnumberedsubsubsec Automatic part combining
914
915 @cindex automatic part combining
916 @cindex part combiner
917 @cindex combining parts
918 @cindex a due part
919 @cindex solo part
920 @funindex \partcombine
921
922 Automatic part combining is used to merge two separate parts of music
923 onto a single staff. This can be especially helpful when typesetting
924 orchestral scores.  A single @code{Voice} is printed while the two parts
925 of music are the same, but in places where they differ, a second
926 @code{Voice} is printed.  Stem directions are set up & down accordingly
927 while Solo and @notation{a due} parts are also identified and marked
928 appropriately.
929
930 The syntax for automatic part combining is:
931
932 @example
933 \partcombine @var{musicexpr1} @var{musicexpr2}
934 @end example
935
936 The following example demonstrates the basic functionality, putting
937 parts on a single staff as polyphony and setting stem directions
938 accordingly.  The same variables are used for the independent parts and
939 the combined staff.
940
941 @lilypond[quote,verbatim]
942 instrumentOne = \relative {
943   c'4 d e f |
944   R1 |
945   d'4 c b a |
946   b4 g2 f4 |
947   e1 |
948 }
949
950 instrumentTwo = \relative {
951   R1 |
952   g'4 a b c |
953   d4 c b a |
954   g4 f( e) d |
955   e1 |
956 }
957
958 <<
959   \new Staff \instrumentOne
960   \new Staff \instrumentTwo
961   \new Staff \partcombine \instrumentOne \instrumentTwo
962 >>
963 @end lilypond
964
965 Both parts have identical notes in the third measure, so only one
966 instance of the notes is printed.  Stem, slur, and tie directions are
967 set automatically, depending on whether the parts are playing solo or in
968 unison.  When needed in polyphony situations, the first part (with
969 context called @code{one}) gets @qq{up} stems, while the second (called
970 @code{two}) always gets @qq{down} stems.  In solo situations, the first
971 and second parts get marked with @qq{Solo} and @qq{Solo II},
972 respectively.  The unison (@notation{a due}) parts are marked with the
973 text @qq{a2}.
974
975 By default, the partcombiner merges two notes of the same pitch as an
976 @notation{a due} note, combines notes with the same
977 rhythm less than a ninth apart as chords and separates notes more than
978 a ninth apart (or when the voices cross) into
979 separate voices.  This can be overridden with an optional argument of a pair
980 of numbers after the @code{\partcombine} command: the first specifies
981 the interval where notes start to be combined (the default is zero) and the
982 second where the notes are split into separate voices.  Setting the second
983 argument to zero means that the partcombiner splits notes with an interval of
984 a second or more, setting it to one splits notes of a third or more, and so on.
985
986 @lilypond[quote,verbatim]
987 instrumentOne = \relative {
988   a4 b c d |
989   e f g a |
990   b c d e |
991 }
992
993 instrumentTwo = \relative {
994   c'4 c c c |
995   c c c c |
996   c c c c |
997 }
998
999 <<
1000   \new Staff \partcombine \instrumentOne \instrumentTwo
1001   \new Staff \partcombine #'(2 . 3) \instrumentOne \instrumentTwo
1002 >>
1003 @end lilypond
1004
1005
1006 Both arguments to @code{\partcombine} will be interpreted as separate
1007 @code{Voice} contexts, so if the music is being specified in relative
1008 mode then @emph{both} parts must contain a @code{\relative} function,
1009 i.e.,
1010
1011 @example
1012 \partcombine
1013   \relative @dots{} @var{musicexpr1}
1014   \relative @dots{} @var{musicexpr2}
1015 @end example
1016
1017 @noindent
1018 A @code{\relative} section that encloses a @code{\partcombine} has no
1019 effect on the pitches of @code{@var{musicexpr1}} or
1020 @code{@var{musicexpr2}}.
1021
1022 @funindex \partcombineChords
1023 @funindex \partcombineApart
1024 @funindex \partcombineUnisono
1025 @funindex \partcombineSoloI
1026 @funindex \partcombineSoloII
1027 @funindex \partcombineAutomatic
1028
1029 In professional scores, voices are often kept apart from each other for
1030 long passages of music even if some of the notes are the same in both
1031 voices, and could just as easily be printed as unison. Combining notes
1032 into a chord, or showing one voice as solo is, therefore, not ideal as
1033 the @code{\partcombine} function considers each note separately. In this
1034 case the @code{\partcombine} function can be overridden with one of the
1035 following commands.  All of the commands may be preceded with
1036 @code{\once} in order to have them only apply to the next note in
1037 the music expression.
1038
1039 @itemize
1040 @item
1041 @code{\partcombineApart} keeps the
1042 notes as two separate voices, even if they can be combined into a chord
1043 or unison.
1044
1045 @item
1046 @code{\partcombineChords} combines the
1047 notes into a chord.
1048
1049 @item
1050 @code{\partcombineUnisono} combines
1051 both voices as @qq{unison}.
1052
1053 @item
1054 @code{\partcombineSoloI} prints only
1055 voice one, and marks it as a @qq{Solo}.
1056
1057 @item
1058 @code{\partcombineSoloII} prints only
1059 voice two and marks it as a @qq{Solo}.
1060
1061 @item
1062 @code{\partcombineAutomatic} ends
1063 the functions of the commands above, and reverts back to the standard
1064 @code{\partcombine} functionality.
1065 @end itemize
1066
1067 @lilypond[quote,verbatim]
1068 instrumentOne = \relative c' {
1069   \partcombineApart c2^"apart" e |
1070   \partcombineAutomatic e2^"auto" e |
1071   \partcombineChords e'2^"chord" e |
1072   \partcombineAutomatic c2^"auto" c |
1073   \partcombineApart c2^"apart" \once \partcombineChords e^"chord once" |
1074   c2 c |
1075 }
1076 instrumentTwo = \relative {
1077   c'2 c |
1078   e2 e |
1079   a,2 c |
1080   c2 c' |
1081   c2 c |
1082   c2 c |
1083 }
1084
1085 <<
1086   \new Staff { \instrumentOne }
1087   \new Staff { \instrumentTwo }
1088   \new Staff { \partcombine \instrumentOne \instrumentTwo }
1089 >>
1090 @end lilypond
1091
1092
1093 @subsubsubheading Using \partcombine with lyrics
1094
1095 @cindex \partcombine and lyrics
1096
1097 The @code{\partcombine} command is not designed to work with
1098 lyrics; if one of the voices is explicitly named in order to
1099 attach lyrics to it, the partcombiner will stop working.  However,
1100 this effect can be achieved using a @code{NullVoice} context.  See
1101 @ref{Polyphony with shared lyrics}.
1102
1103
1104 @snippets
1105
1106 @lilypondfile[verbatim,quote,texidoc,doctitle]
1107 {combining-two-parts-on-the-same-staff.ly}
1108
1109 @lilypondfile[verbatim,quote,texidoc,doctitle]
1110 {changing-partcombine-texts.ly}
1111
1112 @seealso
1113 Music Glossary:
1114 @rglos{a due},
1115 @rglos{part}.
1116
1117 Notation Reference:
1118 @ref{Writing parts}.
1119
1120 Snippets:
1121 @rlsr{Simultaneous notes}.
1122
1123 Internals Reference:
1124 @rinternals{PartCombineMusic},
1125 @rinternals{Voice}.
1126
1127 @knownissues
1128 All @code{\partcombine@dots{}} functions can only accept two voices.
1129
1130 @code{\partcombine@dots{}} functions cannot be placed inside a @code{\tuplet}
1131 or @code{\relative} block.
1132
1133 If @code{printPartCombineTexts} is set and the two voices play the same
1134 notes @qq{on and off}, in the same measure, the part combiner may
1135 typeset @code{a2} more than once in that measure.
1136
1137 @code{\partcombine} only knows when a note starts in a @code{Voice}; it
1138 cannot, for example, remember if a note in one @code{Voice} has already
1139 started when combining notes that have just started in the other
1140 @code{Voice}.  This can lead to a number of unexpected issues including
1141 @qq{Solo} or @qq{Unison} marks being printed incorrectly.
1142
1143 @code{\partcombine} keeps all spanners (slurs, ties, hairpins, etc.) in
1144 the same @code{Voice} so that if any such spanners start or end in a
1145 different @code{Voice}, they may not be printed properly or at all.
1146
1147 If the @code{\partcombine} function cannot combine both music
1148 expressions (i.e., when both voices have different durations), it will
1149 give the voices, internally, its own custom names: @code{one} and
1150 @code{two} respectively.  This means if there is any @qq{switch} to a
1151 differently named @code{Voice} context, the events in that differently
1152 named @code{Voice} will be ignored.
1153
1154 Refer also to @emph{Known issues and warnings} when using
1155 @code{\partcombine} with tablature in @ref{Default tablatures} and the
1156 @emph{Note} in @ref{Automatic beams} when using automatic beaming.
1157
1158
1159 @node Writing music in parallel
1160 @unnumberedsubsubsec Writing music in parallel
1161
1162 @cindex writing music in parallel
1163 @cindex interleaved music
1164 @cindex parallel music
1165 @funindex \parallelMusic
1166
1167 Music for multiple parts can be interleaved in input code.  The
1168 function @code{\parallelMusic} accepts a list with the names of a
1169 number of variables to be created, and a musical expression.  The
1170 content of alternate measures from the expression become the value
1171 of the respective variables, so you can use them afterwards to
1172 print the music.
1173
1174 @warning{Bar checks @code{|} must be used, and the measures must
1175 be of the same length.}
1176
1177 @lilypond[quote,verbatim]
1178 \parallelMusic #'(voiceA voiceB voiceC) {
1179   % Bar 1
1180   r8 g'16 c'' e'' g' c'' e'' r8 g'16 c'' e'' g' c'' e'' |
1181   r16 e'8.~   4              r16 e'8.~   4              |
1182   c'2                        c'2                        |
1183
1184   % Bar 2
1185   r8 a'16 d'' f'' a' d'' f'' r8 a'16 d'' f'' a' d'' f'' |
1186   r16 d'8.~   4              r16 d'8.~   4              |
1187   c'2                        c'2                        |
1188
1189 }
1190 \new StaffGroup <<
1191   \new Staff << \voiceA \\ \voiceB >>
1192   \new Staff { \clef bass \voiceC }
1193 >>
1194 @end lilypond
1195
1196 Relative mode may be used.  Note that the @code{\relative} command
1197 is not used inside @code{\parallelMusic} itself.  The notes are
1198 relative to the preceding note in the voice, not to the previous
1199 note in the input -- in other words, relative notes for
1200 @code{voiceA} ignore the notes in @code{voiceB}.
1201
1202 @lilypond[quote,verbatim]
1203 \parallelMusic #'(voiceA voiceB voiceC) {
1204   % Bar 1
1205   r8 g16 c e g, c e r8 g,16 c e g, c e  |
1206   r16 e8.~ 4        r16 e8.~  4         |
1207   c2                c                   |
1208
1209   % Bar 2
1210   r8 a,16 d f a, d f r8 a,16 d f a, d f |
1211   r16 d8.~  4        r16 d8.~  4        |
1212   c2                 c                  |
1213
1214  }
1215 \new StaffGroup <<
1216   \new Staff << \relative c'' \voiceA \\ \relative c' \voiceB >>
1217   \new Staff \relative c' { \clef bass \voiceC }
1218 >>
1219 @end lilypond
1220
1221 This works quite well for piano music.  This example maps four
1222 consecutive measures to four variables:
1223
1224 @lilypond[quote,verbatim]
1225 global = {
1226   \key g \major
1227   \time 2/4
1228 }
1229
1230 \parallelMusic #'(voiceA voiceB voiceC voiceD) {
1231   % Bar 1
1232   a8    b     c   d     |
1233   d4          e         |
1234   c16 d e fis d e fis g |
1235   a4          a         |
1236
1237   % Bar 2
1238   e8      fis  g     a   |
1239   fis4         g         |
1240   e16 fis g  a fis g a b |
1241   a4           a         |
1242
1243   % Bar 3 ...
1244 }
1245
1246 \score {
1247   \new PianoStaff <<
1248      \new Staff {
1249        \global
1250        <<
1251          \relative c'' \voiceA
1252          \\
1253          \relative c'  \voiceB
1254        >>
1255      }
1256      \new Staff {
1257        \global \clef bass
1258        <<
1259          \relative c \voiceC
1260          \\
1261          \relative c \voiceD
1262        >>
1263      }
1264   >>
1265 }
1266 @end lilypond
1267
1268 @seealso
1269 Learning Manual:
1270 @rlearning{Organizing pieces with variables}.
1271
1272 Snippets:
1273 @rlsr{Simultaneous notes}.