]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/simultaneous.itely
Move fundamental voices stuff into Fundamental.
[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 * Explicitly instantiating voices::  
86 * Collision Resolution::        
87 * Automatic part combining::    
88 * Writing music in parallel::   
89 @end menu
90
91 @node Explicitly instantiating voices
92 @unnumberedsubsubsec Explicitly instantiating voices
93
94 @internalsref{Voice} contexts can also be instantiated manually
95 inside a @code{<< >>} block to create polyphonic music, using
96 @code{\voiceOne}, up to @code{\voiceFour} to assign stem
97 directions and a horizontal shift for each part.
98
99 Specifically,
100 @example
101 << \upper \\ \lower >>
102 @end example
103
104 @noindent
105 is equivalent to
106
107 @example
108 <<
109   \new Voice = "1" @{ \voiceOne \upper @}
110   \new Voice = "2" @{ \voiceTwo \lower @}
111 >>
112 @end example
113
114 The @code{\voiceXXX} commands set the direction of stems, slurs,
115 ties, articulations, text annotations, augmentation dots of dotted
116 notes, and fingerings.  @code{\voiceOne} and @code{\voiceThree}
117 make these objects point upwards, while @code{\voiceTwo} and
118 @code{\voiceFour} make them point downwards.  The command
119 @code{\oneVoice} will revert back to the normal setting.
120
121 An expression that appears directly inside a @code{<< >>} belongs
122 to the main voice.  This is useful when extra voices appear while
123 the main voice is playing.  Here is a more correct rendition of
124 the example from the previous section.  The crossed colored
125 noteheads demonstrate that the main melody is now in a single
126 voice context.
127
128 @lilypond[quote,ragged-right,verbatim]
129 \new Staff \relative c' {
130   \override NoteHead #'style = #'cross
131   \override NoteHead #'color = #red
132   c16 d e f
133   \voiceOne
134   <<
135     { g4 f e | d2 e2 }
136     \new Voice="1" { \voiceTwo
137       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
138       \oneVoice
139     }
140     \new Voice { \voiceThree
141       s2. | s4 b4 c2
142       \oneVoice
143     }
144   >>
145   \oneVoice
146 }
147 @end lilypond
148
149 The correct definition of the voices allows the melody to be
150 slurred.
151
152 @lilypond[quote,ragged-right,verbatim]
153 \new Staff \relative c' {
154   c16^( d e f
155   \voiceOne
156   <<
157     { g4 f e | d2 e2) }
158     \context Voice="1" { \voiceTwo
159       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2
160       \oneVoice
161     }
162     \new Voice { \voiceThree
163       s2. s4 b4 c2
164       \oneVoice
165     }
166   >>
167   \oneVoice
168 }
169 @end lilypond
170
171 Avoiding the @code{\\} separator also allows nesting polyphony
172 constructs, which in some case might be a more natural way to
173 typeset the music.
174
175 @lilypond[quote,ragged-right,verbatim]
176 \new Staff \relative c' {
177   c16^( d e f
178   \voiceOne
179   <<
180     { g4 f e | d2 e2) }
181     \context Voice="1" { \voiceTwo
182       r8 e4 d c8 ~ |
183       <<
184         {c8 b16 a b8 g ~ g2}
185         \new Voice { \voiceThree
186           s4 b4 c2
187           \oneVoice
188         }
189       >>
190     \oneVoice
191     }
192   >>
193   \oneVoice
194 }
195 @end lilypond
196
197 In some instances of complex polyphonic music, you may need
198 additional voices to avoid collisions between notes.  Additional
199 voices are added by defining an identifier, as shown below:
200
201 @lilypond[quote,verbatim,ragged-right,relative=2]
202 voiceFive = #(context-spec-music (make-voice-props-set 4) 'Voice)
203
204 \relative c''' <<
205   { \voiceOne g4 ~  \stemDown g32[ f( es d c b a b64 )g] } \\
206   { \voiceThree  b4} \\
207   { \voiceFive d,} \\
208   { \voiceTwo g,}
209 >>
210 @end lilypond
211
212
213 @node Collision Resolution
214 @unnumberedsubsubsec Collision Resolution
215
216 Normally, note heads with a different number of dots are not
217 merged, but when the object property
218 @code{merge-differently-dotted} is set in the
219 @internalsref{NoteCollision} object, they are merged:
220
221 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
222 \new Voice << {
223   g8 g8
224   \override Staff.NoteCollision
225     #'merge-differently-dotted = ##t
226   g8 g8
227 } \\ { g8.[ f16] g8.[ f16] } >>
228 @end lilypond
229
230 Similarly, you can merge half note heads with eighth notes, by
231 setting @code{merge-differently-headed}:
232
233 @lilypond[quote,ragged-right,fragment,relative=2,verbatim]
234 \new Voice << {
235   c8 c4.
236   \override Staff.NoteCollision
237     #'merge-differently-headed = ##t
238 c8 c4. } \\ { c2 c2 } >>
239 @end lilypond
240
241 @noindent
242 @code{merge-differently-headed} and
243 @code{merge-differently-dotted} only apply to opposing stem
244 directions (ie. Voice 1 & 2).
245
246 LilyPond also vertically shifts rests that are opposite of a stem,
247 for example
248
249 @lilypond[quote,ragged-right,fragment,verbatim]
250 \new Voice << c''4 \\ r4 >>
251 @end lilypond
252
253 If three or more notes line up in the same column,
254 @code{merge-differently-headed} cannot successfully complete the
255 merge of the two notes that should be merged.  To allow the merge
256 to work properly, apply a @code{\shift} to the note that should
257 not be merged.  In the first measure of following example,
258 @code{merge-differently-headed} does not work (the half-note head
259 is solid).  In the second measure, @code{\shiftOn} is applied to
260 move the top @code{g} out of the column, and
261 @code{merge-differently-headed} works properly.
262
263 @lilypond[quote,ragged-right,fragment,verbatim,relative=2]
264 \override Staff.NoteCollision #'merge-differently-headed = ##t
265 <<
266   { d=''2 g2 } \\
267   { \oneVoice d=''8 c8 r4 e,8 c'8 r4 } \\
268   { \voiceFour e,,2 e'2}
269 >>
270 <<
271   { d'=''2 \shiftOn g2 } \\ 
272   { \oneVoice d=''8 c8 r4 e,8 c'8 r4 } \\
273   { \voiceFour e,,2 e'2}
274 >>
275 @end lilypond
276
277
278 @refcommands
279
280 @funindex \oneVoice
281 @code{\oneVoice},
282 @funindex \voiceOne
283 @code{\voiceOne},
284 @funindex \voiceTwo
285 @code{\voiceTwo},
286 @funindex \voiceThree
287 @code{\voiceThree},
288 @funindex \voiceFour
289 @code{\voiceFour}.
290
291 @funindex \shiftOn
292 @code{\shiftOn},
293 @funindex \shiftOnn
294 @code{\shiftOnn},
295 @funindex \shiftOnnn
296 @code{\shiftOnnn},
297 @funindex \shiftOff
298 @code{\shiftOff}: these commands specify the degree to which
299 chords of the current voice should be shifted.  The outer voices
300 (normally: voice one and two) have @code{\shiftOff}, while the
301 inner voices (three and four) have @code{\shiftOn}.
302 @code{\shiftOnn} and @code{\shiftOnnn} define further shift
303 levels.
304
305 When LilyPond cannot cope, the @code{force-hshift} property of the
306 @internalsref{NoteColumn} object and pitched rests can be used to
307 override typesetting decisions.
308
309 @lilypond[quote,verbatim,ragged-right]
310 \relative <<
311 {
312   <d g>
313   <d g>
314 } \\ {
315   <b f'>
316   \once \override NoteColumn #'force-hshift = #1.7
317   <b f'>
318 } >>
319 @end lilypond
320
321
322 @seealso
323
324 Program reference: the objects responsible for resolving
325 collisions are @internalsref{NoteCollision} and
326 @internalsref{RestCollision}.
327
328
329 @refbugs
330
331 When using @code{merge-differently-headed} with an upstem eighth
332 or a shorter note, and a downstem half note, the eighth note gets
333 the wrong offset.
334
335 There is no support for clusters where the same note occurs with
336 different accidentals in the same chord.  In this case, it is
337 recommended to use enharmonic transcription, or to use special
338 cluster notation (see @ref{Clusters}).
339
340
341 @node Automatic part combining
342 @unnumberedsubsubsec Automatic part combining
343 @cindex automatic part combining
344 @cindex part combiner
345
346 Automatic part combining is used to merge two parts of music onto
347 a staff.  It is aimed at typesetting orchestral scores.  When the
348 two parts are identical for a period of time, only one is shown.
349 In places where the two parts differ, they are typeset as separate
350 voices, and stem directions are set automatically.  Also, solo and
351 @emph{a due} parts are identified and can be marked.
352
353 The syntax for part combining is
354
355 @example
356 \partcombine @var{musicexpr1} @var{musicexpr2}
357 @end example
358
359
360 The following example demonstrates the basic functionality of the
361 part combiner: putting parts on one staff, and setting stem
362 directions and polyphony
363
364 @lilypond[quote,verbatim,ragged-right,fragment]
365 \new Staff \partcombine
366   \relative g' { g g a( b) c c r r }
367   \relative g' { g g r4 r e e g g }
368 @end lilypond
369
370 The first @code{g} appears only once, although it was specified
371 twice (once in each part).  Stem, slur, and tie directions are set
372 automatically, depending whether there is a solo or unisono.  The
373 first part (with context called @code{one}) always gets up stems,
374 and @q{Solo}, while the second (called @code{two}) always gets
375 down stems and @q{Solo II}.
376
377 If you just want the merging parts, and not the textual markings,
378 you may set the property @code{printPartCombineTexts} to false
379
380 @lilypond[quote,verbatim,ragged-right,fragment,relative=2]
381 \new Staff <<
382   \set Staff.printPartCombineTexts = ##f
383   \partcombine
384     \relative g' { g a( b) r }
385     \relative g' { g r4 r f }
386 >>
387 @end lilypond
388
389 To change the text that is printed for solos or merging, you may
390 set the @code{soloText}, @code{soloIIText}, and @code{aDueText}
391 properties.
392
393 @lilypond[quote,verbatim,ragged-right,fragment,relative=2]
394 \new Staff <<
395   \set Score.soloText = #"ichi"
396   \set Score.soloIIText = #"ni"
397   \set Score.aDueText = #"tachi"
398   \partcombine
399     \relative g' { g4 g a( b) r }
400     \relative g' { g4 g r r f }
401 >>
402 @end lilypond
403
404 Both arguments to @code{\partcombine} will be interpreted as
405 @internalsref{Voice} contexts.  If using relative octaves,
406 @code{\relative} should be specified for both music expressions,
407 i.e.,
408
409 @example
410 \partcombine
411   \relative @dots{} @var{musicexpr1}
412   \relative @dots{} @var{musicexpr2}
413 @end example
414
415 @noindent
416 A @code{\relative} section that is outside of @code{\partcombine}
417 has no effect on the pitches of @var{musicexpr1} and
418 @var{musicexpr2}.
419
420 @seealso
421
422 Program reference: @internalsref{PartCombineMusic}.
423
424 @refbugs
425
426 When @code{printPartCombineTexts} is set, when the two voices play
427 the same notes on and off, the part combiner may typeset @code{a2}
428 more than once in a measure.
429
430 @code{\partcombine} cannot be inside @code{\times}.
431
432 @code{\partcombine} cannot be inside @code{\relative}.
433
434 Internally, the @code{\partcombine} interprets both arguments as
435 @code{Voice}s named @code{one} and @code{two}, and then decides
436 when the parts can be combined.  Consequently, if the arguments
437 switch to differently named @internalsref{Voice} contexts, the
438 events in those will be ignored.
439
440
441 @node Writing music in parallel
442 @unnumberedsubsubsec Writing music in parallel
443
444 @cindex Writing music in parallel
445 @cindex Interleaved music
446
447 Music for multiple parts can be interleaved
448
449 @lilypond[quote,fragment,verbatim]
450 \parallelMusic #'(voiceA voiceB) {
451   r8 g'16[ c''] e''[ g' c'' e''] r8 g'16[ c''] e''[ g' c'' e''] |
452   c'2                               c'2                         |
453   r8 a'16[ d''] f''[ a' d'' f''] r8 a'16[ d''] f''[ a' d'' f''] |
454   c'2                               c'2                         |
455 }
456 \new StaffGroup <<
457   \new Staff \new Voice \voiceA
458   \new Staff \new Voice \voiceB
459 >>
460 @end lilypond
461
462 This works quite well for piano music
463
464 @c  It would be nice if the first bar fit onto one 66-char line.
465 @c  Maybe simplify the example?  -gp
466 @lilypond[quote,verbatim]
467 music = {
468   \key c \major
469   \time 4/4
470   \parallelMusic #'(voiceA voiceB voiceC voiceD) {
471     % Bar 1
472     r8  g'16[ c''] e''[ g' c'' e'']
473       r8 g'16[ c''] e''[ g' c'' e''] |
474     c'2
475       c'2 |
476     r8  a16[ d'] f'[ a d' f']
477       r8  a16[ d'] f'[ a d' f'] |
478     c2
479       c2 |
480
481     % Bar 2
482     a'8 b'      c'' d''    e'' f''    g'' a'' |
483     d'4         d'         d'         d' |
484     c16 d e f   d e f g    e f g a    f g a b |
485     a,4         a,4        a,4        a,4 |
486
487     % Bar 3 ...
488   }
489 }
490
491 \score {
492   \new PianoStaff <<
493     \music
494     \new Staff <<
495       \voiceA \\
496       \voiceB
497     >>
498     \new Staff {
499       \clef bass
500       <<
501         \voiceC \\
502         \voiceD
503       >>
504     }
505   >>
506 }
507 @end lilypond
508
509
510