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