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