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