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