]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/simultaneous.itely
Merge branch 'master' into beaming
[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 @c \version "2.11.38"
10
11 @node Simultaneous notes
12 @section Simultaneous notes
13
14 @lilypondfile[quote]{simultaneous-headword.ly}
15
16 Polyphony in music refers to having more than one voice occurring
17 in a piece of music.  Polyphony in LilyPond refers to having more
18 than one voice on the same staff.
19
20 @menu
21 * Single voice::                
22 * Multiple voices::             
23 @end menu
24
25
26 @node Single voice
27 @subsection Single voice
28
29 @menu
30 * Chorded notes::                      
31 * Clusters::                    
32 @end menu
33
34 @node Chorded notes
35 @subsubsection Chorded notes
36
37 @cindex chords
38 @cindex brackets, angle
39 @funindex <
40 @funindex >
41 @funindex <...>
42
43 A chord is formed by a enclosing a set of pitches between @code{<} and
44 @code{>}.  A chord may be followed by a duration and/or a set of
45 articulations, just like simple notes:
46
47 @lilypond[verbatim,quote,relative=1]
48 <c e g>2 <c f a>4-> <e g c>-.
49 @end lilypond
50
51 For more information about chords, see @ref{Chord notation}.
52
53 @seealso
54
55 Music Glossary:
56 @rglos{chord}.
57
58 Learning Manual:
59 @rlearning{Combining notes into chords}.
60
61 Notation Reference:
62 @ref{Chord notation}.
63
64 Snippets:
65 @rlsr{Simultaneous notes}.
66
67 @knownissues
68
69 For some reason, music expressions like @code{<< @{ g8 e8 @} a4 >>}
70 that should automatically turn into chords, appear splitted in two
71 staves.  To avoid this, use explicit chords instead as in
72 @code{<g a>8 <e a>8}.
73
74
75 @node Clusters
76 @subsubsection Clusters
77
78 @cindex cluster
79 @funindex \makeClusters
80
81 A cluster indicates a continuous range of pitches to be played.  They
82 can be denoted as the envelope of a set of notes.  They are entered by
83 applying the function @code{\makeClusters} to a sequence of chords,
84 e.g.,
85
86 @lilypond[quote,relative=2,verbatim]
87 \makeClusters { <g b>2 <c g'> }
88 @end lilypond
89
90 Ordinary notes and clusters can be put together in the same staff,
91 even simultaneously.  In such a case no attempt is made to
92 automatically avoid collisions between ordinary notes and clusters.
93
94 @seealso
95
96 Music Glossary:
97 @rglos{cluster}.
98
99 Snippets:
100 @rlsr{Simultaneous notes}.
101
102 Internals Reference:
103 @rinternals{ClusterSpanner},
104 @rinternals{ClusterSpannerBeacon},
105 @rinternals{Cluster_spanner_engraver}.
106
107 @knownissues
108
109 Clusters only look good if they span at least two chords; otherwise
110 they appear too narrow.
111
112 Clusters do not have a stem and can not indicate durations by
113 themselves.  Separate clusters would need a separating rest between
114 them.
115
116 @node Multiple voices
117 @subsection Multiple voices
118
119 @menu
120 * Collision resolution::        
121 * Automatic part combining::    
122 * Writing music in parallel::   
123 @end menu
124
125 @node Collision resolution
126 @subsubsection Collision resolution
127
128 @cindex merging notes
129 @cindex note collisions
130 @cindex collisions
131 @funindex \shiftOn
132 @funindex \shiftOnn
133 @funindex \shiftOnnn
134 @funindex \shiftOff
135 @cindex shift rest, automatic
136
137 Note heads with equal durations are automatically merged, while
138 note heads with unequal durations are not merged.  Rests opposite
139 a stem are shifted vertically.
140
141 @lilypond[quote,verbatim,relative=2]
142 <<
143   {
144     c8 d e d c d c4
145     g'2 fis
146   } \\ {
147     c2 c8. b16 c4
148     e,2 r
149   } \\ {
150     \oneVoice
151     s1
152     e8 a b c d2
153   }
154 >>
155 @end lilypond
156
157 Note heads with different note heads may be merged, with the exception
158 of half-note heads and quarter-note heads:
159
160 @lilypond[quote,verbatim,relative=2]
161 <<
162   {
163     \override Staff.NoteCollision #'merge-differently-headed = ##t
164     c8 d e d c d c4
165     g'2 fis
166   } \\ {
167     c2 c8. b16 c4
168     e,2 r
169   } \\ {
170     \oneVoice
171     s1
172     e8 a b c d2
173   }
174 >>
175 @end lilypond
176
177 Note heads with different dots may be merged:
178
179 @lilypond[quote,relative=2,verbatim]
180 <<
181   {
182     \override Staff.NoteCollision #'merge-differently-headed = ##t
183     \override Staff.NoteCollision #'merge-differently-dotted = ##t      
184     c8 d e d c d c4
185     g'2 fis
186   } \\ {
187     c2 c8. b16 c4
188     e,2 r
189   } \\ {
190     \oneVoice
191     s1
192     e8 a b c d2
193   }
194 >>
195 @end lilypond
196
197 @cindex shift note
198
199 The collision on the second measure happens because
200 @code{merge-differently-headed} cannot successfully complete the merge
201 when three or more notes line up in the same column (in fact, you will
202 obtain a warning for this reason).  To allow the merge to work
203 properly, apply a @code{\shift} to the note that should not be merged.
204 Here, @code{\shiftOn} is applied to move the top @code{g} out of the
205 column, and @code{merge-differently-headed} works properly.
206
207 @lilypond[quote,relative=2,verbatim]
208 <<
209   {
210     \override Staff.NoteCollision #'merge-differently-headed = ##t
211     \override Staff.NoteCollision #'merge-differently-dotted = ##t      
212     c8 d e d c d c4
213     \shiftOn
214     g'2 fis
215   } \\ {
216     c2 c8. b16 c4
217     e,2 r
218   } \\ {
219     \oneVoice
220     s1
221     e8 a b c d2
222   }
223
224 >>
225 @end lilypond
226
227 Notes are only merged if they have opposing stem directions (i.e., in
228 @code{Voice} 1 and 2).
229
230 @cindex multiple voices
231 @cindex polyphonic music
232 @cindex shifting voices
233
234 In some instances of complex polyphonic music, you may need
235 additional voices to avoid collisions between notes.  Additional
236 voices are added by defining an variable, as shown below:
237
238 @lilypond[quote,verbatim]
239 voiceFive = #(context-spec-music (make-voice-props-set 4) 'Voice)
240 \relative c'''
241 << 
242   { \voiceOne g2. ~ \stemDown g32[ f( es d c b a b64) g] } \\
243   { \voiceThree b4 } \\
244   { \voiceFive d,  } \\
245   { \voiceTwo g,   }
246 >>
247 @end lilypond
248
249
250 @predefined
251
252 @funindex \oneVoice
253 @code{\oneVoice},
254 @funindex \voiceOne
255 @code{\voiceOne},
256 @funindex \voiceTwo
257 @code{\voiceTwo},
258 @funindex \voiceThree
259 @code{\voiceThree},
260 @funindex \voiceFour
261 @code{\voiceFour}.
262
263 @c undocumented?: --FV
264 @funindex \voiceNeutralStyle
265 @funindex \voiceOneStyle
266 @funindex \voiceTwoStyle
267 @funindex \voiceThreeStyle
268 @funindex \voiceFourStyle
269 @example
270 \voiceNeutralStyle
271 \voiceOneStyle
272 \voiceTwoStyle
273 \voiceThreeStyle
274 \voiceFourStyle
275 @end example
276
277 @funindex \shiftOn
278 @code{\shiftOn},
279 @funindex \shiftOnn
280 @code{\shiftOnn},
281 @funindex \shiftOnnn
282 @code{\shiftOnnn},
283 @funindex \shiftOff
284 @code{\shiftOff}: these commands specify the degree to which
285 chords of the current voice should be shifted.  The outer voices
286 (normally: voices one and two) have @code{\shiftOff}, while the
287 inner voices (three and four) have @code{\shiftOn}.
288 @code{\shiftOnn} and @code{\shiftOnnn} define further shift
289 levels.
290
291 When LilyPond cannot cope, the @code{force-hshift} property of the
292 @code{NoteColumn} object and pitched rests can be used to
293 override typesetting decisions.
294
295 @lilypond[quote,verbatim,relative=1]
296 <<
297   { <d g>2
298     <d g>  }
299   \\
300   { <b f'>2
301     \once \override NoteColumn #'force-hshift = #1.7
302     <b f'> }
303 >>
304 @end lilypond
305
306
307 @seealso
308
309 Music Glossary:
310 @rglos{polyphony}.
311
312 Learning Manual:
313 @rlearning{Multiple notes at once},
314 @rlearning{Voices contain music},
315 @rlearning{Collisions of objects}.
316
317 Snippets:
318 @rlsr{Simultaneous notes}.
319
320 Internals Reference:
321 @rinternals{NoteColumn}.
322 The objects responsible for resolving collisions
323 are
324 @rinternals{NoteCollision} and
325 @rinternals{RestCollision}.
326
327
328 @knownissues
329
330 When using @code{merge-differently-headed} with an upstem eighth or a
331 shorter note, and a downstem half note, the eighth note stem gets a
332 slightly wrong offset because of the different width of the half note
333 head symbol.
334
335 @c investigate! Sometimes it works, sometimes not. --FV
336 It is not clear in which circumpstances you can succesfully merge
337 different note heads that are at the same time differently dotted.
338
339 There is no support for clusters where the same note occurs with
340 different accidentals in the same chord.  In this case, it is
341 recommended to use enharmonic transcription, or to use special
342 cluster notation (see @ref{Clusters}).
343
344
345 @node Automatic part combining
346 @subsubsection Automatic part combining
347
348 @cindex automatic part combining
349 @cindex part combiner
350 @cindex combining parts
351 @funindex \partcombine
352
353 Automatic part combining is used to merge two parts of music onto a
354 staff.  It is aimed at typesetting orchestral scores.  When the two
355 parts are identical for a period of time, only one is shown.  In
356 places where the two parts differ, they are typeset as separate
357 voices, and stem directions are set automatically.  Also, solo and
358 @notation{a due} parts are identified and marked by default.
359
360 The syntax for part combining is:
361
362 @example
363 \partcombine @var{musicexpr1} @var{musicexpr2}
364 @end example
365
366 The following example demonstrates the basic functionality of the part
367 combiner: putting parts on one staff and setting stem directions and
368 polyphony.  The same variables are used for the independent
369 parts and the combined staff.
370
371 @lilypond[quote,verbatim]
372 instrumentOne = \relative c' {
373   c4 d e f
374   R1
375   d'4 c b a
376   b4 g2 f4
377   e1
378 }
379
380 instrumentTwo = \relative g' {
381   R1
382   g4 a b c
383   d c b a
384   g f( e) d
385   e1
386 }
387
388 <<
389   \new Staff \instrumentOne
390   \new Staff \instrumentTwo
391   \new Staff \partcombine \instrumentOne \instrumentTwo
392 >>
393 @end lilypond
394
395 The notes in the third measure appear only once, although they were
396 specified in both parts.  Stem, slur, and tie directions are set
397 automatically, depending whether there is a solo or unison.  When
398 needed in polyphony situations, the first part (with context called
399 @code{one}) always gets up stems, while the second (called @code{two})
400 always gets down stems.  In solo situations, the parts get marked with
401 @q{Solo} and @q{Solo II}, respectively.  The unisono (@notation{a due})
402 parts are marked by default with the text @qq{a2}.
403
404 Both arguments to @code{\partcombine} will be interpreted as
405 @code{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 @snippets
421
422 Parts may be merged without printing text:
423
424 @lilypond[quote,verbatim]
425 \new Staff <<
426   \set Staff.printPartCombineTexts = ##f
427   \partcombine
428     \relative g' { g a( b) r }
429     \relative g' { g r4 r f }
430 >>
431 @end lilypond
432
433 The printed text may be changed:
434
435 @lilypond[quote,verbatim]
436 \new Staff <<
437   \set Score.soloText = #"girl"
438   \set Score.soloIIText = #"boy"
439   \set Score.aDueText = #"together"
440   \partcombine
441     \relative g' { g4 g r r a2 g }
442     \relative g' { r4 r a( b) a2 g }
443 >>
444 @end lilypond
445
446
447 @seealso
448
449 Music Glossary:
450 @rglos{a due},
451 @rglos{part}.
452
453 Notation Reference:
454 @ref{Writing parts}.
455
456 Snippets:
457 @rlsr{Simultaneous notes}.
458
459
460 Internals Reference:
461 @rinternals{PartCombineMusic},
462 @rinternals{Voice}.
463
464 @knownissues
465
466 When @code{printPartCombineTexts} is set, if the two voices play
467 the same notes on and off, the part combiner may typeset @code{a2}
468 more than once in a measure.
469
470 @code{\partcombine} cannot be inside @code{\times}.
471
472 @code{\partcombine} cannot be inside @code{\relative}.
473
474 Internally, the @code{\partcombine} interprets both arguments as
475 @code{Voice}s named @code{one} and @code{two}, and then decides
476 when the parts can be combined.  Consequently, if the arguments
477 switch to differently named @rinternals{Voice} contexts, the
478 events in those will be ignored.
479
480 @c IIRC in users list someone pointed out more issues. FV
481
482 @node Writing music in parallel
483 @subsubsection Writing music in parallel
484
485 @cindex Writing music in parallel
486 @cindex Interleaved music
487 @funindex parallelMusic
488
489 Music for multiple parts can be interleaved in input code.  The
490 function @code{\parallelMusic} accepts a list with the names of a
491 number of variables to be created, and a musical expression.  The
492 content of alternate measures from the expression become the value of
493 the respective variables, so you can use them afterwards to print the
494 music.
495
496 @warning{Bar checks @code{|} must be used, and the measures must
497 be of the same length.}
498
499 @lilypond[quote,verbatim]
500 \parallelMusic #'(voiceA voiceB) {
501   % Bar 1
502   r8 g'16[ c''] e''[ g' c'' e''] r8 g'16[ c''] e''[ g' c'' e''] |
503   c'2                               c'2                         |
504
505   % Bar 2
506   r8 a'16[ d''] f''[ a' d'' f''] r8 a'16[ d''] f''[ a' d'' f''] |
507   c'2                               c'2                         |
508 }
509 \new StaffGroup <<
510   \new Staff  \voiceA
511   \new Staff  \voiceB
512 >>
513 @end lilypond
514
515 Relative mode may be used.  Note that the @code{\relative} command
516 is not used inside @code{\parallelMusic} itself.  The notes are
517 relative to the preceding note in the voice, not to the previous
518 note in the input -- in other words, relative notes for
519 @code{voiceA} ignore the notes in @code{voiceB}.
520
521 @lilypond[quote,verbatim]
522 \parallelMusic #'(voiceA voiceB) {
523   % Bar 1
524   r8 g16 c e g, c e r8 g,16 c e g, c e  |
525   c2                c                   |
526
527   % Bar 2
528   r8 a,16 d f a, d f r8 a,16 d f a, d f |
529   c2                 c                  |
530  }
531 \new StaffGroup <<
532   \new Staff \relative c'' \voiceA
533   \new Staff \relative c'  \voiceB
534 >>
535 @end lilypond
536
537 This works quite well for piano music.  This example maps four
538 consecutive measures to four variables:
539
540 @lilypond[quote,verbatim]
541 global = {
542   \key g \major
543   \time 2/4
544 }
545
546 \parallelMusic #'(voiceA voiceB voiceC voiceD) {
547   % Bar 1
548   a8    b     c   d     |
549   d4          e         |
550   c16 d e fis d e fis g |
551   a4          a         |
552
553   % Bar 2
554   e8      fis  g     a   |
555   fis4         g         |
556   e16 fis g  a fis g a b |
557   a4           a         |
558
559   % Bar 3 ...
560 }   
561
562 \score {   
563 \new PianoStaff <<
564  \new Staff {
565    \global
566    <<
567      \relative c'' \voiceA \\
568      \relative c'  \voiceB
569    >>
570  }
571  \new Staff {
572    \global \clef bass
573    <<
574      \relative c \voiceC \\
575      \relative c \voiceD
576    >>
577  }
578 >>
579 }
580 @end lilypond
581
582 @seealso
583
584 Learning Manual:
585 @rlearning{Organizing pieces with variables}
586
587 Snippets:
588 @rlsr{Simultaneous notes}.
589