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