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