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