]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/simultaneous.itely
07be1d420b65127ce73b17700809decaec92ccdc
[lilypond.git] / Documentation / user / 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.  See TRANSLATION for details.
7 @end ignore
8
9 @c \version "2.11.51"
10
11
12 @node Simultaneous notes
13 @section Simultaneous notes
14
15 @lilypondfile[quote]{simultaneous-headword.ly}
16
17 Polyphony in music refers to having more than one voice occurring
18 in a piece of music.  Polyphony in LilyPond refers to having more
19 than one voice on the same staff.
20
21 @menu
22 * Single voice::
23 * Multiple voices::
24 @end menu
25
26
27 @node Single voice
28 @subsection Single voice
29
30 This section discusses simultaneous notes inside the same voice.
31
32 @menu
33 * Chorded notes::
34 * Clusters::
35 @end menu
36
37
38 @node Chorded notes
39 @unnumberedsubsubsec Chorded notes
40
41 @cindex chords
42 @cindex brackets, angle
43 @cindex relative pitch in chords
44 @funindex <
45 @funindex >
46 @funindex <...>
47
48 A chord is formed by a enclosing a set of pitches between @code{<} and
49 @code{>}.  A chord may be followed by a duration and/or a set of
50 articulations, just like simple notes:
51
52 @lilypond[verbatim,quote,relative=1]
53 <c e g>2 <c f a>4-> <e g c>-.
54 @end lilypond
55
56 Relative mode can be used for pitches in chords; the preceding pitch
57 into the same chord is still used as a reference for relative pitches,
58 but when a chord is completed, the reference pitch for relative mode
59 is the first note of this chord --not the last note of the chord.
60
61 For more information about chords, see @ref{Chord notation}.
62
63 @seealso
64
65 Music Glossary:
66 @rglos{chord}.
67
68 Learning Manual:
69 @rlearning{Combining notes into chords}.
70
71 Notation Reference:
72 @ref{Chord notation}.
73
74 Snippets:
75 @rlsr{Simultaneous notes}.
76
77 @ignore
78 @knownissues
79
80 For some reason, music expressions like @code{<< @{ g8 e8 @} a4 >>}
81 that should automatically turn into chords, appear split in two
82 staves.  To avoid this, use explicit chords instead as in
83 @code{<g a>8 <e a>8}.
84 @end ignore
85
86
87 @node Clusters
88 @unnumberedsubsubsec Clusters
89
90 @cindex cluster
91 @cindex note cluster
92 @funindex \makeClusters
93 @funindex makeClusters
94
95 A cluster indicates a continuous range of pitches to be played.  They
96 can be denoted as the envelope of a set of notes.  They are entered by
97 applying the function @code{\makeClusters} to a sequence of chords,
98 e.g.,
99
100 @lilypond[quote,relative=2,verbatim]
101 \makeClusters { <g b>2 <c g'> }
102 @end lilypond
103
104 Ordinary notes and clusters can be put together in the same staff,
105 even simultaneously.  In such a case no attempt is made to
106 automatically avoid collisions between ordinary notes and clusters.
107
108 @seealso
109
110 Music Glossary:
111 @rglos{cluster}.
112
113 Snippets:
114 @rlsr{Simultaneous notes}.
115
116 Internals Reference:
117 @rinternals{ClusterSpanner},
118 @rinternals{ClusterSpannerBeacon},
119 @rinternals{Cluster_spanner_engraver}.
120
121 @knownissues
122
123 Clusters look good only if they span at least two chords; otherwise
124 they appear too narrow.
125
126 Clusters do not have a stem and cannot indicate durations by
127 themselves.  Separate clusters would need a separating rest between
128 them.
129
130
131 @node Multiple voices
132 @subsection Multiple voices
133
134 This section discusses simultaneous notes in multiple voices or
135 multiple staves.
136
137 @menu
138 * Single-staff polyphony::
139 * Voice styles::
140 * Collision resolution::
141 * Automatic part combining::
142 * Writing music in parallel::
143 @end menu
144
145
146 @node Single-staff polyphony
147 @unnumberedsubsubsec Single-staff polyphony
148
149 @cindex single-staff polyphony
150 @cindex polyphony, single-staff
151 @cindex voice
152 @cindex lyrics assigned to one voice
153 @funindex \voiceOne
154 @funindex voiceOne
155 @funindex \voiceOne ... \voiceFour
156 @funindex Voice
157 @funindex \oneVoice
158 @funindex oneVoice
159
160 The basic structure of code needed to achieve multiple, independent
161 voices in a single staff is illustrated in the following example:
162
163 @lilypond[quote,relative=3,verbatim]
164 \new Staff <<
165   \new Voice = "first"
166     { \voiceOne r8 r16 g e8. f16 g8[ c,] f e16 d }
167   \new Voice= "second"
168     { \voiceTwo d16 c d8~ d16 b c8~ c16 b c8~ c16 b8. }
169 >>
170 @end lilypond
171
172 Here, voices are instantiated explicitly and are given a name. The
173 @code{\voiceOne} ... @code{\voiceFour} commands set up the voices so
174 that first and third voices get stems up, second and fourth voices get
175 stems down, third and fourth voice note heads are horizontally
176 shifted, and rests in the respective voices are automatically moved to
177 avoid collisions.  Using the @code{\oneVoice} command, all the voice
178 settings are put back to the neutral directions typical of a
179 single-voice passage.
180
181 We can make a voice to be in the same @code{Voice} context before
182 and after a temporary polyphonic passage.  For example, the following
183 construct keeps a voice alive throughout the polyphonic section.  Said
184 voice is the first one inside of the two-voice section, and the extra
185 voice is the second one.
186
187 @example
188 << @{ \voiceOne ... @} \new Voice @{ \voiceTwo ... @} >> \oneVoice
189 @end example
190
191 Using the name given when created, this allows lyrics to be assigned
192 to one consistent voice.
193
194 @lilypond[quote, verbatim, relative=2]
195 <<
196   \new Voice = "melody" {
197     a4
198     <<
199       {
200         \voiceOne
201         g f
202       }
203       \new Voice {
204         \voiceTwo
205         e d
206       }
207     >>
208     \oneVoice
209     e
210   }
211   \new Lyrics \lyricsto "melody" {
212   This is my song.
213   }
214 >>
215 @end lilypond
216
217 Here, the @code{\voiceOne} and @code{\voiceTwo} commands help to make clear what
218 settings does each voice receive.
219
220 The @code{<<@{...@} \\ @{...@}>>} construction, where the two (or
221 more) voices are separated by double backslashes, can be used as a
222 simplified method to print multiple voices in a single staff.  Our
223 first example could be typeset as follows:
224
225 @lilypond[quote,relative=3,verbatim]
226 <<
227   { r8 r16 g e8. f16 g8[ c,] f e16 d }
228   \\
229   { d16 c d8~ d16 b c8~ c16 b c8~ c16 b8. }
230 >>
231 @end lilypond
232
233 This syntax is simpler and can be used where it does not matter that
234 temporary voices are created and then discarded.  These implicitly
235 created voices are given the settings equivalent to the effect of the
236 @code{\voiceOne} ... @code{\voiceFour} commands, in the order in which
237 they appear in the code.  In the following example, the intermediate
238 voice has stems up, therefore we enter it in the third place, so it
239 becomes voice three which has the stems up as desired.
240
241 @lilypond[quote,relative=3,verbatim]
242 <<
243   { r8 g g  g g f16 es f8 d }
244   \\
245   { es,8 r es r d r d r }
246   \\
247   { d'8 s c s bes s a s }
248 >>
249 @end lilypond
250
251 Spacer rests are often used to avoid too many rests, as seen in the
252 example above.
253
254 In all but simplest works it is advisable to create explicit
255 @code{Voice} contexts using the @code{\new} and @code{\context}
256 commands as it is explained in @rlearning{Contexts and engravers} and
257 @rlearning{Explicitly instantiating voices}.
258
259 In the special case that we want to typeset parallel pieces of music
260 that have the same rhythm, we can combine them into a single
261 @code{Voice} context, thus forming chords.  To achieve this, enclose
262 them in a simple simultaneous music construction and make it to be an
263 explicit voice:
264
265 @lilypond[quote,relative=2,verbatim]
266 \new Voice <<
267   { e4 f8 d e16 f g8 d4 }
268   { c4 d8 b c16 d e8 b4 }
269 >>
270 @end lilypond
271
272 This method leads to strange beamings and warnings if the pieces of
273 music do not have the same rhythm.
274
275 @predefined
276
277 @code{\voiceOne},
278 @code{\voiceTwo},
279 @code{\voiceThree},
280 @code{\voiceFour},
281 @code{\oneVoice}.
282
283 @seealso
284
285 Learning Manual:
286 @rlearning{Voices contain music},
287 @rlearning{Explicitly instantiating voices}.
288
289 Notation Reference:
290 @ref{Percussion staves},
291 @ref{Invisible rests}.
292
293 Snippets:
294 @rlsr{Simultaneous notes}.
295
296
297 @node Voice styles
298 @unnumberedsubsubsec Voice styles
299
300 @cindex voice styles
301 @cindex styles, voice
302 @cindex coloring voices
303 @funindex \voiceOneStyle
304 @funindex \voiceTwoStyle
305 @funindex \voiceThreeStyle
306 @funindex \voiceFourStyle
307 @funindex \voiceNeutralStyle
308
309 Voices may be given distinct colors and shapes, allowing them to be
310 easily identified:
311
312 @lilypond[quote,relative=2,verbatim]
313 <<
314   { \voiceOneStyle d4 c2 b4 }
315   \\
316   { \voiceTwoStyle e,2 e }
317   \\
318   { \voiceThreeStyle b2. c4 }
319   \\
320   { \voiceFourStyle g'2 g }
321 >>
322 @end lilypond
323
324 To revert the standard presentation, the @code{\voiceNeutralstyle}
325 command is used.
326
327 @predefined
328
329
330 @code{\voiceOneStyle},
331
332 @code{\voiceTwoStyle},
333 @code{\voiceThreeStyle},
334 @code{\voiceFourStyle},
335 @code{\voiceNeutralStyle}.
336
337 @seealso
338
339 Learning Manual:
340 @rlearning{I'm hearing Voices},
341 @rlearning{Other sources of information}.
342
343 Snippets:
344 @rlsr{Simultaneous notes}.
345
346
347 @node Collision resolution
348 @unnumberedsubsubsec Collision resolution
349
350 @cindex merging notes
351 @cindex note collisions
352 @cindex collisions
353 @cindex shift note
354 @cindex multiple voices
355 @cindex voices, multiple
356 @cindex polyphonic music
357 @cindex shifting voices
358 @cindex voices, multiple
359 @cindex shift rest, automatic
360 @funindex \shiftOn
361 @funindex shiftOn
362 @funindex \shiftOnn
363 @funindex shiftOnn
364 @funindex \shiftOnnn
365 @funindex shiftOnnn
366 @funindex \shiftOff
367 @funindex shiftOff
368 @funindex \mergeDifferentlyDottedOn
369 @funindex mergeDifferentlyDottedOn
370 @funindex \mergeDifferentlyDottedOff
371 @funindex mergeDifferentlyDottedOff
372 @funindex \mergeDifferentlyHeadedOn
373 @funindex mergeDifferentlyHeadedOn
374 @funindex \mergeDifferentlyHeadedOff
375 @funindex mergeDifferentlyHeadedOff
376
377 Note heads with equal durations are automatically merged, while
378 note heads with unequal durations are not merged.  Rests opposite
379 a stem are shifted vertically.
380
381 @lilypond[quote,verbatim,relative=2]
382 <<
383   {
384     c8 d e d c d c4
385     g'2 fis
386   } \\ {
387     c2 c8. b16 c4
388     e,2 r
389   } \\ {
390     \oneVoice
391     s1
392     e8 a b c d2
393   }
394 >>
395 @end lilypond
396
397 Note heads with different note heads may be merged, with the
398 exception of half-note heads and quarter-note heads:
399
400 @lilypond[quote,verbatim,relative=2]
401 <<
402   {
403     \mergeDifferentlyHeadedOn
404     c8 d e d c d c4
405     g'2 fis
406   } \\ {
407     c2 c8. b16 c4
408     e,2 r
409   } \\ {
410     \oneVoice
411     s1
412     e8 a b c d2
413   }
414 >>
415 @end lilypond
416
417 Note heads with different dots may be merged:
418
419 @lilypond[quote,relative=2,verbatim]
420 <<
421   {
422     \mergeDifferentlyHeadedOn
423     \mergeDifferentlyDottedOn
424     c8 d e d c d c4
425     g'2 fis
426   } \\ {
427     c2 c8. b16 c4
428     e,2 r
429   } \\ {
430     \oneVoice
431     s1
432     e8 a b c d2
433   }
434 >>
435 @end lilypond
436
437
438 The collision on the second measure happens because
439 @code{\mergeDifferentlyHeadedOn} cannot successfully complete the
440 merge when three or more notes line up in the same column -- in
441 fact, you will obtain a warning for this reason.  To allow the
442 merge to work properly, apply a @code{\shift} to the note that
443 should not be merged.  Here, @code{\shiftOn} is applied to move
444 the top @code{g} out of the column, and
445 @code{\mergeDifferentlyHeadedOn} works properly.
446
447 @lilypond[quote,relative=2,verbatim]
448 <<
449   {
450     \mergeDifferentlyHeadedOn
451     \mergeDifferentlyDottedOn
452     c8 d e d c d c4
453     \shiftOn
454     g'2 fis
455   } \\ {
456     c2 c8. b16 c4
457     e,2 r
458   } \\ {
459     \oneVoice
460     s1
461     e8 a b c d2
462   }
463
464 >>
465 @end lilypond
466
467 The @code{\shiftOn}, @code{\shiftOnn}, and @code{\shiftOnnn}
468 commands specify the degree to which chords of the current voice
469 should be shifted.  The outer voices (normally: voices one and
470 two) have @code{\shiftOff}, while the inner voices (three and
471 four) have @code{\shiftOn}.  @code{\shiftOnn} and
472 @code{\shiftOnnn} define further shift levels.
473
474 Notes are only merged if they have opposing stem directions (i.e., in
475 @code{Voice} 1 and 2).
476
477
478 @predefined
479
480 @code{\mergeDifferentlyDottedOn},
481 @code{\mergeDifferentlyDottedOff},
482 @code{\mergeDifferentlyHeadedOn},
483 @code{\mergeDifferentlyHeadedOff}.
484
485 @code{\shiftOn},
486 @code{\shiftOnn},
487 @code{\shiftOnnn},
488 @code{\shiftOff}.
489
490 @snippets
491
492 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
493 {additional-voices-to-avoid-collisions.ly}
494
495 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
496 {forcing-horizontal-shift-of-notes.ly}
497
498 @seealso
499
500 Music Glossary:
501 @rglos{polyphony}.
502
503 Learning Manual:
504 @rlearning{Multiple notes at once},
505 @rlearning{Voices contain music},
506 @rlearning{Collisions of objects}.
507
508 Snippets:
509 @rlsr{Simultaneous notes}.
510
511 Internals Reference:
512 @rinternals{NoteColumn},
513 @rinternals{NoteCollision},
514 @rinternals{RestCollision}.
515
516 @knownissues
517
518 When using @code{\mergeDifferentlyHeadedOn} with an upstem eighth
519 or a shorter note, and a downstem half note, the eighth note stem
520 gets a slightly wrong offset because of the different width of the
521 half note head symbol.
522
523 @c investigate! Sometimes it works, sometimes not. --FV
524 The requirements for successfully merging different note heads that
525 are at the same time differently dotted are not clear.
526
527 There is no support for chords where the same note occurs with
528 different accidentals in the same chord.  In this case, it is
529 recommended to use enharmonic transcription, or to use special
530 cluster notation (see @ref{Clusters}).
531
532
533 @node Automatic part combining
534 @unnumberedsubsubsec Automatic part combining
535
536 @cindex automatic part combining
537 @cindex part combiner
538 @cindex combining parts
539 @cindex a due part
540 @cindex solo part
541 @funindex \partcombine
542 @funindex partcombine
543
544 Automatic part combining is used to merge two parts of music onto
545 a staff.  It is aimed at typesetting orchestral scores.  When the
546 two parts are identical for a period of time, only one is shown.
547 In places where the two parts differ, they are typeset as separate
548 voices, and stem directions are set automatically.  Also, solo and
549 @notation{a due} parts are identified and marked by default.
550
551 The syntax for part combining is:
552
553 @example
554 \partcombine @var{musicexpr1} @var{musicexpr2}
555 @end example
556
557 The following example demonstrates the basic functionality of the
558 part combiner: putting parts on one staff and setting stem
559 directions and polyphony.  The same variables are used for the
560 independent parts and the combined staff.
561
562 @lilypond[quote,verbatim]
563 instrumentOne = \relative c' {
564   c4 d e f
565   R1
566   d'4 c b a
567   b4 g2 f4
568   e1
569 }
570
571 instrumentTwo = \relative g' {
572   R1
573   g4 a b c
574   d c b a
575   g f( e) d
576   e1
577 }
578
579 <<
580   \new Staff \instrumentOne
581   \new Staff \instrumentTwo
582   \new Staff \partcombine \instrumentOne \instrumentTwo
583 >>
584 @end lilypond
585
586 The notes in the third measure appear only once, although they were
587 specified in both parts.  Stem, slur, and tie directions are set
588 automatically, depending whether there is a solo or unison.  When
589 needed in polyphony situations, the first part (with context called
590 @code{one}) always gets up stems, while the second (called @code{two})
591 always gets down stems.  In solo situations, the first and second
592 parts get marked with @q{Solo} and @q{Solo II}, respectively.  The
593 unisono (@notation{a due}) parts are marked by default with the text
594 @qq{a2}.
595
596 Both arguments to @code{\partcombine} will be interpreted as
597 @code{Voice} contexts.  If using relative octaves,
598 @code{\relative} should be specified for both music expressions,
599 i.e.,
600
601 @example
602 \partcombine
603   \relative @dots{} @var{musicexpr1}
604   \relative @dots{} @var{musicexpr2}
605 @end example
606
607 @noindent
608 A @code{\relative} section that is outside of @code{\partcombine}
609 has no effect on the pitches of @var{musicexpr1} and
610 @var{musicexpr2}.
611
612 @snippets
613
614 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
615 {combining-two-parts-on-the-same-staff.ly}
616
617 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
618 {changing-partcombine-texts.ly}
619
620 @seealso
621
622 Music Glossary:
623 @rglos{a due},
624 @rglos{part}.
625
626 Notation Reference:
627 @ref{Writing parts}.
628
629 Snippets:
630 @rlsr{Simultaneous notes}.
631
632 Internals Reference:
633 @rinternals{PartCombineMusic},
634 @rinternals{Voice}.
635
636 @knownissues
637
638 When @code{printPartCombineTexts} is set, if the two voices play
639 the same notes on and off, the part combiner may typeset @code{a2}
640 more than once in a measure.
641
642 @code{\partcombine} cannot be inside @code{\times}.
643
644 @code{\partcombine} cannot be inside @code{\relative}.
645
646 Internally, the @code{\partcombine} interprets both arguments as
647 @code{Voice}s named @code{one} and @code{two}, and then decides
648 when the parts can be combined.  Consequently, if the arguments
649 switch to differently named @rinternals{Voice} contexts, the
650 events in those will be ignored.
651
652 @c IIRC in users list someone pointed out more issues. TODO: lookup FV
653
654
655 @node Writing music in parallel
656 @unnumberedsubsubsec Writing music in parallel
657
658 @cindex writing music in parallel
659 @cindex interleaved music
660 @cindex parallel music
661 @funindex \parallelMusic
662 @funindex parallelMusic
663
664 Music for multiple parts can be interleaved in input code.  The
665 function @code{\parallelMusic} accepts a list with the names of a
666 number of variables to be created, and a musical expression.  The
667 content of alternate measures from the expression become the value
668 of the respective variables, so you can use them afterwards to
669 print the music.
670
671 @warning{Bar checks @code{|} must be used, and the measures must
672 be of the same length.}
673
674 @lilypond[quote,verbatim]
675 \parallelMusic #'(voiceA voiceB voiceC) {
676   % Bar 1
677   r8 g'16 c'' e'' g' c'' e'' r8 g'16 c'' e'' g' c'' e'' |
678   r16 e'8.~   e'4            r16 e'8.~   e'4            |
679   c'2                        c'2                        |
680
681   % Bar 2
682   r8 a'16 d'' f'' a' d'' f'' r8 a'16 d'' f'' a' d'' f'' |
683   r16 d'8.~   d'4            r16 d'8.~   d'4            |
684   c'2                        c'2                        |
685
686 }
687 \new StaffGroup <<
688   \new Staff << \voiceA \\ \voiceB >>
689   \new Staff { \clef bass \voiceC }
690 >>
691 @end lilypond
692
693 Relative mode may be used.  Note that the @code{\relative} command
694 is not used inside @code{\parallelMusic} itself.  The notes are
695 relative to the preceding note in the voice, not to the previous
696 note in the input -- in other words, relative notes for
697 @code{voiceA} ignore the notes in @code{voiceB}.
698
699 @lilypond[quote,verbatim]
700 \parallelMusic #'(voiceA voiceB voiceC) {
701   % Bar 1
702   r8 g16 c e g, c e r8 g,16 c e g, c e  |
703   r16 e8.~ e4       r16 e8.~  e4        |
704   c2                c                   |
705
706   % Bar 2
707   r8 a,16 d f a, d f r8 a,16 d f a, d f |
708   r16 d8.~  d4       r16 d8.~  d4       |
709   c2                 c                  |
710
711  }
712 \new StaffGroup <<
713   \new Staff << \relative c'' \voiceA \\ \relative c' \voiceB >>
714   \new Staff \relative c' { \clef bass \voiceC }
715 >>
716 @end lilypond
717
718 This works quite well for piano music.  This example maps four
719 consecutive measures to four variables:
720
721 @lilypond[quote,verbatim]
722 global = {
723   \key g \major
724   \time 2/4
725 }
726
727 \parallelMusic #'(voiceA voiceB voiceC voiceD) {
728   % Bar 1
729   a8    b     c   d     |
730   d4          e         |
731   c16 d e fis d e fis g |
732   a4          a         |
733
734   % Bar 2
735   e8      fis  g     a   |
736   fis4         g         |
737   e16 fis g  a fis g a b |
738   a4           a         |
739
740   % Bar 3 ...
741 }
742
743 \score {
744   \new PianoStaff <<
745      \new Staff {
746        \global
747        <<
748          \relative c'' \voiceA
749          \\
750          \relative c'  \voiceB
751        >>
752      }
753      \new Staff {
754        \global \clef bass
755        <<
756          \relative c \voiceC
757          \\
758          \relative c \voiceD
759        >>
760      }
761   >>
762 }
763 @end lilypond
764
765 @seealso
766
767 Learning Manual:
768 @rlearning{Organizing pieces with variables}.
769
770 Snippets:
771 @rlsr{Simultaneous notes}.