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