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