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