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