]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/simultaneous.itely
Updates to NR chapter 1
[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.17.6"
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 @dots{} @}
418   \new Voice @{ \voiceTwo @dots{} @}
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{<< @{@dots{}@} \\ @{@dots{}@} >>} 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 as shown
685 below.  In this example the note heads on beat 1 of bar 1 are now merged:
686
687 @lilypond[quote,verbatim,relative=2]
688 <<
689   {
690     \mergeDifferentlyHeadedOn
691     c8 d e d c d c4
692     g'2 fis
693   } \\ {
694     c2 c8. b16 c4
695     e,2 r
696   } \\ {
697     \oneVoice
698     s1
699     e8 a b c d2
700   }
701 >>
702 @end lilypond
703
704 Quarter and half notes are not merged in this way, since it would be difficult
705 to tell them apart.
706
707 Note heads with different dots as shown in beat 3 of bar 1 may be
708 also be merged:
709
710 @lilypond[quote,relative=2,verbatim]
711 <<
712   {
713     \mergeDifferentlyHeadedOn
714     \mergeDifferentlyDottedOn
715     c8 d e d c d c4
716     g'2 fis
717   } \\ {
718     c2 c8. b16 c4
719     e,2 r
720   } \\ {
721     \oneVoice
722     s1
723     e8 a b c d2
724   }
725 >>
726 @end lilypond
727
728 The half note and eighth note at the start of the second measure
729 are incorrectly merged because the automatic merge cannot
730 successfully complete the merge when three or more notes line up in
731 the same note column, and in this case the merged note head is
732 incorrect.  To allow the merge to select the correct note head
733 a @code{\shift} must be applied to the note that should not be
734 merged.  Here, @code{\shiftOn} is applied to move the top
735 @notation{g} out of the column, and @code{\mergeDifferentlyHeadedOn}
736 then works properly.
737
738 @lilypond[quote,relative=2,verbatim]
739 <<
740   {
741     \mergeDifferentlyHeadedOn
742     \mergeDifferentlyDottedOn
743     c8 d e d c d c4
744     \shiftOn
745     g'2 fis
746   } \\ {
747     c2 c8. b16 c4
748     e,2 r
749   } \\ {
750     \oneVoice
751     s1
752     e8 a b c d2
753   }
754 >>
755 @end lilypond
756
757 The @code{\shiftOn} command allows (but does not force) the notes
758 in a voice to be shifted.  When @code{\shiftOn} is applied to a
759 voice, a note or chord in that voice is shifted only if its stem
760 would otherwise collide with a stem from another voice, and only
761 if the colliding stems point in the same direction.  The
762 @code{\shiftOff} command prevents this type of shifting from
763 occurring.
764
765 By default, the outer voices (normally voices one and two) have
766 @code{\shiftOff} specified, while the inner voices (three and
767 above) have @code{\shiftOn} specified.  When a shift is applied,
768 voices with upstems (odd-numbered voices) are shifted to the
769 right, and voices with downstems (even-numbered voices) are
770 shifted to the left.
771
772 Here is an example to help you visualize how an abbreviated
773 polyphonic expression would be expanded internally.
774
775 @warning{Note that with three or more voices, the vertical order
776 of voices in your input file should not be the same as the
777 vertical order of voices on the staff!}
778
779 @lilypond[quote,verbatim]
780 \new Staff \relative c'' {
781   %% abbreviated entry
782   <<
783     { f2  }  % 1: highest
784     \\
785     { g,2 }  % 2: lowest
786     \\
787     { d'2 }  % 3: upper middle
788     \\
789     { b2  }  % 4: lower middle
790   >>
791   %% internal expansion of the above
792   <<
793     \new Voice = "1" { \voiceOne   \shiftOff f'2 }
794     \new Voice = "2" { \voiceTwo   \shiftOff g,2 }
795     \new Voice = "3" { \voiceThree \shiftOn  d'2 } % shifts right
796     \new Voice = "4" { \voiceFour  \shiftOn  b2  } % shifts left
797   >>
798 }
799 @end lilypond
800
801 Two additional commands, @code{\shiftOnn} and @code{\shiftOnnn}
802 provide further shift levels which may be specified temporarily to
803 resolve collisions in complex situations -- see
804 @rlearning{Real music example}.
805
806 Notes are only merged if they have opposing stem directions (as
807 they have, for example, in voices one and two by default or when
808 the stems are explicitly set in opposite directions).
809
810 @predefined
811 @code{\mergeDifferentlyDottedOn},
812 @code{\mergeDifferentlyDottedOff},
813 @code{\mergeDifferentlyHeadedOn},
814 @code{\mergeDifferentlyHeadedOff}.
815
816 @code{\shiftOn},
817 @code{\shiftOnn},
818 @code{\shiftOnnn},
819 @code{\shiftOff}.
820 @endpredefined
821
822 @snippets
823 @lilypondfile[verbatim,quote,texidoc,doctitle]
824 {additional-voices-to-avoid-collisions.ly}
825
826 @lilypondfile[verbatim,quote,texidoc,doctitle]
827 {forcing-horizontal-shift-of-notes.ly}
828
829 @seealso
830 Music Glossary:
831 @rglos{polyphony}.
832
833 Learning Manual:
834 @rlearning{Multiple notes at once},
835 @rlearning{Voices contain music},
836 @rlearning{Real music example}.
837
838 Snippets:
839 @rlsr{Simultaneous notes}.
840
841 Internals Reference:
842 @rinternals{NoteColumn},
843 @rinternals{NoteCollision},
844 @rinternals{RestCollision}.
845
846 @cindex collisions, ignoring
847
848 @knownissues
849 Using @code{\override NoteColumn.ignore-collision = ##t} will cause
850 differently headed notes in different voices to merge incorrectly.
851
852 @lilypond[quote,relative=1,verbatim]
853 \mergeDifferentlyHeadedOn
854 << { c16 a' b a } \\ { c,2 } >>
855 \override NoteColumn.ignore-collision = ##t
856 << { c16 a' b a } \\ { c,2 } >>
857 @end lilypond
858
859 @ignore
860 @knownissues
861 @c TODO investigate! Sometimes it works, sometimes not. --FV
862 The requirements for successfully merging different note heads that
863 are at the same time differently dotted are not clear.
864 @end ignore
865
866
867 @node Automatic part combining
868 @unnumberedsubsubsec Automatic part combining
869
870 @cindex automatic part combining
871 @cindex part combiner
872 @cindex combining parts
873 @cindex a due part
874 @cindex solo part
875 @funindex \partcombine
876 @funindex partcombine
877
878 Automatic part combining is used to merge two separate parts of music
879 onto a single staff. This can be especially helpful when typesetting
880 orchestral scores.  A single @code{Voice} is printed while the two parts
881 of music are the same, but in places where they differ, a second
882 @code{Voice} is printed.  Stem directions are set up & down accordingly
883 while Solo and @notation{a due} parts are also identified and marked
884 appropriately.
885
886 The syntax for automatic part combining is:
887
888 @example
889 \partcombine @var{musicexpr1} @var{musicexpr2}
890 @end example
891
892 The following example demonstrates the basic functionality, putting
893 parts on a single staff as polyphony and setting stem directions
894 accordingly.  The same variables are used for the independent parts and
895 the combined staff.
896
897 @lilypond[quote,verbatim]
898 instrumentOne = \relative c' {
899   c4 d e f |
900   R1 |
901   d'4 c b a |
902   b4 g2 f4 |
903   e1 |
904 }
905
906 instrumentTwo = \relative g' {
907   R1 |
908   g4 a b c |
909   d4 c b a |
910   g4 f( e) d |
911   e1 |
912 }
913
914 <<
915   \new Staff \instrumentOne
916   \new Staff \instrumentTwo
917   \new Staff \partcombine \instrumentOne \instrumentTwo
918 >>
919 @end lilypond
920
921 Both parts have identical notes in the third measure, so only one
922 instance of the notes is printed.  Stem, slur, and tie directions are
923 set automatically, depending on whether the parts are playing solo or in
924 unison.  When needed in polyphony situations, the first part (with
925 context called @code{one}) gets @qq{up} stems, while the second (called
926 @code{two}) always gets @qq{down} stems.  In solo situations, the first
927 and second parts get marked with @qq{Solo} and @qq{Solo II},
928 respectively.  The unison (@notation{a due}) parts are marked with the
929 text @qq{a2}.
930
931 Both arguments to @code{\partcombine} will be interpreted as separate
932 @code{Voice} contexts, so if the music is being specified in relative
933 mode then @emph{both} parts must contain a @code{\relative} function,
934 i.e.,
935
936 @example
937 \partcombine
938   \relative @dots{} @var{musicexpr1}
939   \relative @dots{} @var{musicexpr2}
940 @end example
941
942 @noindent
943 A @code{\relative} section that encloses a @code{\partcombine} has no
944 effect on the pitches of @code{@var{musicexpr1}} or
945 @code{@var{musicexpr2}}.
946
947 @funindex \partcombineChords
948 @funindex partcombineChords
949 @funindex \partcombineApart
950 @funindex partcombineApart
951 @funindex \partcombineUnisono
952 @funindex partcombineUnisono
953 @funindex \partcombineSoloI
954 @funindex partcombineSoloI
955 @funindex \partcombineSoloII
956 @funindex partcombineSoloII
957 @funindex \partcombineAutomatic
958 @funindex partcombineAutomatic
959
960 In professional scores, voices are often kept apart from each other for
961 long passages of music even if some of the notes are the same in both
962 voices, and could just as easily be printed as unison. Combining notes
963 into a chord, or showing one voice as solo is, therefore, not ideal as
964 the @code{\partcombine} function considers each note separately. In this
965 case the @code{\partcombine} function can be overriden with the
966 following commands:
967
968 Commands ending in @code{@dots{}Once} apply only to the next note in the
969 music expression.
970
971 @itemize
972 @item
973 @code{\partcombineApart} and @code{\partcombineApartOnce} keep the
974 notes as two separate voices, even if they can be combined into a chord
975 or unison.
976
977 @item
978 @code{\partcombineChords} and @code{\partcombineChordsOnce} combine the
979 notes into a chord.
980
981 @item
982 @code{\partcombineUnisono} and @code{\partcombineUnisonoOnce} combine
983 both voices as @qq{unison}.
984
985 @item
986 @code{\partcombineSoloI} and @code{\partcombineSoloIOnce} print only
987 voice one, and mark it as a @qq{Solo}.
988
989 @item
990 @code{\partcombineSoloII} or @code{\partcombineSoloIIOnce} print only
991 voice two and mark it as a @qq{Solo}.
992
993 @item
994 @code{\partcombineAutomatic} and @code{\partcombineAutomaticOnce} end
995 the functions of the commands above, and revert back to the standard
996 @code{\partcombine} functionality.
997 @end itemize
998
999 @lilypond[quote,verbatim]
1000 instrumentOne = \relative c' {
1001   \partcombineApart c2^"apart" e |
1002   \partcombineAutomatic e2^"auto" e |
1003   \partcombineChords e'2^"chord" e |
1004   \partcombineAutomatic c2^"auto" c |
1005   \partcombineApart c2^"apart" \partcombineChordsOnce e^"chord once" |
1006   c2 c |
1007 }
1008 instrumentTwo = \relative c' {
1009   c2 c |
1010   e2 e |
1011   a,2 c |
1012   c2 c' |
1013   c2 c |
1014   c2 c |
1015 }
1016
1017 <<
1018   \new Staff { \instrumentOne }
1019   \new Staff { \instrumentTwo }
1020   \new Staff { \partcombine \instrumentOne \instrumentTwo }
1021 >>
1022 @end lilypond
1023
1024
1025 @snippets
1026
1027 @lilypondfile[verbatim,quote,texidoc,doctitle]
1028 {combining-two-parts-on-the-same-staff.ly}
1029
1030 @lilypondfile[verbatim,quote,texidoc,doctitle]
1031 {changing-partcombine-texts.ly}
1032
1033 @seealso
1034 Music Glossary:
1035 @rglos{a due},
1036 @rglos{part}.
1037
1038 Notation Reference:
1039 @ref{Writing parts}.
1040
1041 Snippets:
1042 @rlsr{Simultaneous notes}.
1043
1044 Internals Reference:
1045 @rinternals{PartCombineMusic},
1046 @rinternals{Voice}.
1047
1048 @knownissues
1049 All @code{\partcombine@dots{}} functions can only accept two voices and are
1050 not designed to work with lyrics; such that when one of the voices is
1051 explicitly named in order to attach lyrics to it, the partcombiner will
1052 stop working.
1053
1054 @code{\partcombine@dots{}} functions cannot be placed inside a @code{\tuplet}
1055 or @code{\relative} block.
1056
1057 If @code{printPartCombineTexts} is set and the two voices play the same
1058 notes @qq{on and off}, in the same measure, the part combiner may
1059 typeset @code{a2} more than once in that measure.
1060
1061 @code{\partcombine} only knows when a note starts in a @code{Voice}; it
1062 cannot, for example, remember if a note in one @code{Voice} has already
1063 started when combining notes that have just started in the other
1064 @code{Voice}.  This can lead to a number of unexpected issues including
1065 @qq{Solo} or @qq{Unison} marks being printed incorrectly.
1066
1067 @code{\partcombine} keeps all spanners (slurs, ties, hairpins etc.) in
1068 the same @code{Voice} so that if any such spanners start or end in a
1069 different @code{Voice}, they may not be printed properly or at all.
1070
1071 If the @code{\partcombine} function cannot combine both music
1072 expressions (i.e. when both voices have different durations), it will
1073 give the voices, internally, its own custom names: @code{one} and
1074 @code{two} respectively.  This means if there is any @qq{switch} to a
1075 differently named @code{Voice} context, the events in that differently
1076 named @code{Voice} will be ignored.
1077
1078 Refer also to @emph{Known issues and warnings} when using
1079 @code{\partcombine} with tablature in @ref{Default tablatures} and the
1080 @emph{Note} in @ref{Automatic beams} when using automatic beaming.
1081
1082
1083 @node Writing music in parallel
1084 @unnumberedsubsubsec Writing music in parallel
1085
1086 @cindex writing music in parallel
1087 @cindex interleaved music
1088 @cindex parallel music
1089 @funindex \parallelMusic
1090 @funindex parallelMusic
1091
1092 Music for multiple parts can be interleaved in input code.  The
1093 function @code{\parallelMusic} accepts a list with the names of a
1094 number of variables to be created, and a musical expression.  The
1095 content of alternate measures from the expression become the value
1096 of the respective variables, so you can use them afterwards to
1097 print the music.
1098
1099 @warning{Bar checks @code{|} must be used, and the measures must
1100 be of the same length.}
1101
1102 @lilypond[quote,verbatim]
1103 \parallelMusic #'(voiceA voiceB voiceC) {
1104   % Bar 1
1105   r8 g'16 c'' e'' g' c'' e'' r8 g'16 c'' e'' g' c'' e'' |
1106   r16 e'8.~   e'4            r16 e'8.~   e'4            |
1107   c'2                        c'2                        |
1108
1109   % Bar 2
1110   r8 a'16 d'' f'' a' d'' f'' r8 a'16 d'' f'' a' d'' f'' |
1111   r16 d'8.~   d'4            r16 d'8.~   d'4            |
1112   c'2                        c'2                        |
1113
1114 }
1115 \new StaffGroup <<
1116   \new Staff << \voiceA \\ \voiceB >>
1117   \new Staff { \clef bass \voiceC }
1118 >>
1119 @end lilypond
1120
1121 Relative mode may be used.  Note that the @code{\relative} command
1122 is not used inside @code{\parallelMusic} itself.  The notes are
1123 relative to the preceding note in the voice, not to the previous
1124 note in the input -- in other words, relative notes for
1125 @code{voiceA} ignore the notes in @code{voiceB}.
1126
1127 @lilypond[quote,verbatim]
1128 \parallelMusic #'(voiceA voiceB voiceC) {
1129   % Bar 1
1130   r8 g16 c e g, c e r8 g,16 c e g, c e  |
1131   r16 e8.~ e4       r16 e8.~  e4        |
1132   c2                c                   |
1133
1134   % Bar 2
1135   r8 a,16 d f a, d f r8 a,16 d f a, d f |
1136   r16 d8.~  d4       r16 d8.~  d4       |
1137   c2                 c                  |
1138
1139  }
1140 \new StaffGroup <<
1141   \new Staff << \relative c'' \voiceA \\ \relative c' \voiceB >>
1142   \new Staff \relative c' { \clef bass \voiceC }
1143 >>
1144 @end lilypond
1145
1146 This works quite well for piano music.  This example maps four
1147 consecutive measures to four variables:
1148
1149 @lilypond[quote,verbatim]
1150 global = {
1151   \key g \major
1152   \time 2/4
1153 }
1154
1155 \parallelMusic #'(voiceA voiceB voiceC voiceD) {
1156   % Bar 1
1157   a8    b     c   d     |
1158   d4          e         |
1159   c16 d e fis d e fis g |
1160   a4          a         |
1161
1162   % Bar 2
1163   e8      fis  g     a   |
1164   fis4         g         |
1165   e16 fis g  a fis g a b |
1166   a4           a         |
1167
1168   % Bar 3 ...
1169 }
1170
1171 \score {
1172   \new PianoStaff <<
1173      \new Staff {
1174        \global
1175        <<
1176          \relative c'' \voiceA
1177          \\
1178          \relative c'  \voiceB
1179        >>
1180      }
1181      \new Staff {
1182        \global \clef bass
1183        <<
1184          \relative c \voiceC
1185          \\
1186          \relative c \voiceD
1187        >>
1188      }
1189   >>
1190 }
1191 @end lilypond
1192
1193 @seealso
1194 Learning Manual:
1195 @rlearning{Organizing pieces with variables}.
1196
1197 Snippets:
1198 @rlsr{Simultaneous notes}.