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