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