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