]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/simultaneous.itely
9f921c9732081a3078f64ba5ae0dddf425a2a7a2
[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 @node Simultaneous notes
10 @section Simultaneous notes
11
12 Polyphony in music refers to having more than one voice occurring
13 in a piece of music.  Polyphony in LilyPond refers to having more
14 than one voice on the same staff.
15
16 @menu
17 * Single voice::                
18 * Multiple voices::             
19 @end menu
20
21
22 @node Single voice
23 @subsection Single voice
24
25 @menu
26 * Chords::                      
27 * Clusters::                    
28 @end menu
29
30 @node Chords
31 @unnumberedsubsubsec Chords
32
33 @cindex Chords
34
35 A chord is formed by a enclosing a set of pitches between @code{<}
36 and @code{>}.  A chord may be followed by a duration, and a set of
37 articulations, just like simple notes
38
39 @lilypond[verbatim,ragged-right,fragment,quote,relative=1]
40 <c e g>4 <c>8
41 @end lilypond
42
43 For more information about chords, see @ref{Introducing chord
44 names}.
45
46
47 @node Clusters
48 @unnumberedsubsubsec Clusters
49
50 @cindex cluster
51
52 A cluster indicates a continuous range of pitches to be played.
53 They can be denoted as the envelope of a set of notes.  They are
54 entered by applying the function @code{makeClusters} to a sequence
55 of chords, e.g.,
56
57 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
58 \makeClusters { <c e > <b f'> }
59 @end lilypond
60
61 Ordinary notes and clusters can be put together in the same staff,
62 even simultaneously.  In such a case no attempt is made to
63 automatically avoid collisions between ordinary notes and
64 clusters.
65
66 @seealso
67
68 Program reference: @internalsref{ClusterSpanner},
69 @internalsref{ClusterSpannerBeacon},
70 @internalsref{Cluster_spanner_engraver}.
71
72 Examples: @lsr{contemporary,cluster@/.ly}.
73
74 @refbugs
75
76 Music expressions like @code{<< @{ g8 e8 @} a4 >>} are not printed
77 accurately.  Use @code{<g a>8 <e a>8} instead.
78
79
80
81 @node Multiple voices
82 @subsection Multiple voices
83
84 @menu
85 * Basic polyphony::             
86 * Explicitly instantiating voices::  
87 * Collision Resolution::        
88 * Automatic part combining::    
89 * Writing music in parallel::   
90 @end menu
91
92 @node Basic polyphony
93 @unnumberedsubsubsec Basic polyphony
94
95 @cindex polyphony
96
97 The easiest way to enter fragments with more than one voice on a
98 staff is to enter each voice as a sequence (with @code{@{...@}}),
99 and combine them simultaneously, separating the voices with
100 @code{\\}
101
102 @funindex \\
103
104 @lilypond[quote,verbatim,fragment]
105 \new Staff \relative c' {
106   c16 d e f
107   <<
108     { g4 f e | d2 e2 } \\
109     { r8 e4 d c8 ~ | c b16 a b8 g ~ g2 } \\
110     { s2. | s4 b4 c2 }
111   >>
112 }
113 @end lilypond
114
115 @cindex layers
116
117 The separator causes @internalsref{Voice}
118 contexts@footnote{Polyphonic voices are sometimes
119 called @q{layers} in other notation packages} to be instantiated.
120 They bear the names @code{"1"}, @code{"2"}, etc.  In each of these
121 contexts, vertical direction of slurs, stems, etc., is set
122 appropriately.
123
124 These voices are all separate from the voice that contains the
125 notes just outside the @code{<< \\ >>} construct.  This should be
126 noted when making changes at the voice level.  This also means
127 that slurs and ties cannot go into or out of a @code{<< \\ >>}
128 construct.  Conversely, parallel voices from separate @code{<< \\
129 >>} constructs on the same staff are the same voice.  Here is the
130 same example, with different noteheads and colors for each voice.
131 Note that the change to the note-head style in the main voice does
132 not affect the inside of the @code{<< \\ >>} constructs.  Also,
133 the change to the second voice in the first @code{<< \\ >>}
134 construct is effective in the second @code{<< \\ >>}, and the
135 voice is tied across the two constructs.
136
137 @cindex note heads, styles
138
139 @lilypond[quote,verbatim,fragment]
140 \new Staff \relative c' {
141   \override NoteHead #'style = #'cross
142   \override NoteHead #'color = #red
143   c16 d e f
144   <<
145     { g4 f e } \\
146     { \override NoteHead #'style = #'triangle
147       \override NoteHead #'color = #blue
148     r8 e4 d c8 ~ }
149   >> |
150   <<
151     { d2 e2 } \\
152     { c8 b16 a b8 g ~ g2 } \\
153     { \override NoteHead #'style = #'slash 
154       \override NoteHead #'color = #green
155       s4 b4 c2 }
156   >>
157 }
158 @end lilypond
159
160 Polyphony does not change the relationship of notes within a
161 @code{\relative @{ @}} block.  Each note is calculated relative to
162 the note immediately preceding it.
163
164 @example
165 \relative @{ noteA << noteB \\ noteC >> noteD @}
166 @end example
167
168 @code{noteC} is relative to @code{noteB}, not @code{noteA};
169 @code{noteD} is relative to @code{noteC}, not @code{noteB} or
170 @code{noteA}.
171
172
173 @node Explicitly instantiating voices
174 @unnumberedsubsubsec Explicitly instantiating voices
175
176 @internalsref{Voice} contexts can also be instantiated manually
177 inside a @code{<< >>} block to create polyphonic music, using
178 @code{\voiceOne}, up to @code{\voiceFour} to assign stem
179 directions and a horizontal shift for each part.
180
181 Specifically,
182 @example
183 << \upper \\ \lower >>
184 @end example
185
186 @noindent
187 is equivalent to
188
189 @example
190 <<
191   \new Voice = "1" @{ \voiceOne \upper @}
192   \new Voice = "2" @{ \voiceTwo \lower @}
193 >>
194 @end example
195
196 The @code{\voiceXXX} commands set the direction of stems, slurs,
197 ties, articulations, text annotations, augmentation dots of dotted
198 notes, and fingerings.  @code{\voiceOne} and @code{\voiceThree}
199 make these objects point upwards, while @code{\voiceTwo} and
200 @code{\voiceFour} make them point downwards.  The command
201 @code{\oneVoice} will revert back to the normal setting.
202
203 An expression that appears directly inside a @code{<< >>} belongs
204 to the main voice.  This is useful when extra voices appear while
205 the main voice is playing.  Here is a more correct rendition of
206 the example from the previous section.  The crossed colored
207 noteheads demonstrate that the main melody is now in a single
208 voice context.
209
210 @lilypond[quote,ragged-right,verbatim]
211 \new Staff \relative c' {
212   \override NoteHead #'style = #'cross
213   \override NoteHead #'color = #red
214   c16 d e f
215   \voiceOne
216   <<
217     { g4 f e | d2 e2 }
218     \new Voice="1" { \voiceTwo
219       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
220       \oneVoice
221     }
222     \new Voice { \voiceThree
223       s2. | s4 b4 c2
224       \oneVoice
225     }
226   >>
227   \oneVoice
228 }
229 @end lilypond
230
231 The correct definition of the voices allows the melody to be
232 slurred.
233
234 @lilypond[quote,ragged-right,verbatim]
235 \new Staff \relative c' {
236   c16^( d e f
237   \voiceOne
238   <<
239     { g4 f e | d2 e2) }
240     \context Voice="1" { \voiceTwo
241       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
242       \oneVoice
243     }
244     \new Voice { \voiceThree
245       s2. s4 b4 c2
246       \oneVoice
247     }
248   >>
249   \oneVoice
250 }
251 @end lilypond
252
253 Avoiding the @code{\\} separator also allows nesting polyphony
254 constructs, which in some case might be a more natural way to
255 typeset the music.
256
257 @lilypond[quote,ragged-right,verbatim]
258 \new Staff \relative c' {
259   c16^( d e f
260   \voiceOne
261   <<
262     { g4 f e | d2 e2) }
263     \context Voice="1" { \voiceTwo
264       r8 e4 d c8 ~ |
265       <<
266         {c8 b16 a b8 g ~ g2}
267         \new Voice { \voiceThree
268           s4 b4 c2
269           \oneVoice
270         }
271       >>
272     \oneVoice
273     }
274   >>
275   \oneVoice
276 }
277 @end lilypond
278
279 In some instances of complex polyphonic music, you may need
280 additional voices to avoid collisions between notes.  Additional
281 voices are added by defining an identifier, as shown below:
282
283 @lilypond[quote,verbatim,ragged-right,relative=2]
284 voiceFive = #(context-spec-music (make-voice-props-set 4) 'Voice)
285
286 \relative c''' <<
287   { \voiceOne g4 ~  \stemDown g32[ f( es d c b a b64 )g] } \\
288   { \voiceThree  b4} \\
289   { \voiceFive d,} \\
290   { \voiceTwo g,}
291 >>
292 @end lilypond
293
294
295 @node Collision Resolution
296 @unnumberedsubsubsec Collision Resolution
297
298 Normally, note heads with a different number of dots are not
299 merged, but when the object property
300 @code{merge-differently-dotted} is set in the
301 @internalsref{NoteCollision} object, they are merged:
302
303 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
304 \new Voice << {
305   g8 g8
306   \override Staff.NoteCollision
307     #'merge-differently-dotted = ##t
308   g8 g8
309 } \\ { g8.[ f16] g8.[ f16] } >>
310 @end lilypond
311
312 Similarly, you can merge half note heads with eighth notes, by
313 setting @code{merge-differently-headed}:
314
315 @lilypond[quote,ragged-right,fragment,relative=2,verbatim]
316 \new Voice << {
317   c8 c4.
318   \override Staff.NoteCollision
319     #'merge-differently-headed = ##t
320 c8 c4. } \\ { c2 c2 } >>
321 @end lilypond
322
323 @noindent
324 @code{merge-differently-headed} and
325 @code{merge-differently-dotted} only apply to opposing stem
326 directions (ie. Voice 1 & 2).
327
328 LilyPond also vertically shifts rests that are opposite of a stem,
329 for example
330
331 @lilypond[quote,ragged-right,fragment,verbatim]
332 \new Voice << c''4 \\ r4 >>
333 @end lilypond
334
335 If three or more notes line up in the same column,
336 @code{merge-differently-headed} cannot successfully complete the
337 merge of the two notes that should be merged.  To allow the merge
338 to work properly, apply a @code{\shift} to the note that should
339 not be merged.  In the first measure of following example,
340 @code{merge-differently-headed} does not work (the half-note head
341 is solid).  In the second measure, @code{\shiftOn} is applied to
342 move the top @code{g} out of the column, and
343 @code{merge-differently-headed} works properly.
344
345 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
346 \override Staff.NoteCollision #'merge-differently-headed = ##t
347 <<
348   { d=''2 g2 } \\
349   { \oneVoice d=''8 c8 r4 e,8 c'8 r4 } \\
350   { \voiceFour e,,2 e'2}
351 >>
352 <<
353   { d'=''2 \shiftOn g2 } \\ 
354   { \oneVoice d=''8 c8 r4 e,8 c'8 r4 } \\
355   { \voiceFour e,,2 e'2}
356 >>
357 @end lilypond
358
359
360 @refcommands
361
362 @funindex \oneVoice
363 @code{\oneVoice},
364 @funindex \voiceOne
365 @code{\voiceOne},
366 @funindex \voiceTwo
367 @code{\voiceTwo},
368 @funindex \voiceThree
369 @code{\voiceThree},
370 @funindex \voiceFour
371 @code{\voiceFour}.
372
373 @funindex \shiftOn
374 @code{\shiftOn},
375 @funindex \shiftOnn
376 @code{\shiftOnn},
377 @funindex \shiftOnnn
378 @code{\shiftOnnn},
379 @funindex \shiftOff
380 @code{\shiftOff}: these commands specify the degree to which
381 chords of the current voice should be shifted.  The outer voices
382 (normally: voice one and two) have @code{\shiftOff}, while the
383 inner voices (three and four) have @code{\shiftOn}.
384 @code{\shiftOnn} and @code{\shiftOnnn} define further shift
385 levels.
386
387 When LilyPond cannot cope, the @code{force-hshift} property of the
388 @internalsref{NoteColumn} object and pitched rests can be used to
389 override typesetting decisions.
390
391 @lilypond[quote,verbatim,ragged-right]
392 \relative <<
393 {
394   <d g>
395   <d g>
396 } \\ {
397   <b f'>
398   \once \override NoteColumn #'force-hshift = #1.7
399   <b f'>
400 } >>
401 @end lilypond
402
403
404 @seealso
405
406 Program reference: the objects responsible for resolving
407 collisions are @internalsref{NoteCollision} and
408 @internalsref{RestCollision}.
409
410
411 @refbugs
412
413 When using @code{merge-differently-headed} with an upstem eighth
414 or a shorter note, and a downstem half note, the eighth note gets
415 the wrong offset.
416
417 There is no support for clusters where the same note occurs with
418 different accidentals in the same chord.  In this case, it is
419 recommended to use enharmonic transcription, or to use special
420 cluster notation (see @ref{Clusters}).
421
422
423 @node Automatic part combining
424 @unnumberedsubsubsec Automatic part combining
425 @cindex automatic part combining
426 @cindex part combiner
427
428 Automatic part combining is used to merge two parts of music onto
429 a staff.  It is aimed at typesetting orchestral scores.  When the
430 two parts are identical for a period of time, only one is shown.
431 In places where the two parts differ, they are typeset as separate
432 voices, and stem directions are set automatically.  Also, solo and
433 @emph{a due} parts are identified and can be marked.
434
435 The syntax for part combining is
436
437 @example
438 \partcombine @var{musicexpr1} @var{musicexpr2}
439 @end example
440
441
442 The following example demonstrates the basic functionality of the
443 part combiner: putting parts on one staff, and setting stem
444 directions and polyphony
445
446 @lilypond[quote,verbatim,ragged-right,fragment]
447 \new Staff \partcombine
448   \relative g' { g g a( b) c c r r }
449   \relative g' { g g r4 r e e g g }
450 @end lilypond
451
452 The first @code{g} appears only once, although it was specified
453 twice (once in each part).  Stem, slur, and tie directions are set
454 automatically, depending whether there is a solo or unisono.  The
455 first part (with context called @code{one}) always gets up stems,
456 and @q{Solo}, while the second (called @code{two}) always gets
457 down stems and @q{Solo II}.
458
459 If you just want the merging parts, and not the textual markings,
460 you may set the property @code{printPartCombineTexts} to false
461
462 @lilypond[quote,verbatim,ragged-right,fragment,relative=2]
463 \new Staff <<
464   \set Staff.printPartCombineTexts = ##f
465   \partcombine
466     \relative g' { g a( b) r }
467     \relative g' { g r4 r f }
468 >>
469 @end lilypond
470
471 To change the text that is printed for solos or merging, you may
472 set the @code{soloText}, @code{soloIIText}, and @code{aDueText}
473 properties.
474
475 @lilypond[quote,verbatim,ragged-right,fragment,relative=2]
476 \new Staff <<
477   \set Score.soloText = #"ichi"
478   \set Score.soloIIText = #"ni"
479   \set Score.aDueText = #"tachi"
480   \partcombine
481     \relative g' { g4 g a( b) r }
482     \relative g' { g4 g r r f }
483 >>
484 @end lilypond
485
486 Both arguments to @code{\partcombine} will be interpreted as
487 @internalsref{Voice} contexts.  If using relative octaves,
488 @code{\relative} should be specified for both music expressions,
489 i.e.,
490
491 @example
492 \partcombine
493   \relative @dots{} @var{musicexpr1}
494   \relative @dots{} @var{musicexpr2}
495 @end example
496
497 @noindent
498 A @code{\relative} section that is outside of @code{\partcombine}
499 has no effect on the pitches of @var{musicexpr1} and
500 @var{musicexpr2}.
501
502 @seealso
503
504 Program reference: @internalsref{PartCombineMusic}.
505
506 @refbugs
507
508 When @code{printPartCombineTexts} is set, when the two voices play
509 the same notes on and off, the part combiner may typeset @code{a2}
510 more than once in a measure.
511
512 @code{\partcombine} cannot be inside @code{\times}.
513
514 @code{\partcombine} cannot be inside @code{\relative}.
515
516 Internally, the @code{\partcombine} interprets both arguments as
517 @code{Voice}s named @code{one} and @code{two}, and then decides
518 when the parts can be combined.  Consequently, if the arguments
519 switch to differently named @internalsref{Voice} contexts, the
520 events in those will be ignored.
521
522
523 @node Writing music in parallel
524 @unnumberedsubsubsec Writing music in parallel
525
526 @cindex Writing music in parallel
527 @cindex Interleaved music
528
529 Music for multiple parts can be interleaved
530
531 @lilypond[quote,fragment,verbatim]
532 \parallelMusic #'(voiceA voiceB) {
533   r8 g'16[ c''] e''[ g' c'' e''] r8 g'16[ c''] e''[ g' c'' e''] |
534   c'2                               c'2                         |
535   r8 a'16[ d''] f''[ a' d'' f''] r8 a'16[ d''] f''[ a' d'' f''] |
536   c'2                               c'2                         |
537 }
538 \new StaffGroup <<
539   \new Staff \new Voice \voiceA
540   \new Staff \new Voice \voiceB
541 >>
542 @end lilypond
543
544 This works quite well for piano music
545
546 @c  It would be nice if the first bar fit onto one 66-char line.
547 @c  Maybe simplify the example?  -gp
548 @lilypond[quote,verbatim]
549 music = {
550   \key c \major
551   \time 4/4
552   \parallelMusic #'(voiceA voiceB voiceC voiceD) {
553     % Bar 1
554     r8  g'16[ c''] e''[ g' c'' e'']
555       r8 g'16[ c''] e''[ g' c'' e''] |
556     c'2
557       c'2 |
558     r8  a16[ d'] f'[ a d' f']
559       r8  a16[ d'] f'[ a d' f'] |
560     c2
561       c2 |
562
563     % Bar 2
564     a'8 b'      c'' d''    e'' f''    g'' a'' |
565     d'4         d'         d'         d' |
566     c16 d e f   d e f g    e f g a    f g a b |
567     a,4         a,4        a,4        a,4 |
568
569     % Bar 3 ...
570   }
571 }
572
573 \score {
574   \new PianoStaff <<
575     \music
576     \new Staff <<
577       \voiceA \\
578       \voiceB
579     >>
580     \new Staff {
581       \clef bass
582       <<
583         \voiceC \\
584         \voiceD
585       >>
586     }
587   >>
588 }
589 @end lilypond
590
591
592