]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/simultaneous.itely
Doc:NR Pitches: clarify simultaneous accidentals
[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.13.36"
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 @item
120 temporary use of @ref{Multiple voices},
121 @samp{<< f! \\ <e fis!> >>},
122
123 @item
124 enharmonic transcription of one or more pitches,
125 @samp{<e f ges>}, or
126
127 @item
128 @ref{Clusters}.
129
130 @end itemize
131
132 @node Chord repetition
133 @unnumberedsubsubsec Chord repetition
134
135 In order to save typing, a shortcut can be used to repeat the preceding
136 chord.  The chord repetition symbol is @code{q}:
137
138 @lilypond[verbatim,quote,relative=2]
139 <a c e>1 q <f a c>2 q
140 @end lilypond
141
142 As with regular chords, the chord repetition symbol can be used with
143 durations, articulations, markups, slurs, beams, etc. as only the
144 pitches of the previous chord are duplicated.
145
146 @lilypond[verbatim,quote,relative=2]
147 <a c e>1\p^"text" q2\<( q8)[-| q8.]\! q16-1-2-3 q8\prall
148 @end lilypond
149
150 The chord repetition symbol always remembers the last instance of
151 a chord so it is possible to repeat the most recent chord even if
152 other non-chorded notes or rests have been added since.
153
154 @lilypond[verbatim,quote,relative=2]
155 <a c e>1 c4 q2 r8 q8
156 @end lilypond
157
158 However, the chord repetition symbol does not retain any dynamics,
159 articulation or ornamentation within, or attached to the previous chord.
160
161 @lilypond[verbatim,quote,relative=2]
162 <a-. c\prall e>1\sfz c4 q2 r8 q8
163 @end lilypond
164
165 @seealso
166 Notation Reference:
167 @ref{Chord notation},
168 @ref{Articulations and ornamentations}.
169
170 Installed Files:
171 @file{ly/chord-repetition-init.ly}.
172
173
174 @node Simultaneous expressions
175 @unnumberedsubsubsec Simultaneous expressions
176
177 One or more music expressions enclosed in double angle brackets are
178 taken to be simultaneous.  If the first expression begins with a
179 single note or if the whole simultaneous expression appears
180 explicitly within a single voice, the whole expression is placed on
181 a single staff; otherwise the elements of the simultaneous
182 expression are placed on separate staves.
183
184 The following examples show simultaneous expressions on one staff:
185
186 @lilypond[quote,verbatim,relative=2]
187 \new Voice {  % explicit single voice
188   << { a4 b g2 } { d4 g c,2 } >>
189 }
190 @end lilypond
191
192 @lilypond[quote,verbatim,relative=2]
193 % single first note
194 a << { a4 b g } { d4 g c, } >>
195 @end lilypond
196
197 This can be useful if the simultaneous sections have identical
198 rhythms, but attempts to attach notes with different durations
199 to the same stem will cause errors.
200
201 The following example shows how simultaneous expressions can
202 generate multiple staves implicitly:
203
204 @lilypond[quote,verbatim,relative=2]
205 % no single first note
206 << { a4 b g2 } { d4 g2 c,4 } >>
207 @end lilypond
208
209 Here different rhythms cause no problems.
210
211
212 @node Clusters
213 @unnumberedsubsubsec Clusters
214
215 @cindex cluster
216 @cindex note cluster
217
218 @funindex \makeClusters
219 @funindex makeClusters
220
221 A cluster indicates a continuous range of pitches to be played.
222 They can be denoted as the envelope of a set of notes.  They are
223 entered by applying the function @code{\makeClusters} to a sequence
224 of chords, e.g.,
225
226 @lilypond[quote,relative=2,verbatim]
227 \makeClusters { <g b>2 <c g'> }
228 @end lilypond
229
230 Ordinary notes and clusters can be put together in the same staff,
231 even simultaneously.  In such a case no attempt is made to
232 automatically avoid collisions between ordinary notes and clusters.
233
234
235 @seealso
236 Music Glossary:
237 @rglos{cluster}.
238
239 Snippets:
240 @rlsr{Simultaneous notes}.
241
242 Internals Reference:
243 @rinternals{ClusterSpanner},
244 @rinternals{ClusterSpannerBeacon},
245 @rinternals{Cluster_spanner_engraver}.
246
247
248 @knownissues
249
250 Clusters look good only if they span at least two chords; otherwise
251 they appear too narrow.
252
253 Clusters do not have a stem and cannot indicate durations by
254 themselves, but the length of the printed cluster is determined by
255 the durations of the defining chords.  Separate clusters need a
256 separating rest between them.
257
258 Clusters do not produce MIDI output.
259
260 @node Multiple voices
261 @subsection Multiple voices
262
263 This section discusses simultaneous notes in multiple voices or
264 multiple staves.
265
266 @menu
267 * Single-staff polyphony::
268 * Voice styles::
269 * Collision resolution::
270 * Automatic part combining::
271 * Writing music in parallel::
272 @end menu
273
274
275 @node Single-staff polyphony
276 @unnumberedsubsubsec Single-staff polyphony
277
278 @cindex single-staff polyphony
279 @cindex polyphony, single-staff
280 @cindex voice
281 @cindex lyrics assigned to one voice
282
283 @funindex \voiceOne
284 @funindex voiceOne
285 @funindex \voiceOne ... \voiceFour
286 @funindex Voice
287 @funindex \oneVoice
288 @funindex oneVoice
289
290 @strong{@i{Explicitly instantiating voices}}
291
292 The basic structure needed to achieve multiple independent
293 voices in a single staff is illustrated in the following example:
294
295 @lilypond[quote,relative=3,verbatim]
296 \new Staff <<
297   \new Voice = "first"
298     { \voiceOne r8 r16 g e8. f16 g8[ c,] f e16 d }
299   \new Voice= "second"
300     { \voiceTwo d16 c d8~ d16 b c8~ c16 b c8~ c16 b8. }
301 >>
302 @end lilypond
303
304 @noindent
305 Here, voices are instantiated explicitly and are given names.  The
306 @code{\voiceOne} ... @code{\voiceFour} commands set up the voices
307 so that first and third voices get stems up, second and fourth
308 voices get stems down, third and fourth voice note heads are
309 horizontally shifted, and rests in the respective voices are
310 automatically moved to avoid collisions.  The @code{\oneVoice}
311 command returns all the voice settings to the neutral default
312 directions.
313
314 @strong{@i{Temporary polyphonic passages}}
315
316 A temporary polyphonic passage can be created with the following
317 construct:
318
319 @example
320 << @{ \voiceOne ... @}
321   \new Voice @{ \voiceTwo ... @}
322 >> \oneVoice
323 @end example
324
325 @noindent
326 Here, the first expression within a temporary polyphonic passage is
327 placed into the @code{Voice} context which was in use immediately
328 before the polyphonic passage, and that same @code{Voice} context
329 continues after the temporary section.  Other expressions within
330 the angle brackets are assigned to distinct temporary voices.
331 This allows lyrics to be assigned to one continuing voice before,
332 during and after a polyphonic section:
333
334 @lilypond[quote, verbatim, relative=2]
335 <<
336   \new Voice = "melody" {
337     a4
338     <<
339       {
340         \voiceOne
341         g f
342       }
343       \new Voice {
344         \voiceTwo
345         d2
346       }
347     >>
348     \oneVoice
349     e4
350   }
351   \new Lyrics \lyricsto "melody" {
352   This is my song.
353   }
354 >>
355 @end lilypond
356
357 @noindent
358 Here, the @code{\voiceOne} and @code{\voiceTwo} commands are
359 required to define the settings of each voice.
360
361 @strong{@i{The double backslash construct}}
362
363 The @code{<< @{...@} \\ @{...@} >>} construct, where the two (or
364 more) expressions are separated by double backslashes, behaves
365 differently to the similar construct without the double backslashes:
366 @emph{all} the expressions within this construct are assigned
367 to new @code{Voice} contexts.  These new @code{Voice} contexts
368 are created implicitly and are given the fixed names @code{"1"},
369 @code{"2"}, etc.
370
371 The first example could be typeset as follows:
372
373 @lilypond[quote,relative=3,verbatim]
374 <<
375   { r8 r16 g e8. f16 g8[ c,] f e16 d }
376   \\
377   { d16 c d8~ d16 b c8~ c16 b c8~ c16 b8. }
378 >>
379 @end lilypond
380
381 This syntax can be used where it does not matter that temporary
382 voices are created and then discarded.  These implicitly created
383 voices are given the settings equivalent to the effect of the
384 @code{\voiceOne} ... @code{\voiceFour} commands, in the order in
385 which they appear in the code.
386
387 In the following example, the intermediate voice has stems up,
388 therefore we enter it in the third place, so it becomes voice
389 three, which has the stems up as desired.  Spacer rests are
390 used to avoid printing doubled rests.
391
392 @lilypond[quote,relative=3,verbatim]
393 <<
394   { r8 g g  g g f16 ees f8 d }
395   \\
396   { ees,8 r ees r d r d r }
397   \\
398   { d'8 s c s bes s a s }
399 >>
400 @end lilypond
401
402 In all but the simplest works it is advisable to create explicit
403 @code{Voice} contexts as explained in @rlearning{Contexts and engravers} and
404 @rlearning{Explicitly instantiating voices}.
405
406 @strong{@i{Voice order}}
407
408 When entering multiple voices in the input file, use the following
409 order:
410
411 @example
412 Voice 1: highest
413 Voice 2: lowest
414 Voice 3: second highest
415 Voice 4: second lowest
416 Voice 5: third highest
417 Voice 6: third lowest
418 etc.
419 @end example
420
421 Though this may seem counterintuitive, it simplifies the automatic
422 layout process.  Note that the odd-numbered voices are given
423 upstems, and the even-numbered voices are given downstems:
424
425 @lilypond[quote,verbatim]
426 \new Staff <<
427   \time 2/4
428   { f''2 }  % 1: highest
429   \\
430   { c'2  }  % 2: lowest
431   \\
432   { d''2 }  % 3: second-highest
433   \\
434   { e'2  }  % 4: second-lowest
435   \\
436   { b'2  }  % 5: third-highest
437   \\
438   { g'2  }  % 6: third-lowest
439 >>
440 @end lilypond
441
442 @strong{@i{Identical rhythms}}
443
444 In the special case that we want to typeset parallel pieces of music
445 that have the same rhythm, we can combine them into a single
446 @code{Voice} context, thus forming chords.  To achieve this, enclose
447 them in a simple simultaneous music construct within an explicit voice:
448
449 @lilypond[quote,relative=2,verbatim]
450 \new Voice <<
451   { e4 f8 d e16 f g8 d4 }
452   { c4 d8 b c16 d e8 b4 }
453 >>
454 @end lilypond
455
456 This method leads to strange beamings and warnings if the pieces of
457 music do not have the same rhythm.
458
459
460 @predefined
461 @code{\voiceOne},
462 @code{\voiceTwo},
463 @code{\voiceThree},
464 @code{\voiceFour},
465 @code{\oneVoice}.
466 @endpredefined
467
468
469 @seealso
470 Learning Manual:
471 @rlearning{Voices contain music},
472 @rlearning{Explicitly instantiating voices}.
473
474 Notation Reference:
475 @ref{Percussion staves},
476 @ref{Invisible rests},
477 @ref{Stems}.
478
479 Snippets:
480 @rlsr{Simultaneous notes}.
481
482
483 @node Voice styles
484 @unnumberedsubsubsec Voice styles
485
486 @cindex voice styles
487 @cindex styles, voice
488 @cindex coloring voices
489 @funindex \voiceOneStyle
490 @funindex \voiceTwoStyle
491 @funindex \voiceThreeStyle
492 @funindex \voiceFourStyle
493 @funindex \voiceNeutralStyle
494
495 Voices may be given distinct colors and shapes, allowing them to be
496 easily identified:
497
498 @lilypond[quote,relative=2,verbatim]
499 <<
500   { \voiceOneStyle d4 c2 b4 }
501   \\
502   { \voiceTwoStyle e,2 e }
503   \\
504   { \voiceThreeStyle b2. c4 }
505   \\
506   { \voiceFourStyle g'2 g }
507 >>
508 @end lilypond
509
510 The @code{\voiceNeutralStyle} command is used to revert to the
511 standard presentation.
512
513
514 @predefined
515 @code{\voiceOneStyle},
516 @code{\voiceTwoStyle},
517 @code{\voiceThreeStyle},
518 @code{\voiceFourStyle},
519 @code{\voiceNeutralStyle}.
520 @endpredefined
521
522
523 @seealso
524 Learning Manual:
525 @rlearning{I'm hearing Voices},
526 @rlearning{Other sources of information}.
527
528 Snippets:
529 @rlsr{Simultaneous notes}.
530
531
532 @node Collision resolution
533 @unnumberedsubsubsec Collision resolution
534
535 @cindex merging notes
536 @cindex note collisions
537 @cindex collisions
538 @cindex shift note
539 @cindex multiple voices
540 @cindex voices, multiple
541 @cindex polyphonic music
542 @cindex shifting voices
543 @cindex voices, multiple
544 @cindex shift rest, automatic
545 @funindex \shiftOn
546 @funindex shiftOn
547 @funindex \shiftOnn
548 @funindex shiftOnn
549 @funindex \shiftOnnn
550 @funindex shiftOnnn
551 @funindex \shiftOff
552 @funindex shiftOff
553 @funindex \mergeDifferentlyDottedOn
554 @funindex mergeDifferentlyDottedOn
555 @funindex \mergeDifferentlyDottedOff
556 @funindex mergeDifferentlyDottedOff
557 @funindex \mergeDifferentlyHeadedOn
558 @funindex mergeDifferentlyHeadedOn
559 @funindex \mergeDifferentlyHeadedOff
560 @funindex mergeDifferentlyHeadedOff
561
562 The note heads of notes in different voices with the same pitch,
563 same note head and opposite stem direction are automatically
564 merged, but notes with different note heads or the same stem
565 direction are not.  Rests opposite a stem in a different voice
566 are shifted vertically.  The following example shows three
567 different circumstances, on beats 1 and 3 in bar 1 and beat 1
568 in bar 2, where the automatic merging fails.
569
570 @lilypond[quote,verbatim,relative=2]
571 <<
572   {
573     c8 d e d c d c4
574     g'2 fis
575   } \\ {
576     c2 c8. b16 c4
577     e,2 r
578   } \\ {
579     \oneVoice
580     s1
581     e8 a b c d2
582   }
583 >>
584 @end lilypond
585
586 Notes with different note heads may be merged, with the
587 exception of half-note heads and quarter-note heads, as shown
588 below.  Here the note heads on beat 1 of bar 1 are now merged:
589
590 @lilypond[quote,verbatim,relative=2]
591 <<
592   {
593     \mergeDifferentlyHeadedOn
594     c8 d e d c d c4
595     g'2 fis
596   } \\ {
597     c2 c8. b16 c4
598     e,2 r
599   } \\ {
600     \oneVoice
601     s1
602     e8 a b c d2
603   }
604 >>
605 @end lilypond
606
607 Note heads with different dots as shown in beat 3 of bar 1 may be
608 also be merged:
609
610 @lilypond[quote,relative=2,verbatim]
611 <<
612   {
613     \mergeDifferentlyHeadedOn
614     \mergeDifferentlyDottedOn
615     c8 d e d c d c4
616     g'2 fis
617   } \\ {
618     c2 c8. b16 c4
619     e,2 r
620   } \\ {
621     \oneVoice
622     s1
623     e8 a b c d2
624   }
625 >>
626 @end lilypond
627
628
629 The half note and eighth note at the start of the second measure
630 are incorrectly merged because the automatic merge cannot
631 successfully complete the merge when three or more notes line up in
632 the same note column, and in this case the merged note head is
633 incorrect.  To allow the merge to select the correct note head
634 a @code{\shift} must be applied to the note that should not be
635 merged.  Here, @code{\shiftOn} is applied to move the top
636 @notation{g} out of the column, and @code{\mergeDifferentlyHeadedOn}
637 then works properly.
638
639 @lilypond[quote,relative=2,verbatim]
640 <<
641   {
642     \mergeDifferentlyHeadedOn
643     \mergeDifferentlyDottedOn
644     c8 d e d c d c4
645     \shiftOn
646     g'2 fis
647   } \\ {
648     c2 c8. b16 c4
649     e,2 r
650   } \\ {
651     \oneVoice
652     s1
653     e8 a b c d2
654   }
655 >>
656 @end lilypond
657
658 The @code{\shiftOn} command allows (but does not force) the notes
659 in a voice to be shifted.  When @code{\shiftOn} is applied to a
660 voice, a note or chord in that voice is shifted only if its stem
661 would otherwise collide with a stem from another voice, and only
662 if the colliding stems point in the same direction.  The
663 @code{\shiftOff} command prevents this type of shifting from
664 occurring.
665
666 By default, the outer voices (normally voices one and two) have
667 @code{\shiftOff} specified, while the inner voices (three and
668 above) have @code{\shiftOn} specified.  When a shift is applied,
669 voices with upstems (odd-numbered voices) are shifted to the
670 right, and voices with downstems (even-numbered voices) are
671 shifted to the left.
672
673 Here is an example to help you visualize how an abbreviated
674 polyphonic expression would be expanded internally.
675
676 @warning{Note that with three or more voices, the vertical order
677 of voices in your input file should not be the same as the
678 vertical order of voices on the staff!}
679
680 @lilypond[quote,verbatim]
681 \new Staff \relative c'' {
682   %% abbreviated entry
683   <<
684     { f2  }  % 1: highest
685     \\
686     { g,2 }  % 2: lowest
687     \\
688     { d'2 }  % 3: upper middle
689     \\
690     { b2  }  % 4: lower middle
691   >>
692   %% internal expansion of the above
693   <<
694     \new Voice = "1" { \voiceOne   \shiftOff f'2 }
695     \new Voice = "2" { \voiceTwo   \shiftOff g,2 }
696     \new Voice = "3" { \voiceThree \shiftOn  d'2 } % shifts right
697     \new Voice = "4" { \voiceFour  \shiftOn  b2  } % shifts left
698   >>
699 }
700 @end lilypond
701
702 Two additional commands, @code{\shiftOnn} and @code{\shiftOnnn}
703 provide further shift levels which may be specified temporarily to
704 resolve collisions in complex situations -- see
705 @rlearning{Real music example}.
706
707 Notes are only merged if they have opposing stem directions (as
708 they have, for example, in voices one and two by default or when
709 the stems are explicitly set in opposite directions).
710
711
712 @predefined
713 @code{\mergeDifferentlyDottedOn},
714 @code{\mergeDifferentlyDottedOff},
715 @code{\mergeDifferentlyHeadedOn},
716 @code{\mergeDifferentlyHeadedOff}.
717
718 @code{\shiftOn},
719 @code{\shiftOnn},
720 @code{\shiftOnnn},
721 @code{\shiftOff}.
722 @endpredefined
723
724
725 @snippets
726
727 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
728 {additional-voices-to-avoid-collisions.ly}
729
730 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
731 {forcing-horizontal-shift-of-notes.ly}
732
733
734 @seealso
735 Music Glossary:
736 @rglos{polyphony}.
737
738 Learning Manual:
739 @rlearning{Multiple notes at once},
740 @rlearning{Voices contain music},
741 @rlearning{Real music example}.
742
743 Snippets:
744 @rlsr{Simultaneous notes}.
745
746 Internals Reference:
747 @rinternals{NoteColumn},
748 @rinternals{NoteCollision},
749 @rinternals{RestCollision}.
750
751
752 @ignore
753 @knownissues
754 @c TODO investigate! Sometimes it works, sometimes not. --FV
755 The requirements for successfully merging different note heads that
756 are at the same time differently dotted are not clear.
757 @end ignore
758
759 @node Automatic part combining
760 @unnumberedsubsubsec Automatic part combining
761
762 @cindex automatic part combining
763 @cindex part combiner
764 @cindex combining parts
765 @cindex a due part
766 @cindex solo part
767 @funindex \partcombine
768 @funindex partcombine
769
770 Automatic part combining is used to merge two parts of music onto
771 a staff.  It is aimed at typesetting orchestral scores.  When the
772 two parts are identical for a period of time, only one is shown.
773 In places where the two parts differ, they are typeset as separate
774 voices, and stem directions are set automatically.  Also, solo and
775 @notation{a due} parts are identified and marked by default.
776
777 The syntax for part combining is:
778
779 @example
780 \partcombine @var{musicexpr1} @var{musicexpr2}
781 @end example
782
783 The following example demonstrates the basic functionality of the
784 part combiner: putting parts on one staff and setting stem
785 directions and polyphony.  The same variables are used for the
786 independent parts and the combined staff.
787
788 @lilypond[quote,verbatim]
789 instrumentOne = \relative c' {
790   c4 d e f
791   R1
792   d'4 c b a
793   b4 g2 f4
794   e1
795 }
796
797 instrumentTwo = \relative g' {
798   R1
799   g4 a b c
800   d c b a
801   g f( e) d
802   e1
803 }
804
805 <<
806   \new Staff \instrumentOne
807   \new Staff \instrumentTwo
808   \new Staff \partcombine \instrumentOne \instrumentTwo
809 >>
810 @end lilypond
811
812 The notes in the third measure appear only once, although they were
813 specified in both parts.  Stem, slur, and tie directions are set
814 automatically, depending whether there is a solo or unison.  When
815 needed in polyphony situations, the first part (with context called
816 @code{one}) always gets up stems, while the second (called @code{two})
817 always gets down stems.  In solo situations, the first and second
818 parts get marked with @q{Solo} and @q{Solo II}, respectively.  The
819 unisono (@notation{a due}) parts are marked by default with the text
820 @qq{a2}.
821
822 Both arguments to @code{\partcombine} will be interpreted as
823 @code{Voice} contexts.  If using relative octaves,
824 @code{\relative} should be specified for both music expressions,
825 i.e.,
826
827 @example
828 \partcombine
829   \relative @dots{} @var{musicexpr1}
830   \relative @dots{} @var{musicexpr2}
831 @end example
832
833 @noindent
834 A @code{\relative} section that is outside of @code{\partcombine}
835 has no effect on the pitches of @code{@var{musicexpr1}} and
836 @code{@var{musicexpr2}}.
837
838 @snippets
839
840 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
841 {combining-two-parts-on-the-same-staff.ly}
842
843 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
844 {changing-partcombine-texts.ly}
845
846
847 @seealso
848 Music Glossary:
849 @rglos{a due},
850 @rglos{part}.
851
852 Notation Reference:
853 @ref{Writing parts}.
854
855 Snippets:
856 @rlsr{Simultaneous notes}.
857
858 Internals Reference:
859 @rinternals{PartCombineMusic},
860 @rinternals{Voice}.
861
862
863 @knownissues
864
865 @code{\partcombine} can only accept two voices.
866
867 When @code{printPartCombineTexts} is set, if the two voices play
868 the same notes on and off, the part combiner may typeset @code{a2}
869 more than once in a measure.
870
871 @code{\partcombine} cannot be inside @code{\times}.
872
873 @code{\partcombine} cannot be inside @code{\relative}.
874
875 Internally, the @code{\partcombine} interprets both arguments as
876 @code{Voice}s and decides when the parts can be combined.  When they have
877 different durations they cannot be combined and are given the names
878 @code{one} and @code{two}.  Consequently, if the arguments switch to
879 differently named @rinternals{Voice} contexts, the events in those will
880 be ignored.  Likewise, partcombining isn't designed to work with lyrics;
881 when one of the voices is explicitly named in order to attach lyrics to
882 it, the partcombining stops working.
883
884 @code{\partcombine} only observes onset times of notes.  It cannot
885 determine whether a previously started note is playing or not, leading
886 to various problems.
887
888
889 @node Writing music in parallel
890 @unnumberedsubsubsec Writing music in parallel
891
892 @cindex writing music in parallel
893 @cindex interleaved music
894 @cindex parallel music
895 @funindex \parallelMusic
896 @funindex parallelMusic
897
898 Music for multiple parts can be interleaved in input code.  The
899 function @code{\parallelMusic} accepts a list with the names of a
900 number of variables to be created, and a musical expression.  The
901 content of alternate measures from the expression become the value
902 of the respective variables, so you can use them afterwards to
903 print the music.
904
905 @warning{Bar checks @code{|} must be used, and the measures must
906 be of the same length.}
907
908 @lilypond[quote,verbatim]
909 \parallelMusic #'(voiceA voiceB voiceC) {
910   % Bar 1
911   r8 g'16 c'' e'' g' c'' e'' r8 g'16 c'' e'' g' c'' e'' |
912   r16 e'8.~   e'4            r16 e'8.~   e'4            |
913   c'2                        c'2                        |
914
915   % Bar 2
916   r8 a'16 d'' f'' a' d'' f'' r8 a'16 d'' f'' a' d'' f'' |
917   r16 d'8.~   d'4            r16 d'8.~   d'4            |
918   c'2                        c'2                        |
919
920 }
921 \new StaffGroup <<
922   \new Staff << \voiceA \\ \voiceB >>
923   \new Staff { \clef bass \voiceC }
924 >>
925 @end lilypond
926
927 Relative mode may be used.  Note that the @code{\relative} command
928 is not used inside @code{\parallelMusic} itself.  The notes are
929 relative to the preceding note in the voice, not to the previous
930 note in the input -- in other words, relative notes for
931 @code{voiceA} ignore the notes in @code{voiceB}.
932
933 @lilypond[quote,verbatim]
934 \parallelMusic #'(voiceA voiceB voiceC) {
935   % Bar 1
936   r8 g16 c e g, c e r8 g,16 c e g, c e  |
937   r16 e8.~ e4       r16 e8.~  e4        |
938   c2                c                   |
939
940   % Bar 2
941   r8 a,16 d f a, d f r8 a,16 d f a, d f |
942   r16 d8.~  d4       r16 d8.~  d4       |
943   c2                 c                  |
944
945  }
946 \new StaffGroup <<
947   \new Staff << \relative c'' \voiceA \\ \relative c' \voiceB >>
948   \new Staff \relative c' { \clef bass \voiceC }
949 >>
950 @end lilypond
951
952 This works quite well for piano music.  This example maps four
953 consecutive measures to four variables:
954
955 @lilypond[quote,verbatim]
956 global = {
957   \key g \major
958   \time 2/4
959 }
960
961 \parallelMusic #'(voiceA voiceB voiceC voiceD) {
962   % Bar 1
963   a8    b     c   d     |
964   d4          e         |
965   c16 d e fis d e fis g |
966   a4          a         |
967
968   % Bar 2
969   e8      fis  g     a   |
970   fis4         g         |
971   e16 fis g  a fis g a b |
972   a4           a         |
973
974   % Bar 3 ...
975 }
976
977 \score {
978   \new PianoStaff <<
979      \new Staff {
980        \global
981        <<
982          \relative c'' \voiceA
983          \\
984          \relative c'  \voiceB
985        >>
986      }
987      \new Staff {
988        \global \clef bass
989        <<
990          \relative c \voiceC
991          \\
992          \relative c \voiceD
993        >>
994      }
995   >>
996 }
997 @end lilypond
998
999
1000 @seealso
1001 Learning Manual:
1002 @rlearning{Organizing pieces with variables}.
1003
1004 Snippets:
1005 @rlsr{Simultaneous notes}.