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