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