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