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