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