]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/simultaneous.itely
bbe2b7ce3c71ed21c81f4376ba38e92444435fbc
[lilypond.git] / Documentation / notation / 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.  For details, see the Contributors'
7     Guide, node Updating translation committishes..
8 @end ignore
9
10 @c \version "2.12.0"
11
12
13 @node Simultaneous notes
14 @section Simultaneous notes
15
16 @lilypondfile[quote]{simultaneous-headword.ly}
17
18 Polyphony in music refers to having more than one voice occurring
19 in a piece of music.  Polyphony in LilyPond refers to having more
20 than one voice on the same staff.
21
22 @menu
23 * Single voice::
24 * Multiple voices::
25 @end menu
26
27
28 @node Single voice
29 @subsection Single voice
30
31 This section discusses simultaneous notes inside the same voice.
32
33 @menu
34 * Chorded notes::
35 * Chord repetition::
36 * Simultaneous expressions::
37 * Clusters::
38 @end menu
39
40
41 @node Chorded notes
42 @unnumberedsubsubsec Chorded notes
43
44 @cindex chords
45 @cindex brackets, angle
46
47 @funindex <
48 @funindex >
49 @funindex <...>
50
51 A chord is formed by enclosing a set of pitches between @code{<}
52 and @code{>}.  A chord may be followed by a duration just like simple
53 notes.
54
55 @lilypond[verbatim,quote,relative=2]
56 <a c e>1 <a c e>2 <f a c e>4 <a c>8. <g c e>16
57 @end lilypond
58
59 Chords may also be followed by articulations, again just like simple
60 notes.
61
62 @lilypond[verbatim,quote,relative=2]
63 <a c e>1\fermata <a c e>2-> <f a c e>4\prall <a c>8.^| <g c e>16-.
64 @end lilypond
65
66 The notes within the chord themselves can also be followed by articulation
67 and ornamentation.
68
69 @lilypond[verbatim,quote,relative=2]
70 <a c\prall e>1 <a-> c-^ e>2 <f-. a c-. e-.>4 <a-+ c-->8. <g\fermata c e\turn>16
71 @end lilypond
72
73 However some notation, such as dynamics, hairpins and slurs must be
74 attached to the chord, rather than notes within the chord, otherwise
75 they will not print.
76
77 @lilypond[verbatim,quote,relative=2]
78 <a\f c( e>1 <a c) e>\f <a\< c e>( <a\! c e>) <a c e>\< <a c e> <a c e>\!
79 @end lilypond
80
81 @cindex relative pitch, chords
82 @cindex chords, relative pitch
83
84 Relative mode can be used for pitches in chords.  The first note of
85 each chord is always relative to the first note of the chord that
86 came before it, or in the case where no preceding chord exists, the
87 pitch of the last note that came before the chord.  All remaining notes
88 in the chord are relative to the note that came before it
89 @emph{within the same chord}.
90
91 @lilypond[verbatim,quote,relative=2]
92 <a c e>1 <f a c> <a c e> <f' a c> <b, e b,>
93 @end lilypond
94
95 For more information about chords, see @ref{Chord notation}.
96
97 @seealso
98 Music Glossary:
99 @rglos{chord}.
100
101 Learning Manual:
102 @rlearning{Combining notes into chords}.
103
104 Notation Reference:
105 @ref{Chord notation},
106 @ref{Articulations and ornamentations},
107 @ref{Relative octave entry}.
108
109 Snippets:
110 @rlsr{Simultaneous notes}.
111
112
113 @node Chord repetition
114 @unnumberedsubsubsec Chord repetition
115
116 In order to save typing, a shortcut can be used to repeat the preceding
117 chord.  The chord repetition symbol is @code{q}:
118
119 @lilypond[verbatim,quote,relative=2]
120 <a c e>1 q <f a c>2 q
121 @end lilypond
122
123 As with regular chords, the chord repetition symbol can be used with
124 durations, articulations, markups, slurs, beams, etc. as only the
125 pitches of the previous chord are duplicated.
126
127 @lilypond[verbatim,quote,relative=2]
128 <a c e>1\p^"text" q2\<( q8)[-| q8.]\! q16-1-2-3 q8\prall
129 @end lilypond
130
131 The chord repetition symbol always remembers the last instance of
132 a chord so it is possible to repeat the most recent chord even if
133 other non-chorded notes or rests have been added since.
134
135 @lilypond[verbatim,quote,relative=2]
136 <a c e>1 c4 q2 r8 q8
137 @end lilypond
138
139 However, the chord repetition symbol does not retain any dynamics,
140 articulation or ornamentation within, or attached to the previous chord.
141
142 @lilypond[verbatim,quote,relative=2]
143 <a-. c\prall e>1\sfz c4 q2 r8 q8
144 @end lilypond
145
146 @seealso
147 Notation Reference:
148 @ref{Chord notation},
149 @ref{Articulations and ornamentations}.
150
151 Installed Files:
152 @file{ly/@/chord-repetition-init@/.ly}.
153
154
155 @node Simultaneous expressions
156 @unnumberedsubsubsec Simultaneous expressions
157
158 One or more music expressions enclosed in double angle brackets are
159 taken to be simultaneous.  If the first expression begins with a
160 single note or if the whole simultaneous expression appears
161 explicitly within a single voice, the whole expression is placed on
162 a single staff; otherwise the elements of the simultaneous
163 expression are placed on separate staves.
164
165 The following examples show simultaneous expressions on one staff:
166
167 @lilypond[quote,verbatim,relative=2]
168 \new Voice {  % explicit single voice
169   << { a4 b g2 } { d4 g c,2 } >>
170 }
171 @end lilypond
172
173 @lilypond[quote,verbatim,relative=2]
174 % single first note
175 a << { a4 b g } { d4 g c, } >>
176 @end lilypond
177
178 This can be useful if the simultaneous sections have identical
179 rhythms, but attempts to attach notes with different durations
180 to the same stem will cause errors.
181
182 The following example shows how simultaneous expressions can
183 generate multiple staves implicitly:
184
185 @lilypond[quote,verbatim,relative=2]
186 % no single first note
187 << { a4 b g2 } { d4 g2 c,4 } >>
188 @end lilypond
189
190 Here different rhythms cause no problems.
191
192
193 @node Clusters
194 @unnumberedsubsubsec Clusters
195
196 @cindex cluster
197 @cindex note cluster
198
199 @funindex \makeClusters
200 @funindex makeClusters
201
202 A cluster indicates a continuous range of pitches to be played.
203 They can be denoted as the envelope of a set of notes.  They are
204 entered by applying the function @code{\makeClusters} to a sequence
205 of chords, e.g.,
206
207 @lilypond[quote,relative=2,verbatim]
208 \makeClusters { <g b>2 <c g'> }
209 @end lilypond
210
211 Ordinary notes and clusters can be put together in the same staff,
212 even simultaneously.  In such a case no attempt is made to
213 automatically avoid collisions between ordinary notes and clusters.
214
215
216 @seealso
217 Music Glossary:
218 @rglos{cluster}.
219
220 Snippets:
221 @rlsr{Simultaneous notes}.
222
223 Internals Reference:
224 @rinternals{ClusterSpanner},
225 @rinternals{ClusterSpannerBeacon},
226 @rinternals{Cluster_spanner_engraver}.
227
228
229 @knownissues
230
231 Clusters look good only if they span at least two chords; otherwise
232 they appear too narrow.
233
234 Clusters do not have a stem and cannot indicate durations by
235 themselves, but the length of the printed cluster is determined by
236 the durations of the defining chords.  Separate clusters need a
237 separating rest between them.
238
239 Clusters do not produce MIDI output.
240
241 @node Multiple voices
242 @subsection Multiple voices
243
244 This section discusses simultaneous notes in multiple voices or
245 multiple staves.
246
247 @menu
248 * Single-staff polyphony::
249 * Voice styles::
250 * Collision resolution::
251 * Automatic part combining::
252 * Writing music in parallel::
253 @end menu
254
255
256 @node Single-staff polyphony
257 @unnumberedsubsubsec Single-staff polyphony
258
259 @cindex single-staff polyphony
260 @cindex polyphony, single-staff
261 @cindex voice
262 @cindex lyrics assigned to one voice
263
264 @funindex \voiceOne
265 @funindex voiceOne
266 @funindex \voiceOne ... \voiceFour
267 @funindex Voice
268 @funindex \oneVoice
269 @funindex oneVoice
270
271 @strong{@i{Explicitly instantiating voices}}
272
273 The basic structure needed to achieve multiple independent
274 voices in a single staff is illustrated in the following example:
275
276 @lilypond[quote,relative=3,verbatim]
277 \new Staff <<
278   \new Voice = "first"
279     { \voiceOne r8 r16 g e8. f16 g8[ c,] f e16 d }
280   \new Voice= "second"
281     { \voiceTwo d16 c d8~ d16 b c8~ c16 b c8~ c16 b8. }
282 >>
283 @end lilypond
284
285 @noindent
286 Here, voices are instantiated explicitly and are given names. The
287 @code{\voiceOne} ... @code{\voiceFour} commands set up the voices
288 so that first and third voices get stems up, second and fourth
289 voices get stems down, third and fourth voice note heads are
290 horizontally shifted, and rests in the respective voices are
291 automatically moved to avoid collisions.  The @code{\oneVoice}
292 command returns all the voice settings to the neutral default
293 directions.
294
295 @strong{@i{Temporary polyphonic passages}}
296
297 A temporary polyphonic passage can be created with the following
298 construct:
299
300 @example
301 << @{ \voiceOne ... @}
302   \new Voice @{ \voiceTwo ... @}
303 >> \oneVoice
304 @end example
305
306 @noindent
307 Here, the first expression within a temporary polyphonic passage is
308 placed into the @code{Voice} context which was in use immediately
309 before the polyphonic passage, and that same @code{Voice} context
310 continues after the temporary section.  Other expressions within
311 the angle brackets are assigned to distinct temporary voices.
312 This allows lyrics to be assigned to one continuing voice before,
313 during and after a polyphonic section:
314
315 @lilypond[quote, verbatim, relative=2]
316 <<
317   \new Voice = "melody" {
318     a4
319     <<
320       {
321         \voiceOne
322         g f
323       }
324       \new Voice {
325         \voiceTwo
326         d2
327       }
328     >>
329     \oneVoice
330     e4
331   }
332   \new Lyrics \lyricsto "melody" {
333   This is my song.
334   }
335 >>
336 @end lilypond
337
338 @noindent
339 Here, the @code{\voiceOne} and @code{\voiceTwo} commands are
340 required to define the settings of each voice.
341
342 @strong{@i{The double backslash construct}}
343
344 The @code{<< @{...@} \\ @{...@} >>} construct, where the two (or
345 more) expressions are separated by double backslashes, behaves
346 differently to the similar construct without the double backslashes:
347 @emph{all} the expressions within this construct are assigned
348 to new @code{Voice} contexts.  These new @code{Voice} contexts
349 are created implicitly and are given the fixed names @code{"1"},
350 @code{"2"}, etc.
351
352 The first example could be typeset as follows:
353
354 @lilypond[quote,relative=3,verbatim]
355 <<
356   { r8 r16 g e8. f16 g8[ c,] f e16 d }
357   \\
358   { d16 c d8~ d16 b c8~ c16 b c8~ c16 b8. }
359 >>
360 @end lilypond
361
362 This syntax can be used where it does not matter that temporary
363 voices are created and then discarded.  These implicitly created
364 voices are given the settings equivalent to the effect of the
365 @code{\voiceOne} ... @code{\voiceFour} commands, in the order in
366 which they appear in the code.
367
368 In the following example, the intermediate voice has stems up,
369 therefore we enter it in the third place, so it becomes voice
370 three, which has the stems up as desired.  Spacer rests are
371 used to avoid printing doubled rests.
372
373 @lilypond[quote,relative=3,verbatim]
374 <<
375   { r8 g g  g g f16 ees f8 d }
376   \\
377   { ees,8 r ees r d r d r }
378   \\
379   { d'8 s c s bes s a s }
380 >>
381 @end lilypond
382
383 In all but the simplest works it is advisable to create explicit
384 @code{Voice} contexts as explained in @rlearning{Contexts and engravers} and
385 @rlearning{Explicitly instantiating voices}.
386
387 @strong{@i{Identical rhythms}}
388
389 In the special case that we want to typeset parallel pieces of music
390 that have the same rhythm, we can combine them into a single
391 @code{Voice} context, thus forming chords.  To achieve this, enclose
392 them in a simple simultaneous music construct within an explicit voice:
393
394 @lilypond[quote,relative=2,verbatim]
395 \new Voice <<
396   { e4 f8 d e16 f g8 d4 }
397   { c4 d8 b c16 d e8 b4 }
398 >>
399 @end lilypond
400
401 This method leads to strange beamings and warnings if the pieces of
402 music do not have the same rhythm.
403
404
405 @predefined
406 @code{\voiceOne},
407 @code{\voiceTwo},
408 @code{\voiceThree},
409 @code{\voiceFour},
410 @code{\oneVoice}.
411 @endpredefined
412
413
414 @seealso
415 Learning Manual:
416 @rlearning{Voices contain music},
417 @rlearning{Explicitly instantiating voices}.
418
419 Notation Reference:
420 @ref{Percussion staves},
421 @ref{Invisible rests},
422 @ref{Stems}.
423
424 Snippets:
425 @rlsr{Simultaneous notes}.
426
427
428 @node Voice styles
429 @unnumberedsubsubsec Voice styles
430
431 @cindex voice styles
432 @cindex styles, voice
433 @cindex coloring voices
434 @funindex \voiceOneStyle
435 @funindex \voiceTwoStyle
436 @funindex \voiceThreeStyle
437 @funindex \voiceFourStyle
438 @funindex \voiceNeutralStyle
439
440 Voices may be given distinct colors and shapes, allowing them to be
441 easily identified:
442
443 @lilypond[quote,relative=2,verbatim]
444 <<
445   { \voiceOneStyle d4 c2 b4 }
446   \\
447   { \voiceTwoStyle e,2 e }
448   \\
449   { \voiceThreeStyle b2. c4 }
450   \\
451   { \voiceFourStyle g'2 g }
452 >>
453 @end lilypond
454
455 The @code{\voiceNeutralStyle} command is used to revert to the
456 standard presentation.
457
458
459 @predefined
460 @code{\voiceOneStyle},
461 @code{\voiceTwoStyle},
462 @code{\voiceThreeStyle},
463 @code{\voiceFourStyle},
464 @code{\voiceNeutralStyle}.
465 @endpredefined
466
467
468 @seealso
469 Learning Manual:
470 @rlearning{I'm hearing Voices},
471 @rlearning{Other sources of information}.
472
473 Snippets:
474 @rlsr{Simultaneous notes}.
475
476
477 @node Collision resolution
478 @unnumberedsubsubsec Collision resolution
479
480 @cindex merging notes
481 @cindex note collisions
482 @cindex collisions
483 @cindex shift note
484 @cindex multiple voices
485 @cindex voices, multiple
486 @cindex polyphonic music
487 @cindex shifting voices
488 @cindex voices, multiple
489 @cindex shift rest, automatic
490 @funindex \shiftOn
491 @funindex shiftOn
492 @funindex \shiftOnn
493 @funindex shiftOnn
494 @funindex \shiftOnnn
495 @funindex shiftOnnn
496 @funindex \shiftOff
497 @funindex shiftOff
498 @funindex \mergeDifferentlyDottedOn
499 @funindex mergeDifferentlyDottedOn
500 @funindex \mergeDifferentlyDottedOff
501 @funindex mergeDifferentlyDottedOff
502 @funindex \mergeDifferentlyHeadedOn
503 @funindex mergeDifferentlyHeadedOn
504 @funindex \mergeDifferentlyHeadedOff
505 @funindex mergeDifferentlyHeadedOff
506
507 The note heads of notes in different voices with the same pitch,
508 same note head and opposite stem direction are automatically
509 merged, but notes with different note heads or the same stem
510 direction are not.  Rests opposite a stem in a different voice
511 are shifted vertically.  The following example shows three
512 different circumstances, on beats 1 and 3 in bar 1 and beat 1
513 in bar 2, where the automatic merging fails.
514
515 @lilypond[quote,verbatim,relative=2]
516 <<
517   {
518     c8 d e d c d c4
519     g'2 fis
520   } \\ {
521     c2 c8. b16 c4
522     e,2 r
523   } \\ {
524     \oneVoice
525     s1
526     e8 a b c d2
527   }
528 >>
529 @end lilypond
530
531 Notes with different note heads may be merged, with the
532 exception of half-note heads and quarter-note heads, as shown
533 below.  Here the note heads on beat 1 of bar 1 are now merged:
534
535 @lilypond[quote,verbatim,relative=2]
536 <<
537   {
538     \mergeDifferentlyHeadedOn
539     c8 d e d c d c4
540     g'2 fis
541   } \\ {
542     c2 c8. b16 c4
543     e,2 r
544   } \\ {
545     \oneVoice
546     s1
547     e8 a b c d2
548   }
549 >>
550 @end lilypond
551
552 Note heads with different dots as shown in beat 3 of bar 1 may be
553 also be merged:
554
555 @lilypond[quote,relative=2,verbatim]
556 <<
557   {
558     \mergeDifferentlyHeadedOn
559     \mergeDifferentlyDottedOn
560     c8 d e d c d c4
561     g'2 fis
562   } \\ {
563     c2 c8. b16 c4
564     e,2 r
565   } \\ {
566     \oneVoice
567     s1
568     e8 a b c d2
569   }
570 >>
571 @end lilypond
572
573
574 The half note and eighth note at the start of the second measure
575 are incorrectly merged because the automatic merge cannot
576 successfully complete the merge when three or more notes line up in
577 the same note column, and in this case the merged note head is
578 incorrect.  To allow the merge to select the correct note head
579 a @code{\shift} must be applied to the note that should not be
580 merged.  Here, @code{\shiftOn} is applied to move the top
581 @notation{g} out of the column, and @code{\mergeDifferentlyHeadedOn}
582 then works properly.
583
584 @lilypond[quote,relative=2,verbatim]
585 <<
586   {
587     \mergeDifferentlyHeadedOn
588     \mergeDifferentlyDottedOn
589     c8 d e d c d c4
590     \shiftOn
591     g'2 fis
592   } \\ {
593     c2 c8. b16 c4
594     e,2 r
595   } \\ {
596     \oneVoice
597     s1
598     e8 a b c d2
599   }
600 >>
601 @end lilypond
602
603 The @code{\shiftOn}, @code{\shiftOnn}, and @code{\shiftOnnn}
604 commands specify the degree to which chords of the current voice
605 should be shifted.  The outer voices (normally: voices one and
606 two) have @code{\shiftOff}, while the inner voices (three and
607 four) have @code{\shiftOn}.  @code{\shiftOnn} and
608 @code{\shiftOnnn} define further shift levels.
609
610 Notes are only merged if they have opposing stem directions (as
611 they have, for example, in voices one and two by default or when
612 the stems are explicitly set in opposite directions).
613
614
615 @predefined
616 @code{\mergeDifferentlyDottedOn},
617 @code{\mergeDifferentlyDottedOff},
618 @code{\mergeDifferentlyHeadedOn},
619 @code{\mergeDifferentlyHeadedOff}.
620
621 @code{\shiftOn},
622 @code{\shiftOnn},
623 @code{\shiftOnnn},
624 @code{\shiftOff}.
625 @endpredefined
626
627
628 @snippets
629
630 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
631 {additional-voices-to-avoid-collisions.ly}
632
633 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
634 {forcing-horizontal-shift-of-notes.ly}
635
636
637 @seealso
638 Music Glossary:
639 @rglos{polyphony}.
640
641 Learning Manual:
642 @rlearning{Multiple notes at once},
643 @rlearning{Voices contain music},
644 @rlearning{Real music example}.
645
646 Snippets:
647 @rlsr{Simultaneous notes}.
648
649 Internals Reference:
650 @rinternals{NoteColumn},
651 @rinternals{NoteCollision},
652 @rinternals{RestCollision}.
653
654
655 @knownissues
656
657 @ignore
658 @c TODO investigate! Sometimes it works, sometimes not. --FV
659 The requirements for successfully merging different note heads that
660 are at the same time differently dotted are not clear.
661 @end ignore
662
663 There is no support for chords where the same note occurs with
664 different accidentals in the same chord.  In this case, it is
665 recommended to use enharmonic transcription, or to use special
666 cluster notation (see @ref{Clusters}).
667
668
669 @node Automatic part combining
670 @unnumberedsubsubsec Automatic part combining
671
672 @cindex automatic part combining
673 @cindex part combiner
674 @cindex combining parts
675 @cindex a due part
676 @cindex solo part
677 @funindex \partcombine
678 @funindex partcombine
679
680 Automatic part combining is used to merge two parts of music onto
681 a staff.  It is aimed at typesetting orchestral scores.  When the
682 two parts are identical for a period of time, only one is shown.
683 In places where the two parts differ, they are typeset as separate
684 voices, and stem directions are set automatically.  Also, solo and
685 @notation{a due} parts are identified and marked by default.
686
687 The syntax for part combining is:
688
689 @example
690 \partcombine @var{musicexpr1} @var{musicexpr2}
691 @end example
692
693 The following example demonstrates the basic functionality of the
694 part combiner: putting parts on one staff and setting stem
695 directions and polyphony.  The same variables are used for the
696 independent parts and the combined staff.
697
698 @lilypond[quote,verbatim]
699 instrumentOne = \relative c' {
700   c4 d e f
701   R1
702   d'4 c b a
703   b4 g2 f4
704   e1
705 }
706
707 instrumentTwo = \relative g' {
708   R1
709   g4 a b c
710   d c b a
711   g f( e) d
712   e1
713 }
714
715 <<
716   \new Staff \instrumentOne
717   \new Staff \instrumentTwo
718   \new Staff \partcombine \instrumentOne \instrumentTwo
719 >>
720 @end lilypond
721
722 The notes in the third measure appear only once, although they were
723 specified in both parts.  Stem, slur, and tie directions are set
724 automatically, depending whether there is a solo or unison.  When
725 needed in polyphony situations, the first part (with context called
726 @code{one}) always gets up stems, while the second (called @code{two})
727 always gets down stems.  In solo situations, the first and second
728 parts get marked with @q{Solo} and @q{Solo II}, respectively.  The
729 unisono (@notation{a due}) parts are marked by default with the text
730 @qq{a2}.
731
732 Both arguments to @code{\partcombine} will be interpreted as
733 @code{Voice} contexts.  If using relative octaves,
734 @code{\relative} should be specified for both music expressions,
735 i.e.,
736
737 @example
738 \partcombine
739   \relative @dots{} @var{musicexpr1}
740   \relative @dots{} @var{musicexpr2}
741 @end example
742
743 @noindent
744 A @code{\relative} section that is outside of @code{\partcombine}
745 has no effect on the pitches of @var{musicexpr1} and
746 @var{musicexpr2}.
747
748 @snippets
749
750 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
751 {combining-two-parts-on-the-same-staff.ly}
752
753 @lilypondfile[verbatim,lilyquote,texidoc,doctitle]
754 {changing-partcombine-texts.ly}
755
756
757 @seealso
758 Music Glossary:
759 @rglos{a due},
760 @rglos{part}.
761
762 Notation Reference:
763 @ref{Writing parts}.
764
765 Snippets:
766 @rlsr{Simultaneous notes}.
767
768 Internals Reference:
769 @rinternals{PartCombineMusic},
770 @rinternals{Voice}.
771
772
773 @knownissues
774
775 @code{\partcombine} can only accept two voices.
776
777 When @code{printPartCombineTexts} is set, if the two voices play
778 the same notes on and off, the part combiner may typeset @code{a2}
779 more than once in a measure.
780
781 @code{\partcombine} cannot be inside @code{\times}.
782
783 @code{\partcombine} cannot be inside @code{\relative}.
784
785 Internally, the @code{\partcombine} interprets both arguments as
786 @code{Voice}s and decides when the parts can be combined.  When they have
787 different durations they cannot be combined and are given the names
788 @code{one} and @code{two}.  Consequently, if the arguments switch to
789 differently named @rinternals{Voice} contexts, the events in those will
790 be ignored.  Likewise, partcombining isn't designed to work with lyrics;
791 when one of the voices is explicitly named in order to attach lyrics to
792 it, the partcombining stops working.
793
794 @code{\partcombine} only observes onset times of notes. It cannot
795 determine whether a previously started note is playing or not, leading
796 to various problems.
797
798
799 @node Writing music in parallel
800 @unnumberedsubsubsec Writing music in parallel
801
802 @cindex writing music in parallel
803 @cindex interleaved music
804 @cindex parallel music
805 @funindex \parallelMusic
806 @funindex parallelMusic
807
808 Music for multiple parts can be interleaved in input code.  The
809 function @code{\parallelMusic} accepts a list with the names of a
810 number of variables to be created, and a musical expression.  The
811 content of alternate measures from the expression become the value
812 of the respective variables, so you can use them afterwards to
813 print the music.
814
815 @warning{Bar checks @code{|} must be used, and the measures must
816 be of the same length.}
817
818 @lilypond[quote,verbatim]
819 \parallelMusic #'(voiceA voiceB voiceC) {
820   % Bar 1
821   r8 g'16 c'' e'' g' c'' e'' r8 g'16 c'' e'' g' c'' e'' |
822   r16 e'8.~   e'4            r16 e'8.~   e'4            |
823   c'2                        c'2                        |
824
825   % Bar 2
826   r8 a'16 d'' f'' a' d'' f'' r8 a'16 d'' f'' a' d'' f'' |
827   r16 d'8.~   d'4            r16 d'8.~   d'4            |
828   c'2                        c'2                        |
829
830 }
831 \new StaffGroup <<
832   \new Staff << \voiceA \\ \voiceB >>
833   \new Staff { \clef bass \voiceC }
834 >>
835 @end lilypond
836
837 Relative mode may be used.  Note that the @code{\relative} command
838 is not used inside @code{\parallelMusic} itself.  The notes are
839 relative to the preceding note in the voice, not to the previous
840 note in the input -- in other words, relative notes for
841 @code{voiceA} ignore the notes in @code{voiceB}.
842
843 @lilypond[quote,verbatim]
844 \parallelMusic #'(voiceA voiceB voiceC) {
845   % Bar 1
846   r8 g16 c e g, c e r8 g,16 c e g, c e  |
847   r16 e8.~ e4       r16 e8.~  e4        |
848   c2                c                   |
849
850   % Bar 2
851   r8 a,16 d f a, d f r8 a,16 d f a, d f |
852   r16 d8.~  d4       r16 d8.~  d4       |
853   c2                 c                  |
854
855  }
856 \new StaffGroup <<
857   \new Staff << \relative c'' \voiceA \\ \relative c' \voiceB >>
858   \new Staff \relative c' { \clef bass \voiceC }
859 >>
860 @end lilypond
861
862 This works quite well for piano music.  This example maps four
863 consecutive measures to four variables:
864
865 @lilypond[quote,verbatim]
866 global = {
867   \key g \major
868   \time 2/4
869 }
870
871 \parallelMusic #'(voiceA voiceB voiceC voiceD) {
872   % Bar 1
873   a8    b     c   d     |
874   d4          e         |
875   c16 d e fis d e fis g |
876   a4          a         |
877
878   % Bar 2
879   e8      fis  g     a   |
880   fis4         g         |
881   e16 fis g  a fis g a b |
882   a4           a         |
883
884   % Bar 3 ...
885 }
886
887 \score {
888   \new PianoStaff <<
889      \new Staff {
890        \global
891        <<
892          \relative c'' \voiceA
893          \\
894          \relative c'  \voiceB
895        >>
896      }
897      \new Staff {
898        \global \clef bass
899        <<
900          \relative c \voiceC
901          \\
902          \relative c \voiceD
903        >>
904      }
905   >>
906 }
907 @end lilypond
908
909
910 @seealso
911 Learning Manual:
912 @rlearning{Organizing pieces with variables}.
913
914 Snippets:
915 @rlsr{Simultaneous notes}.