]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/simultaneous.itely
Create engravers for merging rests
[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
345 A cluster indicates a continuous range of pitches to be played.
346 They can be denoted as the envelope of a set of notes.  They are
347 entered by applying the function @code{\makeClusters} to a sequence
348 of chords, e.g.,
349
350 @lilypond[quote,verbatim]
351 \relative \makeClusters { <g' b>2 <c g'> }
352 @end lilypond
353
354 Ordinary notes and clusters can be put together in the same staff,
355 even simultaneously.  In such a case no attempt is made to
356 automatically avoid collisions between ordinary notes and clusters.
357
358 @seealso
359 Music Glossary:
360 @rglos{cluster}.
361
362 Snippets:
363 @rlsr{Simultaneous notes}.
364
365 Internals Reference:
366 @rinternals{ClusterSpanner},
367 @rinternals{ClusterSpannerBeacon},
368 @rinternals{Cluster_spanner_engraver}.
369
370 @knownissues
371 Clusters look good only if they span at least two chords; otherwise
372 they appear too narrow.
373
374 Clusters do not have a stem and cannot indicate durations by
375 themselves, but the length of the printed cluster is determined by
376 the durations of the defining chords.  Separate clusters need a
377 separating rest between them.
378
379 Clusters do not produce MIDI output.
380
381
382 @node Multiple voices
383 @subsection Multiple voices
384
385 This section discusses simultaneous notes in multiple voices or
386 multiple staves.
387
388 @menu
389 * Single-staff polyphony::
390 * Voice styles::
391 * Collision resolution::
392 * Merging rests::
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 ... \voiceFour
408 @funindex Voice
409 @funindex \oneVoice
410
411 @subsubsubheading Explicitly instantiating voices
412
413 The basic structure needed to achieve multiple independent
414 voices in a single staff is illustrated in the following example:
415
416 @lilypond[quote,verbatim]
417 \new Staff <<
418   \new Voice = "first"
419     \relative { \voiceOne r8 r16 g'' e8. f16 g8[ c,] f e16 d }
420   \new Voice= "second"
421     \relative { \voiceTwo d''16 c d8~ 16 b c8~ 16 b c8~ 16 b8. }
422 >>
423 @end lilypond
424
425 @noindent
426 Here, voices are instantiated explicitly and are given names.  The
427 @code{\voiceOne} @dots{} @code{\voiceFour} commands set up the voices
428 so that first and third voices get stems up, second and fourth
429 voices get stems down, third and fourth voice note heads are
430 horizontally shifted, and rests in the respective voices are
431 automatically moved to avoid collisions.  The @code{\oneVoice}
432 command returns all the voice settings to the neutral default
433 directions.
434
435 @subsubsubheading Temporary polyphonic passages
436
437 A temporary polyphonic passage can be created with the following
438 construct:
439
440 @example
441 << @{ \voiceOne @dots{} @}
442   \new Voice @{ \voiceTwo @dots{} @}
443 >> \oneVoice
444 @end example
445
446 @noindent
447 Here, the first expression within a temporary polyphonic passage is
448 placed into the @code{Voice} context which was in use immediately
449 before the polyphonic passage, and that same @code{Voice} context
450 continues after the temporary section.  Other expressions within
451 the angle brackets are assigned to distinct temporary voices.
452 This allows lyrics to be assigned to one continuing voice before,
453 during and after a polyphonic section:
454
455 @lilypond[quote,verbatim]
456 \relative <<
457   \new Voice = "melody" {
458     a'4
459     <<
460       {
461         \voiceOne
462         g f
463       }
464       \new Voice {
465         \voiceTwo
466         d2
467       }
468     >>
469     \oneVoice
470     e4
471   }
472   \new Lyrics \lyricsto "melody" {
473   This is my song.
474   }
475 >>
476 @end lilypond
477
478 @noindent
479 Here, the @code{\voiceOne} and @code{\voiceTwo} commands are
480 required to define the settings of each voice.
481
482 @subsubsubheading The double backslash construct
483
484 The @code{<< @{@dots{}@} \\ @{@dots{}@} >>} construct, where the two (or
485 more) expressions are separated by double backslashes, behaves
486 differently to the similar construct without the double backslashes:
487 @emph{all} the expressions within this construct are assigned
488 to new @code{Voice} contexts.  These new @code{Voice} contexts
489 are created implicitly and are given the fixed names @code{"1"},
490 @code{"2"}, etc.
491
492 The first example could be typeset as follows:
493
494 @lilypond[quote,verbatim]
495 <<
496   \relative { r8 r16 g'' e8. f16 g8[ c,] f e16 d }
497   \\
498   \relative { d''16 c d8~ 16 b c8~ 16 b c8~ 16 b8. }
499 >>
500 @end lilypond
501
502 This syntax can be used where it does not matter that temporary
503 voices are created and then discarded.  These implicitly created
504 voices are given the settings equivalent to the effect of the
505 @code{\voiceOne} @dots{} @code{\voiceFour} commands, in the order in
506 which they appear in the code.
507
508 In the following example, the intermediate voice has stems up,
509 therefore we enter it in the third place, so it becomes voice
510 three, which has the stems up as desired.  Spacer rests are
511 used to avoid printing doubled rests.
512
513 @lilypond[quote,verbatim]
514 <<
515   \relative { r8 g'' g  g g f16 ees f8 d }
516   \\
517   \relative { ees'8 r ees r d r d r }
518   \\
519   \relative { d''8 s c s bes s a s }
520 >>
521 @end lilypond
522
523 In all but the simplest works it is advisable to create explicit
524 @code{Voice} contexts as explained in @rlearning{Contexts and engravers} and
525 @rlearning{Explicitly instantiating voices}.
526
527 @subsubsubheading Voice order
528
529 When entering multiple voices in the input file, use the following
530 order:
531
532 @example
533 Voice 1: highest
534 Voice 2: lowest
535 Voice 3: second highest
536 Voice 4: second lowest
537 Voice 5: third highest
538 Voice 6: third lowest
539 etc.
540 @end example
541
542 Though this may seem counterintuitive, it simplifies the automatic
543 layout process.  Note that the odd-numbered voices are given
544 upstems, and the even-numbered voices are given downstems:
545
546 @lilypond[quote,verbatim]
547 \new Staff <<
548   \time 2/4
549   { f''2 }  % 1: highest
550   \\
551   { c'2  }  % 2: lowest
552   \\
553   { d''2 }  % 3: second-highest
554   \\
555   { e'2  }  % 4: second-lowest
556   \\
557   { b'2  }  % 5: third-highest
558   \\
559   { g'2  }  % 6: third-lowest
560 >>
561 @end lilypond
562
563 @funindex \voices
564 When a different voice entry order is desired, the command
565 @code{\voices} may be convenient:
566
567 @lilypond[quote,verbatim]
568 \new Staff \voices 1,3,5,6,4,2 <<
569   \time 2/4
570   { f''2 }  % 1: highest
571   \\
572   { d''2 }  % 3: second-highest
573   \\
574   { b'2  }  % 5: third-highest
575   \\
576   { g'2  }  % 6: third-lowest
577   \\
578   { e'2  }  % 4: second-lowest
579   \\
580   { c'2  }  % 2: lowest
581 >>
582 @end lilypond
583
584
585 @warning{Lyrics and spanners (such as slurs, ties, hairpins, etc.) cannot
586 be created @q{across} voices.}
587
588 @subsubsubheading Identical rhythms
589
590 In the special case that we want to typeset parallel pieces of music
591 that have the same rhythm, we can combine them into a single
592 @code{Voice} context, thus forming chords.  To achieve this, enclose
593 them in a simple simultaneous music construct within an explicit voice:
594
595 @lilypond[quote,verbatim]
596 \new Voice <<
597   \relative { e''4 f8 d e16 f g8 d4 }
598   \relative { c''4 d8 b c16 d e8 b4 }
599 >>
600 @end lilypond
601
602 This method leads to strange beamings and warnings if the pieces of
603 music do not have the same rhythm.
604
605
606 @predefined
607 @code{\voiceOne},
608 @code{\voiceTwo},
609 @code{\voiceThree},
610 @code{\voiceFour},
611 @code{\oneVoice}.
612 @endpredefined
613
614 @seealso
615 Learning Manual:
616 @rlearning{Voices contain music},
617 @rlearning{Explicitly instantiating voices}.
618
619 Notation Reference:
620 @ref{Percussion staves},
621 @ref{Invisible rests},
622 @ref{Stems}.
623
624 Snippets:
625 @rlsr{Simultaneous notes}.
626
627
628 @node Voice styles
629 @unnumberedsubsubsec Voice styles
630
631 @cindex voice styles
632 @cindex styles, voice
633 @cindex coloring voices
634 @funindex \voiceOneStyle
635 @funindex \voiceTwoStyle
636 @funindex \voiceThreeStyle
637 @funindex \voiceFourStyle
638 @funindex \voiceNeutralStyle
639
640 Voices may be given distinct colors and shapes, allowing them to be
641 easily identified:
642
643 @lilypond[quote,verbatim]
644 <<
645   \relative { \voiceOneStyle d''4 c2 b4 }
646   \\
647   \relative { \voiceTwoStyle e'2 e }
648   \\
649   \relative { \voiceThreeStyle b2. c4 }
650   \\
651   \relative { \voiceFourStyle g'2 g }
652 >>
653 @end lilypond
654
655 The @code{\voiceNeutralStyle} command is used to revert to the
656 standard presentation.
657
658
659 @predefined
660 @code{\voiceOneStyle},
661 @code{\voiceTwoStyle},
662 @code{\voiceThreeStyle},
663 @code{\voiceFourStyle},
664 @code{\voiceNeutralStyle}.
665 @endpredefined
666
667 @seealso
668 Learning Manual:
669 @rlearning{I'm hearing Voices},
670 @rlearning{Other sources of information}.
671
672 Snippets:
673 @rlsr{Simultaneous notes}.
674
675
676 @node Collision resolution
677 @unnumberedsubsubsec Collision resolution
678
679 @cindex merging notes
680 @cindex note collisions
681 @cindex collisions
682 @cindex shift note
683 @cindex multiple voices
684 @cindex voices, multiple
685 @cindex polyphonic music
686 @cindex shifting voices
687 @cindex voices, multiple
688 @cindex shift rest, automatic
689 @funindex \shiftOn
690 @funindex \shiftOnn
691 @funindex \shiftOnnn
692 @funindex \shiftOff
693 @funindex \mergeDifferentlyDottedOn
694 @funindex \mergeDifferentlyDottedOff
695 @funindex \mergeDifferentlyHeadedOn
696 @funindex \mergeDifferentlyHeadedOff
697
698 The note heads of notes in different voices with the same pitch,
699 same note head and opposite stem direction are automatically
700 merged, but notes with different note heads or the same stem
701 direction are not.  Rests opposite a stem in a different voice
702 are shifted vertically.  The following example shows three
703 different circumstances, on beats 1 and 3 in bar 1 and beat 1
704 in bar 2, where the automatic merging fails.
705
706 @lilypond[quote,verbatim]
707 <<
708   \relative {
709     c''8 d e d c d c4
710     g'2 fis
711   } \\
712   \relative {
713     c''2 c8. b16 c4
714     e,2 r
715   } \\
716   \relative {
717     \oneVoice
718     s1
719     e'8 a b c d2
720   }
721 >>
722 @end lilypond
723
724 Notes with different note heads may be merged as shown
725 below.  In this example the note heads on beat 1 of bar 1 are now merged:
726
727 @lilypond[quote,verbatim]
728 <<
729   \relative {
730     \mergeDifferentlyHeadedOn
731     c''8 d e d c d c4
732     g'2 fis
733   } \\
734   \relative {
735     c''2 c8. b16 c4
736     e,2 r
737   } \\
738   \relative {
739     \oneVoice
740     s1
741     e'8 a b c d2
742   }
743 >>
744 @end lilypond
745
746 Quarter and half notes are not merged in this way, since it would be difficult
747 to tell them apart.
748
749 Note heads with different dots as shown in beat 3 of bar 1 may be
750 also be merged:
751
752 @lilypond[quote,verbatim]
753 <<
754   \relative {
755     \mergeDifferentlyHeadedOn
756     \mergeDifferentlyDottedOn
757     c''8 d e d c d c4
758     g'2 fis
759   } \\
760   \relative {
761     c''2 c8. b16 c4
762     e,2 r
763   } \\
764   \relative {
765     \oneVoice
766     s1
767     e'8 a b c d2
768   }
769 >>
770 @end lilypond
771
772 The half note and eighth note at the start of the second measure
773 are incorrectly merged because the automatic merge cannot
774 successfully complete the merge when three or more notes line up in
775 the same note column, and in this case the merged note head is
776 incorrect.  To allow the merge to select the correct note head
777 a @code{\shift} must be applied to the note that should not be
778 merged.  Here, @code{\shiftOn} is applied to move the top
779 @notation{g} out of the column, and @code{\mergeDifferentlyHeadedOn}
780 then works properly.
781
782 @lilypond[quote,verbatim]
783 <<
784   \relative {
785     \mergeDifferentlyHeadedOn
786     \mergeDifferentlyDottedOn
787     c''8 d e d c d c4
788     \shiftOn
789     g'2 fis
790   } \\
791   \relative {
792     c''2 c8. b16 c4
793     e,2 r
794   } \\
795   \relative {
796     \oneVoice
797     s1
798     e'8 a b c d2
799   }
800 >>
801 @end lilypond
802
803 The @code{\shiftOn} command allows (but does not force) the notes
804 in a voice to be shifted.  When @code{\shiftOn} is applied to a
805 voice, a note or chord in that voice is shifted only if its stem
806 would otherwise collide with a stem from another voice, and only
807 if the colliding stems point in the same direction.  The
808 @code{\shiftOff} command prevents this type of shifting from
809 occurring.
810
811 By default, the outer voices (normally voices one and two) have
812 @code{\shiftOff} specified, while the inner voices (three and
813 above) have @code{\shiftOn} specified.  When a shift is applied,
814 voices with upstems (odd-numbered voices) are shifted to the
815 right, and voices with downstems (even-numbered voices) are
816 shifted to the left.
817
818 Here is an example to help you visualize how an abbreviated
819 polyphonic expression would be expanded internally.
820
821 @warning{Note that with three or more voices, the vertical order
822 of voices in your input file should not be the same as the
823 vertical order of voices on the staff!}
824
825 @lilypond[quote,verbatim]
826 \new Staff \relative {
827   %% abbreviated entry
828   <<
829     { f''2  }  % 1: highest
830     \\
831     { g,2 }  % 2: lowest
832     \\
833     { d'2 }  % 3: upper middle
834     \\
835     { b2  }  % 4: lower middle
836   >>
837   %% internal expansion of the above
838   <<
839     \new Voice = "1" { \voiceOne   \shiftOff f'2 }
840     \new Voice = "2" { \voiceTwo   \shiftOff g,2 }
841     \new Voice = "3" { \voiceThree \shiftOn  d'2 } % shifts right
842     \new Voice = "4" { \voiceFour  \shiftOn  b2  } % shifts left
843   >>
844 }
845 @end lilypond
846
847 Two additional commands, @code{\shiftOnn} and @code{\shiftOnnn}
848 provide further shift levels which may be specified temporarily to
849 resolve collisions in complex situations -- see
850 @rlearning{Real music example}.
851
852 Notes are only merged if they have opposing stem directions (as
853 they have, for example, in voices one and two by default or when
854 the stems are explicitly set in opposite directions).
855
856 @predefined
857 @code{\mergeDifferentlyDottedOn},
858 @code{\mergeDifferentlyDottedOff},
859 @code{\mergeDifferentlyHeadedOn},
860 @code{\mergeDifferentlyHeadedOff}.
861
862 @code{\shiftOn},
863 @code{\shiftOnn},
864 @code{\shiftOnnn},
865 @code{\shiftOff}.
866 @endpredefined
867
868 @snippets
869 @lilypondfile[verbatim,quote,texidoc,doctitle]
870 {additional-voices-to-avoid-collisions.ly}
871
872 @lilypondfile[verbatim,quote,texidoc,doctitle]
873 {forcing-horizontal-shift-of-notes.ly}
874
875 @seealso
876 Music Glossary:
877 @rglos{polyphony}.
878
879 Learning Manual:
880 @rlearning{Multiple notes at once},
881 @rlearning{Voices contain music},
882 @rlearning{Real music example}.
883
884 Snippets:
885 @rlsr{Simultaneous notes}.
886
887 Internals Reference:
888 @rinternals{NoteColumn},
889 @rinternals{NoteCollision},
890 @rinternals{RestCollision}.
891
892 @cindex collisions, ignoring
893
894 @knownissues
895 Using @code{\override NoteColumn.ignore-collision = ##t} will cause
896 differently headed notes in different voices to merge incorrectly.
897
898 @lilypond[quote,verbatim,fragment]
899 \mergeDifferentlyHeadedOn
900 << \relative { c'16 a' b a } \\ \relative { c'2 } >>
901 \override NoteColumn.ignore-collision = ##t
902 << \relative { c'16 a' b a } \\ \relative { c'2 } >>
903 @end lilypond
904
905 @ignore
906 @knownissues
907 @c TODO investigate! Sometimes it works, sometimes not. --FV
908 The requirements for successfully merging different note heads that
909 are at the same time differently dotted are not clear.
910 @end ignore
911
912
913 @node Merging rests
914 @unnumberedsubsubsec Merging rests
915
916 When using multiple voices it is common to merge rests which occur in both
917 parts. This can be accomplished using @code{Merge_rests_engraver}.
918
919 @lilypond[quote,verbatim]
920 voiceA = \relative { d''4 r d2 | R1 | }
921 voiceB = \relative { fis'4 r g2 | R1 | }
922 \score {
923   <<
924     \new Staff \with {
925       instrumentName = "unmerged"
926     }
927     <<
928       \new Voice { \voiceOne \voiceA }
929       \new Voice { \voiceTwo \voiceB }
930     >>
931     \new Staff \with {
932       instrumentName = "merged"
933       \consists #Merge_rests_engraver
934     }
935     <<
936       \new Voice { \voiceOne \voiceA }
937       \new Voice { \voiceTwo \voiceB }
938     >>
939   >>
940 }
941 @end lilypond
942
943 Setting the context property @code{suspendRestMerging} to @code{##t} allows for
944 turning off rest merging temporarily.
945
946 @node Automatic part combining
947 @unnumberedsubsubsec Automatic part combining
948
949 @cindex automatic part combining
950 @cindex part combiner
951 @cindex combining parts
952 @cindex a due part
953 @cindex solo part
954 @funindex \partcombine
955
956 Automatic part combining is used to merge two separate parts of music
957 onto a single staff. This can be especially helpful when typesetting
958 orchestral scores.  A single @code{Voice} is printed while the two parts
959 of music are the same, but in places where they differ, a second
960 @code{Voice} is printed.  Stem directions are set up & down accordingly
961 while Solo and @notation{a due} parts are also identified and marked
962 appropriately.
963
964 The syntax for automatic part combining is:
965
966 @example
967 \partcombine @var{musicexpr1} @var{musicexpr2}
968 @end example
969
970 The following example demonstrates the basic functionality, putting
971 parts on a single staff as polyphony and setting stem directions
972 accordingly.  The same variables are used for the independent parts and
973 the combined staff.
974
975 @lilypond[quote,verbatim]
976 instrumentOne = \relative {
977   c'4 d e f |
978   R1 |
979   d'4 c b a |
980   b4 g2 f4 |
981   e1 |
982 }
983
984 instrumentTwo = \relative {
985   R1 |
986   g'4 a b c |
987   d4 c b a |
988   g4 f( e) d |
989   e1 |
990 }
991
992 <<
993   \new Staff \instrumentOne
994   \new Staff \instrumentTwo
995   \new Staff \partcombine \instrumentOne \instrumentTwo
996 >>
997 @end lilypond
998
999 Both parts have identical notes in the third measure, so only one
1000 instance of the notes is printed.  Stem, slur, and tie directions are
1001 set automatically, depending on whether the parts are playing solo or in
1002 unison.  When needed in polyphony situations, the first part (with
1003 context called @code{one}) gets @qq{up} stems, while the second (called
1004 @code{two}) always gets @qq{down} stems.  In solo situations, the first
1005 and second parts get marked with @qq{Solo} and @qq{Solo II},
1006 respectively.  The unison (@notation{a due}) parts are marked with the
1007 text @qq{a2}.
1008
1009 By default, the partcombiner merges two notes of the same pitch as an
1010 @notation{a due} note, combines notes with the same
1011 rhythm less than a ninth apart as chords and separates notes more than
1012 a ninth apart (or when the voices cross) into
1013 separate voices.  This can be overridden with an optional argument of a pair
1014 of numbers after the @code{\partcombine} command: the first specifies
1015 the interval where notes start to be combined (the default is zero) and the
1016 second where the notes are split into separate voices.  Setting the second
1017 argument to zero means that the partcombiner splits notes with an interval of
1018 a second or more, setting it to one splits notes of a third or more, and so on.
1019
1020 @lilypond[quote,verbatim]
1021 instrumentOne = \relative {
1022   a4 b c d |
1023   e f g a |
1024   b c d e |
1025 }
1026
1027 instrumentTwo = \relative {
1028   c'4 c c c |
1029   c c c c |
1030   c c c c |
1031 }
1032
1033 <<
1034   \new Staff \partcombine \instrumentOne \instrumentTwo
1035   \new Staff \partcombine #'(2 . 3) \instrumentOne \instrumentTwo
1036 >>
1037 @end lilypond
1038
1039
1040 Both arguments to @code{\partcombine} will be interpreted as separate
1041 @code{Voice} contexts, so if the music is being specified in relative
1042 mode then @emph{both} parts must contain a @code{\relative} function,
1043 i.e.,
1044
1045 @example
1046 \partcombine
1047   \relative @dots{} @var{musicexpr1}
1048   \relative @dots{} @var{musicexpr2}
1049 @end example
1050
1051 @noindent
1052 A @code{\relative} section that encloses a @code{\partcombine} has no
1053 effect on the pitches of @code{@var{musicexpr1}} or
1054 @code{@var{musicexpr2}}.
1055
1056 @funindex \partcombineChords
1057 @funindex \partcombineApart
1058 @funindex \partcombineUnisono
1059 @funindex \partcombineSoloI
1060 @funindex \partcombineSoloII
1061 @funindex \partcombineAutomatic
1062
1063 In professional scores, voices are often kept apart from each other for
1064 long passages of music even if some of the notes are the same in both
1065 voices, and could just as easily be printed as unison. Combining notes
1066 into a chord, or showing one voice as solo is, therefore, not ideal as
1067 the @code{\partcombine} function considers each note separately. In this
1068 case the @code{\partcombine} function can be overridden with one of the
1069 following commands.  All of the commands may be preceded with
1070 @code{\once} in order to have them only apply to the next note in
1071 the music expression.
1072
1073 @itemize
1074 @item
1075 @code{\partcombineApart} keeps the
1076 notes as two separate voices, even if they can be combined into a chord
1077 or unison.
1078
1079 @item
1080 @code{\partcombineChords} combines the
1081 notes into a chord.
1082
1083 @item
1084 @code{\partcombineUnisono} combines
1085 both voices as @qq{unison}.
1086
1087 @item
1088 @code{\partcombineSoloI} prints only
1089 voice one, and marks it as a @qq{Solo}.
1090
1091 @item
1092 @code{\partcombineSoloII} prints only
1093 voice two and marks it as a @qq{Solo}.
1094
1095 @item
1096 @code{\partcombineAutomatic} ends
1097 the functions of the commands above, and reverts back to the standard
1098 @code{\partcombine} functionality.
1099 @end itemize
1100
1101 @lilypond[quote,verbatim]
1102 instrumentOne = \relative c' {
1103   \partcombineApart c2^"apart" e |
1104   \partcombineAutomatic e2^"auto" e |
1105   \partcombineChords e'2^"chord" e |
1106   \partcombineAutomatic c2^"auto" c |
1107   \partcombineApart c2^"apart" \once \partcombineChords e^"chord once" |
1108   c2 c |
1109 }
1110 instrumentTwo = \relative {
1111   c'2 c |
1112   e2 e |
1113   a,2 c |
1114   c2 c' |
1115   c2 c |
1116   c2 c |
1117 }
1118
1119 <<
1120   \new Staff { \instrumentOne }
1121   \new Staff { \instrumentTwo }
1122   \new Staff { \partcombine \instrumentOne \instrumentTwo }
1123 >>
1124 @end lilypond
1125
1126
1127 @subsubsubheading Using \partcombine with lyrics
1128
1129 @cindex \partcombine and lyrics
1130
1131 The @code{\partcombine} command is not designed to work with
1132 lyrics; if one of the voices is explicitly named in order to
1133 attach lyrics to it, the partcombiner will stop working.  However,
1134 this effect can be achieved using a @code{NullVoice} context.  See
1135 @ref{Polyphony with shared lyrics}.
1136
1137
1138 @snippets
1139
1140 @lilypondfile[verbatim,quote,texidoc,doctitle]
1141 {combining-two-parts-on-the-same-staff.ly}
1142
1143 @lilypondfile[verbatim,quote,texidoc,doctitle]
1144 {changing-partcombine-texts.ly}
1145
1146 @seealso
1147 Music Glossary:
1148 @rglos{a due},
1149 @rglos{part}.
1150
1151 Notation Reference:
1152 @ref{Writing parts}.
1153
1154 Snippets:
1155 @rlsr{Simultaneous notes}.
1156
1157 Internals Reference:
1158 @rinternals{PartCombineMusic},
1159 @rinternals{Voice}.
1160
1161 @knownissues
1162 All @code{\partcombine@dots{}} functions can only accept two voices.
1163
1164 @code{\partcombine@dots{}} functions cannot be placed inside a @code{\tuplet}
1165 or @code{\relative} block.
1166
1167 If @code{printPartCombineTexts} is set and the two voices play the same
1168 notes @qq{on and off}, in the same measure, the part combiner may
1169 typeset @code{a2} more than once in that measure.
1170
1171 @code{\partcombine} only knows when a note starts in a @code{Voice}; it
1172 cannot, for example, remember if a note in one @code{Voice} has already
1173 started when combining notes that have just started in the other
1174 @code{Voice}.  This can lead to a number of unexpected issues including
1175 @qq{Solo} or @qq{Unison} marks being printed incorrectly.
1176
1177 @code{\partcombine} keeps all spanners (slurs, ties, hairpins, etc.) in
1178 the same @code{Voice} so that if any such spanners start or end in a
1179 different @code{Voice}, they may not be printed properly or at all.
1180
1181 If the @code{\partcombine} function cannot combine both music
1182 expressions (i.e., when both voices have different durations), it will
1183 give the voices, internally, its own custom names: @code{one} and
1184 @code{two} respectively.  This means if there is any @qq{switch} to a
1185 differently named @code{Voice} context, the events in that differently
1186 named @code{Voice} will be ignored.
1187
1188 Refer also to @emph{Known issues and warnings} when using
1189 @code{\partcombine} with tablature in @ref{Default tablatures} and the
1190 @emph{Note} in @ref{Automatic beams} when using automatic beaming.
1191
1192
1193 @node Writing music in parallel
1194 @unnumberedsubsubsec Writing music in parallel
1195
1196 @cindex writing music in parallel
1197 @cindex interleaved music
1198 @cindex parallel music
1199 @funindex \parallelMusic
1200
1201 Music for multiple parts can be interleaved in input code.  The
1202 function @code{\parallelMusic} accepts a list with the names of a
1203 number of variables to be created, and a musical expression.  The
1204 content of alternate measures from the expression become the value
1205 of the respective variables, so you can use them afterwards to
1206 print the music.
1207
1208 @warning{Bar checks @code{|} must be used, and the measures must
1209 be of the same length.}
1210
1211 @lilypond[quote,verbatim]
1212 \parallelMusic #'(voiceA voiceB voiceC) {
1213   % Bar 1
1214   r8 g'16 c'' e'' g' c'' e'' r8 g'16 c'' e'' g' c'' e'' |
1215   r16 e'8.~   4              r16 e'8.~   4              |
1216   c'2                        c'2                        |
1217
1218   % Bar 2
1219   r8 a'16 d'' f'' a' d'' f'' r8 a'16 d'' f'' a' d'' f'' |
1220   r16 d'8.~   4              r16 d'8.~   4              |
1221   c'2                        c'2                        |
1222
1223 }
1224 \new StaffGroup <<
1225   \new Staff << \voiceA \\ \voiceB >>
1226   \new Staff { \clef bass \voiceC }
1227 >>
1228 @end lilypond
1229
1230 Relative mode may be used.  Note that the @code{\relative} command
1231 is not used inside @code{\parallelMusic} itself.  The notes are
1232 relative to the preceding note in the voice, not to the previous
1233 note in the input -- in other words, relative notes for
1234 @code{voiceA} ignore the notes in @code{voiceB}.
1235
1236 @lilypond[quote,verbatim]
1237 \parallelMusic #'(voiceA voiceB voiceC) {
1238   % Bar 1
1239   r8 g16 c e g, c e r8 g,16 c e g, c e  |
1240   r16 e8.~ 4        r16 e8.~  4         |
1241   c2                c                   |
1242
1243   % Bar 2
1244   r8 a,16 d f a, d f r8 a,16 d f a, d f |
1245   r16 d8.~  4        r16 d8.~  4        |
1246   c2                 c                  |
1247
1248  }
1249 \new StaffGroup <<
1250   \new Staff << \relative c'' \voiceA \\ \relative c' \voiceB >>
1251   \new Staff \relative c' { \clef bass \voiceC }
1252 >>
1253 @end lilypond
1254
1255 This works quite well for piano music.  This example maps four
1256 consecutive measures to four variables:
1257
1258 @lilypond[quote,verbatim]
1259 global = {
1260   \key g \major
1261   \time 2/4
1262 }
1263
1264 \parallelMusic #'(voiceA voiceB voiceC voiceD) {
1265   % Bar 1
1266   a8    b     c   d     |
1267   d4          e         |
1268   c16 d e fis d e fis g |
1269   a4          a         |
1270
1271   % Bar 2
1272   e8      fis  g     a   |
1273   fis4         g         |
1274   e16 fis g  a fis g a b |
1275   a4           a         |
1276
1277   % Bar 3 ...
1278 }
1279
1280 \score {
1281   \new PianoStaff <<
1282      \new Staff {
1283        \global
1284        <<
1285          \relative c'' \voiceA
1286          \\
1287          \relative c'  \voiceB
1288        >>
1289      }
1290      \new Staff {
1291        \global \clef bass
1292        <<
1293          \relative c \voiceC
1294          \\
1295          \relative c \voiceD
1296        >>
1297      }
1298   >>
1299 }
1300 @end lilypond
1301
1302 @seealso
1303 Learning Manual:
1304 @rlearning{Organizing pieces with variables}.
1305
1306 Snippets:
1307 @rlsr{Simultaneous notes}.