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