]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/basic-notation.itely
cda2b3e3577da480b2407d4d99ca18585a45a2ec
[lilypond.git] / Documentation / user / basic-notation.itely
1 @c -*- coding: latin-1; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3
4 @c A menu is needed before every deeper *section nesting of @node's; run
5 @c     M-x texinfo-all-menus-update
6 @c to automatically fill in these menus before saving changes
7
8
9 @node Basic notation
10 @chapter Basic notation
11
12 This chapter explains how to use all basic notation features.
13
14 @menu
15 * Note entry::                  
16 * Alternate music entry::       
17 * Staff notation::              
18 * Connecting notes::            
19 * Expressive marks::            
20 * Polyphony::                   
21 * Repeats::                     
22 @end menu
23
24
25
26 @node Note entry
27 @section Note entry
28 @cindex Note entry
29
30 This section is about basic notation elements like notes, rests, and
31 related constructs, such as stems, tuplets and ties.
32
33 @menu
34 * Notes::                       
35 * Pitches::                     
36 * Cautionary accidentals::      
37 * Micro tones::                 
38 * Chords::                      
39 * Rests::                       
40 * Skips::                       
41 * Durations::                   
42 * Augmentation dots::           
43 * Tuplets::                     
44 * Scaling durations::           
45 @end menu
46
47
48 @node Notes
49 @subsection Notes
50
51 @cindex Note specification
52 @cindex entering notes
53
54 A note is printed by specifying its pitch and then its duration,
55
56 @lilypond[quote,verbatim,raggedright,fragment]
57 cis'4 d'8 e'16 c'16
58 @end lilypond
59
60 @seealso
61
62 This manual: @ref{Pitches}, @ref{Durations}
63
64
65 @node Pitches
66 @subsection Pitches
67
68 @cindex Pitch names
69 @cindex pitches
70
71 The most common syntax for pitch entry is used for standard notes and
72 @code{\chordmode} modes.  In these modes, pitches may be designated by
73 names.  The notes are specified by the letters @code{a} through
74 @code{g}.  The octave is formed with notes ranging from @code{c}
75 to @code{b}.  The pitch @code{c} is an octave below middle C and the
76 letters span the octave above that C
77
78 @lilypond[quote,fragment,verbatim,raggedright]
79 \clef bass
80 a,4 b, c d e f g a b c' d' e' \clef treble f' g' a' b' c''
81 @end lilypond
82
83 @cindex @code{'}
84 @cindex @code{,}
85
86 The optional octave specification takes the form of a series of
87 single quote (`@code{'}') characters or a series of comma
88 (`@code{,}') characters.  Each @code{'} raises the pitch by one
89 octave; each @code{,} lowers the pitch by an octave
90
91 @lilypond[quote,raggedright,fragment,verbatim]
92 c' c'' e' g d'' d'
93 @end lilypond
94
95 @cindex note names, Dutch
96
97 A sharp is formed by adding @code{-is} to the end of a pitch name and
98 a flat is formed by adding @code{-es}.  Double sharps and double flats
99 are obtained by adding @code{-isis} or @code{-eses}.  These
100 names are the Dutch note names.  In Dutch, @code{aes} is contracted to
101 @code{as}, but both forms are accepted.  Similarly, both
102 @code{es} and @code{ees} are accepted
103
104 @lilypond[fragment,quote,raggedright,verbatim,relative=2]
105 ceses4
106 ces
107 c
108 cis
109 cisis
110 @end lilypond
111
112 There are predefined sets of note names for various other languages.
113 To use them, include the language specific init file.  For
114 example: @code{\include "english.ly"}.  The available language files
115 and the note names they define are
116
117 @anchor{note name}
118 @anchor{note names}
119 @example
120                         Note Names               sharp       flat
121 nederlands.ly  c   d   e   f   g   a   bes b   -is         -es
122 english.ly     c   d   e   f   g   a   bf  b   -s/-sharp   -f/-flat
123                                                -x (double)
124 deutsch.ly     c   d   e   f   g   a   b   h   -is         -es
125 norsk.ly       c   d   e   f   g   a   b   h   -iss/-is    -ess/-es
126 svenska.ly     c   d   e   f   g   a   b   h   -iss        -ess
127 italiano.ly    do  re  mi  fa  sol la  sib si  -d          -b
128 catalan.ly     do  re  mi  fa  sol la  sib si  -d/-s       -b
129 espanol.ly     do  re  mi  fa  sol la  sib si  -s          -b
130 @end example
131
132
133 @commonprop
134
135 In accordance with standard typsetting rules, a natural sign is printed
136 before a sharp or flat if a previous accidental needs to be
137 cancelled.  To change this behaviour, use
138 @code{\set Staff.extraNatural = ##f}
139
140 @lilypond[fragment,quote,raggedright,verbatim,relative=2]
141 ceses4 ces cis c
142 \set Staff.extraNatural = ##f
143 ceses4 ces cis c
144 @end lilypond
145
146
147 @seealso
148
149 Program reference: @internalsref{LedgerLineSpanner}, @internalsref{NoteHead}.
150
151
152 @node Cautionary accidentals
153 @subsection Cautionary accidentals 
154
155 @cindex reminder accidental
156 @cindex @code{?}
157 @cindex cautionary accidental
158 @cindex parenthesized accidental
159 @cindex @code{!}
160
161 Normally accidentals are printed automatically, but you may also
162 print them manually.  A reminder accidental
163 can be forced by adding an exclamation mark @code{!}
164 after the pitch.  A cautionary accidental
165 (i.e., an accidental within parentheses) can be obtained by adding the
166 question mark `@code{?}' after the pitch.
167
168 @lilypond[quote,raggedright,fragment,verbatim]
169 cis' cis' cis'! cis'?
170 @end lilypond
171
172
173 @seealso
174
175 The automatic production of accidentals can be tuned in many
176 ways.  For more information, refer to @ref{Automatic accidentals}.
177
178
179
180 @node Micro tones
181 @subsection Micro tones
182
183 @cindex quarter tones
184 @cindex semi-flats, semi-sharps
185
186 Half-flats and half-sharps are formed by adding @code{-eh} and
187 @code{-ih}; the following is a series of Cs with increasing pitches
188
189 @lilypond[verbatim,raggedright,quote,relative=2,fragment]
190 \set Staff.extraNatural = ##f
191 ceseh ceh cih cisih
192 @end lilypond
193
194 Micro tones are also exported to the MIDI file.
195
196
197 @refbugs
198
199 There are no generally accepted standards for denoting three quarter
200 flats, so LilyPond's symbol does not conform to any standard.
201
202
203 @node Chords
204 @subsection Chords
205
206 @cindex Chords
207
208 A chord is formed by a enclosing a set of pitches in @code{<} and
209 @code{>}.  A chord may be followed by a duration, and a set of
210 articulations, just like simple notes
211
212 @lilypond[verbatim,raggedright,fragment,quote,relative=1]
213 <c e g>4 <c>8
214 @end lilypond
215
216 For more information about chords, see @ref{Chord names}.
217
218
219 @node Rests
220 @subsection Rests
221 @cindex Rests
222
223
224 @cindex @code{\rest}
225 @cindex @code{r}
226
227 Rests are entered like notes with the note name @code{r}
228
229 @lilypond[fragment,quote,raggedright,verbatim]
230 r1 r2 r4 r8
231 @end lilypond
232
233 Whole bar rests, centered in middle of the bar,
234 must be done with multi-measure rests.  They are discussed in
235 @ref{Multi measure rests}.
236
237
238 A rest's vertical position may be explicitly specified by entering a
239 note with the @code{\rest} keyword appended, the rest will be placed at
240 the note's place.  This makes manual formatting in polyphonic music
241 easier.  Automatic rest collision formatting will leave these rests
242 alone
243
244 @lilypond[fragment,quote,raggedright,verbatim]
245 a'4\rest d'4\rest
246 @end lilypond
247
248 @seealso
249
250 Program reference: @internalsref{Rest}.
251
252
253 @node Skips
254 @subsection Skips
255
256 @cindex Skip
257 @cindex Invisible rest
258 @cindex Space note
259 @cindex @code{\skip}
260 @cindex @code{s}
261
262 An invisible rest (also called a `skip') can be entered like a note
263 with note name `@code{s}' or with @code{\skip @var{duration}}
264
265 @lilypond[fragment,quote,raggedright,verbatim,relative=2]
266 a4 a4 s4 a4 \skip 1 a4
267 @end lilypond
268
269 The @code{s} syntax is only available in note mode and chord mode.  In
270 other situations, for example, when entering lyrics, you should use
271 the @code{\skip} command
272
273 @lilypond[quote,raggedright,verbatim]
274 <<
275   \relative { a'2 a2 }
276   \new Lyrics \lyricmode { \skip 2 bla2 }
277 >>
278 @end lilypond
279
280 The skip command is merely an empty musical placeholder.  It does not
281 produce any output, not even transparent output.
282
283 The @code{s} skip command does create @internalsref{Staff} and
284 @internalsref{Voice} when necessary, similar to note and rest
285 commands.  For example, the following results in an empty staff.
286
287 @lilypond[quote,raggedright,verbatim]
288 { s4 }
289 @end lilypond
290
291 The fragment @code{@{ \skip 4 @} } would produce an empty page.
292
293 @seealso
294
295 Program reference: @internalsref{SkipMusic}.
296
297
298 @node Durations
299 @subsection Durations
300
301 @cindex duration
302 @cindex @code{\longa}
303 @cindex @code{\breve}
304 @cindex @code{\maxima}
305
306 In Note, Chord, and Lyrics mode, durations are designated by numbers and
307 dots: durations are entered as their reciprocal values.  For example, a
308 quarter note is entered using a @code{4} (since it is a 1/4 note), while
309 a half note is entered using a @code{2} (since it is a 1/2 note).  For
310 notes longer than a whole you must use the variables @code{\longa} and
311 @code{\breve}
312
313 @example
314 c'\breve
315 c'1 c'2 c'4 c'8 c'16 c'32 c'64 c'64
316 r\longa r\breve
317 r1 r2 r4 r8 r16 r32 r64 r64
318 @end example
319
320 @lilypond[quote]
321 \score {
322  \relative c'' {
323     a\breve*1/2 \autoBeamOff
324     a1 a2 a4 a8 a16 a32 a64 a64
325    \bar "empty"
326    \break
327     r\longa*1/4 r\breve *1/2
328     r1 r2 r4 r8 r16 r32 r64 r64
329   }
330   \layout {
331     raggedright = ##t
332     \context {
333       \Staff
334         \remove "Clef_engraver"
335         \override StaffSymbol #'transparent = ##t
336         \override TimeSignature #'transparent = ##t
337         \override BarLine #'transparent = ##t
338         \consists "Pitch_squash_engraver"
339     }
340   }
341 }
342 @end lilypond
343
344 If the duration is omitted then it is set to the previously entered
345 duration.  The default for the first note is a quarter note.
346
347 @lilypond[quote,raggedright,verbatim,fragment]
348 { a a a2 a a4 a a1 a }
349 @end lilypond
350
351
352 @node Augmentation dots
353 @subsection Augmentation dots
354
355 @cindex @code{.}
356
357 To obtain dotted note lenghts, simply add a dot (`@code{.}') to
358 the number.  Double-dotted notes are produced in a similar way.
359
360 @lilypond[quote,raggedright,fragment,verbatim]
361 a'4 b' c''4. b'8 a'4. b'4.. c''8.
362 @end lilypond
363
364 @refcommands
365
366 Dots are normally moved up to avoid staff lines, except in polyphonic
367 situations.  The following commands may be used to force a particular
368 direction manually
369
370 @cindex @code{\dotsUp}
371 @code{\dotsUp},
372 @cindex @code{\dotsDown}
373 @code{\dotsDown},
374 @cindex @code{\dotsNeutral}
375 @code{\dotsNeutral}.
376
377 @seealso
378
379 Program reference: @internalsref{Dots}, and @internalsref{DotColumn}.
380
381
382 @node Tuplets
383 @subsection Tuplets
384
385 @cindex tuplets
386 @cindex triplets
387 @cindex @code{\times}
388
389 Tuplets are made out of a music expression by multiplying all durations
390 with a fraction
391
392 @example
393 \times @var{fraction} @var{musicexpr}
394 @end example
395
396 @noindent
397 The duration of @var{musicexpr} will be multiplied by the fraction.
398 The fraction's denominator will be printed over the notes, optionally
399 with a bracket.  The most common tuplet is the triplet in which 3
400 notes have the length of 2, so the notes are 2/3 of their written
401 length
402
403 @lilypond[quote,raggedright,fragment,verbatim]
404 g'4 \times 2/3 {c'4 c' c'} d'4 d'4
405 @end lilypond
406
407 @refcommands
408
409 @cindex @code{\tupletUp}
410 @code{\tupletUp},
411 @cindex @code{\tupletDown}
412 @code{\tupletDown},
413 @cindex @code{\tupletNeutral}
414 @code{\tupletNeutral}.
415
416
417 @commonprop
418
419 @cindex @code{tupletNumberFormatFunction}
420 @cindex tuplet formatting
421
422 The property @code{tupletSpannerDuration} specifies how long each
423 bracket should last.  With this, you can make lots of tuplets while
424 typing @code{\times} only once, thus saving lots of typing.  In the next
425 example, there are two triplets shown, while @code{\times} was only
426 used once
427
428 @lilypond[quote,fragment,relative=1,raggedright,verbatim]
429 \set tupletSpannerDuration = #(ly:make-moment 1 4)
430 \times 2/3 { c'8 c c c c c }
431 @end lilypond
432
433 The format of the number is determined by the property
434 @code{tupletNumberFormatFunction}.  The default prints only the
435 denominator, but if it is set to the Scheme function
436 @code{fraction-tuplet-formatter}, @var{num}:@var{den} will be printed
437 instead.
438
439
440 @seealso
441
442 Program reference: @internalsref{TupletBracket}, and @internalsref{TimeScaledMusic}.
443
444
445 @refbugs
446
447 Nested tuplets are not formatted automatically.  In this case, outer
448 tuplet brackets should be moved manually, which is demonstrated in
449 @inputfileref{input/@/regression,tuplet@/-nest@/.ly}.
450
451
452 @node Scaling durations
453 @subsection Scaling durations
454
455 You can alter the length of duration by a fraction @var{N/M}
456 appending `@code{*}@var{N/M}' (or `@code{*}@var{N}' if @var{M=1}).  This
457 will not affect the appearance of the notes or rests produced.
458
459 In the following example, the first three notes take up exactly two
460 beats, but no triplet bracket is printed.
461 @lilypond[quote,raggedright,fragment,relative=2,verbatim]
462 \time 2/4
463 a4*2/3 gis4*2/3 a4*2/3
464 a4 a4 a4*2
465 b16*4 c4
466 @end lilypond
467
468
469 @seealso
470
471 This manual: @ref{Tuplets}
472
473
474
475 @node Alternate music entry
476 @section Alternate music entry
477 @cindex Music entry
478
479 This section deals with tricks and features of the input language that
480 were added solely to help entering music and finding and correcting
481 mistakes.  There are also external tools that make debugging easier.
482 See @ref{Point and click} for more information.
483
484 It is also possible to enter and edit music using other programs, such as
485 GUI interfaces or MIDI sequencers.  Refer to the LilyPond
486 website for more information.
487
488 @menu
489 * Relative octaves::            
490 * Octave check::                
491 * Transpose::                   
492 * Bar check::                   
493 * Skipping corrected music::    
494 * Automatic note splitting::    
495 @end menu
496
497
498 @node Relative octaves
499 @subsection Relative octaves
500
501 @cindex Relative
502 @cindex Relative octave specification
503 @cindex @code{\relative}
504
505 Octaves are specified by adding @code{'} and @code{,} to pitch names.
506 When you copy existing music, it is easy to accidentally put a pitch
507 in the wrong octave and hard to find such an error.  The relative
508 octave mode prevents these errors by making the mistakes much
509 larger: a single error puts the rest of the piece off by one octave
510
511 @example
512 \relative @var{startpitch} @var{musicexpr}
513 @end example
514
515 @noindent
516 or
517
518 @example
519 \relative @var{musicexpr}
520 @end example
521
522 The octave of notes that appear in @var{musicexpr} are calculated as
523 follows: if no octave changing marks are used, the basic interval
524 between this and the last note is always taken to be a fourth or
525 less.  This distance is determined without regarding alterations; a
526 @code{fisis} following a @code{ceses} will be put above the
527 @code{ceses}.  In other words, a doubly-augmented fourth is considered
528 a smaller interval than a diminshed fifth, even though the fourth is
529 seven semitones while the fifth is only six semitones.
530
531 The octave changing marks @code{'} and @code{,} can be added to raise
532 or lower the pitch by an extra octave.  Upon entering relative mode,
533 an absolute starting pitch can be specified that will act as the
534 predecessor of the first note of @var{musicexpr}.  If no starting pitch
535 is specified, then middle C is used as a start.
536
537 Here is the relative mode shown in action
538 @lilypond[quote,fragment,raggedright,verbatim]
539 \relative c'' {
540   b c d c b c bes a
541 }
542 @end lilypond
543
544 Octave changing marks are used for intervals greater than a fourth
545 @lilypond[quote,raggedright,fragment,verbatim]
546 \relative c'' {
547   c g c f, c' a, e''
548 }
549 @end lilypond
550
551 If the preceding item is a chord, the first note of the chord is used
552 to determine the first note of the next chord
553
554 @lilypond[quote,raggedright,fragment,verbatim]
555 \relative c' {
556   c <c e g>
557   <c' e g>
558   <c, e' g>
559 }
560 @end lilypond
561
562 The pitch after the @code{\relative} contains a note name.
563
564 The relative conversion will not affect @code{\transpose},
565 @code{\chordmode} or @code{\relative} sections in its argument.  To use
566 relative within transposed music, an additional @code{\relative} must
567 be placed inside @code{\transpose}.
568
569
570 @node Octave check
571 @subsection Octave check
572
573 @cindex Octave check
574
575 Octave checks make octave errors easier to correct: a note may be
576 followed by @code{=}@var{quotes} which indicates what its absolute
577 octave should be.  In the following example,
578
579 @example
580 \relative c'' @{ c='' b=' d,='' @}
581 @end example
582
583 @noindent
584 the @code{d} will generate a warning, because a @code{d''} is expected
585 (because @code{b'} to @code{d''} is only a third), but a @code{d'} is
586 found.  In the output, the octave is corrected to be a @code{d''} and
587 the next note is calculated relative to @code{d''} instead of @code{d'}.
588
589 There is also a syntax that is separate from the notes.  The syntax
590
591 @example
592 \octave @var{pitch}
593 @end example
594
595 This checks that @var{pitch} (without quotes) yields @var{pitch} (with
596 quotes) in \relative mode.  If not, a warning is printed, and the
597 octave is corrected.
598
599 In the example below, the first check passes without incident, since
600 the @code{e} (in relative mode) is within a fifth of @code{a'}.  However,
601 the second check produces a warning, since the @code{e} is not within
602 a fifth of @code{b'}.  The warning message is printed, and the octave
603 is adjusted so that the following notes are in the correct octave
604 once again.
605
606 @example
607 \relative c' @{
608   e
609   \octave a'
610   \octave b'
611 @}
612 @end example
613
614
615 The octave of a note following an octave check is determined with
616 respect to the note preceding it.  In the next fragment, the last note
617 is an @code{a'}, above middle C.  That means that the @code{\octave}
618 check passes successfully, so the check could be deleted without changing
619 the output of the piece.
620
621 @lilypond[quote,raggedright,verbatim,fragment]
622 \relative c' {
623   e
624   \octave b
625   a
626 }
627 @end lilypond
628
629
630 @node Transpose
631 @subsection Transpose
632
633 @cindex Transpose
634 @cindex transposition of pitches
635 @cindex @code{\transpose}
636
637 A music expression can be transposed with @code{\transpose}.  The
638 syntax is
639 @example
640 \transpose @var{from} @var{to} @var{musicexpr}
641 @end example
642
643 This means that @var{musicexpr} is transposed by the interval between
644 the pitches @var{from} and @var{to}: any note with pitch @code{from}
645 is changed to @code{to}.
646
647 For example, consider a piece written in the key of D-major.  If
648 this piece is a little too low for its performer, it can be
649 transposed up to E-major with
650 @example
651 \transpose d e @dots{}
652 @end example
653
654 Consider a part written for violin (a C instrument).  If
655 this part is to be played on the A clarinet, the following
656 transposition will produce the appropriate part
657
658 @example
659 \transpose a c @dots{}
660 @end example
661
662 @code{\transpose} distinguishes between enharmonic pitches: both
663 @code{\transpose c cis} or @code{\transpose c des} will transpose up
664 half a tone.  The first version will print sharps and the second
665 version will print flats
666
667 @lilypond[quote,raggedright,verbatim]
668 mus = { \key d \major cis d fis g }
669 \context Staff {
670   \clef "F" \mus
671   \clef "G"
672   \transpose c g' \mus
673   \transpose c f' \mus
674 }
675 @end lilypond
676
677 @code{\transpose} may also be used to input written notes for a
678 transposing instrument.  Pitches are normally entered into LilyPond
679 in C (or ``concert pitch''), but they may be entered in another
680 key.  For example, when entering music for a B-flat trumpet which
681 begins on concert D, one would write
682
683 @example
684 \transpose c bes @{ e4 @dots{} @}
685 @end example
686
687 To print this music in B-flat again (ie producing a trumpet part,
688 instead of a concert pitch conductor's score) you would wrap the
689 existing music with another @code{transpose}
690
691 @example
692 \transpose bes c @{ \transpose c bes @{ e4 @dots{} @} @}
693 @end example
694
695
696 @seealso
697
698 Program reference: @internalsref{TransposedMusic}.
699
700
701 @refbugs
702
703 If you want to use both @code{\transpose} and @code{\relative},
704 you must put @code{\transpose} outside of @code{\relative}, since
705 @code{\relative} will have no effect music that appears inside a
706 @code{\transpose}.
707
708
709 @node Bar check
710 @subsection Bar check
711
712 @cindex Bar check
713 @cindex @code{barCheckSynchronize}
714 @cindex @code{|}
715
716 Bar checks help detect errors in the durations.  A bar check is
717 entered using the bar symbol, `@code{|}'.  Whenever it is encountered
718 during interpretation, it should fall on a measure boundary.  If it
719 does not, a warning is printed.  In the next example, the second bar
720 check will signal an error
721 @example
722 \time 3/4 c2 e4 | g2 |
723 @end example
724
725 Bar checks can also be used in lyrics, for example
726
727 @example
728 \lyricmode @{
729   \time 2/4
730   Twin -- kle | Twin -- kle
731 @}
732 @end example
733
734 Failed bar checks are caused by entering incorrect
735 durations.  Incorrect durations often completely garble up the score,
736 especially if the score is polyphonic, so a good place to start correcting
737 input is by scanning for failed bar checks and incorrect durations.
738
739 @cindex @code{|}
740 @cindex @code{pipeSymbol}
741
742 It is also possible to redefine the meaning of @code{|}.  This is done
743 by assigning a music expression to @code{pipeSymbol},
744
745 @lilypond[quote,raggedright,verbatim]
746 pipeSymbol = \bar "||"
747
748 { c'2 c' | c'2 c' }
749 @end lilypond
750
751
752 @node Skipping corrected music
753 @subsection Skipping corrected music
754
755
756 @cindex @code{skipTypesetting}
757 @cindex @code{showLastLength}
758
759 When entering or copying music, only the music near the end (where you
760 are adding notes) is interesting to view and correct.  To speed up
761 this correction process, it is possible to skip typesetting of all but
762 the last few measures. This is achieved by putting
763
764 @verbatim
765 showLastLength = R1*5
766 \score { ... }
767 @end verbatim
768
769 @noindent
770 in your source file. This will render only the last 5 measures
771 (assuming 4/4 time signature) of every @code{\score} in the input
772 file. For longer pieces, rendering only a small part is often an order
773 of magnitude quicker than rendering it completely
774
775 Skipping parts of a score can be controlled in a more fine-grained
776 fashing with the property @code{Score.skipTypesetting}.  When it is
777 set, no typesetting is performed at all.
778
779 @lilypond[quote,fragment,raggedright,verbatim]
780 \relative c'' {
781   c8 d
782   \set Score.skipTypesetting = ##t
783   e e e e e e e e
784   \set Score.skipTypesetting = ##f
785   c d b bes a g c2 }
786 @end lilypond
787
788 In polyphonic music, @code{Score.skipTypesetting} will affect all
789 voices and staves, saving even more time.
790
791
792 @node Automatic note splitting
793 @subsection Automatic note splitting
794
795 Long notes can be converted automatically to tied notes.  This is done
796 by replacing the @internalsref{Note_heads_engraver} by the
797 @internalsref{Completion_heads_engraver}.
798 In the following examples, notes crossing the bar line are split and tied.
799
800 @lilypond[quote,fragment,verbatim,relative=1,linewidth=12\cm]
801 \new Voice \with {
802   \remove "Note_heads_engraver"
803   \consists "Completion_heads_engraver"
804 } {
805   c2. c8 d4 e f g a b c8 c2 b4 a g16 f4 e d c8. c2
806 }
807 @end lilypond
808
809 This engraver splits all running notes at the bar line, and inserts
810 ties.  One of its uses is to debug complex scores: if the measures are
811 not entirely filled, then the ties exactly show how much each measure
812 is off.
813
814
815 @refbugs
816
817 Not all durations (especially those containing tuplets) can be
818 represented exactly with normal notes and dots, but the engraver will
819 not insert tuplets.
820
821 @code{Completion_heads_engraver} only affects notes; it does not split
822 rests.
823
824
825 @seealso
826
827 Examples: @inputfileref{input/@/regression,completion@/-heads@/.ly}.
828
829 @noindent
830
831 Program reference: @internalsref{Completion_heads_engraver}.
832
833
834
835 @node Staff notation
836 @section Staff notation
837
838 @cindex Staff notation
839
840 This section describes music notation that occurs on staff level,
841 such as key signatures, clefs and time signatures.
842
843 @menu
844 * Clef::                        
845 * Key signature::               
846 * Time signature::              
847 * Partial measures::            
848 * Bar lines::                   
849 * Unmetered music::             
850 * System start delimiters::     
851 * Staff symbol::                
852 @end menu
853
854
855 @node Clef
856 @subsection Clef
857
858 @cindex @code{\clef}
859
860 The clef indicates which lines of the staff correspond to which
861 pitches.  The clef is set with the @code{\clef} command
862
863 @lilypond[quote,raggedright,fragment,verbatim]
864 { c''2 \clef alto g'2 }
865 @end lilypond
866
867 @cindex treble clef
868 @cindex violin clef
869 @cindex alto clef
870 @cindex tenor clef
871 @cindex bass clef
872 @cindex french clef
873 @cindex soprano clef
874 @cindex mezzosoprano clef
875 @cindex baritone clef
876 @cindex varbaritone clef
877 @cindex subbass clef
878
879 Supported clefs finclude
880 @table @code
881 @item treble, violin, G, G2
882  G clef on 2nd line
883 @item alto, C
884  C clef on 3rd line
885 @item tenor
886  C clef on 4th line.
887 @item bass, F
888  F clef on 4th line
889 @item french
890  G clef on 1st line, so-called French violin clef
891 @item soprano
892  C clef on 1st line
893 @item mezzosoprano
894  C clef on 2nd line
895 @item baritone
896  C clef on 5th line
897 @item varbaritone
898  F clef on 3rd line
899 @item subbass
900  F clef on 5th line
901 @item percussion
902  percussion clef
903 @item tab
904  tablature clef
905 @end table
906
907 By adding @code{_8} or @code{^8} to the clef name, the clef is
908 transposed one octave down or up, respectively, and @code{_15} and
909 @code{^15} transposes by two octaves.  The argument @var{clefname}
910 must be enclosed in quotes when it contains underscores or digits.  For
911 example,
912
913 @cindex choral tenor clef
914 @lilypond[quote,raggedright,verbatim,fragment,relative=1]
915 \clef "G_8" c4
916 @end lilypond
917
918
919 @commonprop
920
921 The command @code{\clef "treble_8"} is equivalent to setting @code{clefGlyph},
922 @code{clefPosition} (which controls the Y position of the clef),
923 @code{middleCPosition} and @code{clefOctavation}.  A clef is printed
924 when any of these properties are changed.  The following example shows
925 possibilities when setting properties manually.
926
927 @lilypond[quote,raggedright,verbatim]
928 {
929   \set Staff.clefGlyph = #"clefs.F"
930   \set Staff.clefPosition = #2
931   c'4
932   \set Staff.clefGlyph = #"clefs.G"
933   c'4
934   \set Staff.clefGlyph = #"clefs.C"
935   c'4
936   \set Staff.clefOctavation = #7
937   c'4
938   \set Staff.clefOctavation = #0
939   \set Staff.clefPosition = #0
940   c'4
941   \clef "bass"
942   c'4
943   \set Staff.middleCPosition = #4
944   c'4
945 }
946 @end lilypond
947
948
949 @seealso
950
951 Program reference: @internalsref{Clef}.
952
953
954 @node Key signature
955 @subsection Key signature
956
957 @cindex Key signature
958 @cindex @code{\key}
959
960 The key signature indicates the tonality in which a piece is played.  It
961 is denoted by a set of alterations (flats or sharps) at the start of the
962 staff.
963
964 Setting or changing the key signature is done with the @code{\key}
965 command
966
967 @example
968 @code{\key} @var{pitch} @var{type}
969 @end example
970
971 @cindex @code{\minor}
972 @cindex @code{\major}
973 @cindex @code{\minor}
974 @cindex @code{\ionian}
975 @cindex @code{\locrian}
976 @cindex @code{\aeolian}
977 @cindex @code{\mixolydian}
978 @cindex @code{\lydian}
979 @cindex @code{\phrygian}
980 @cindex @code{\dorian}
981 @cindex church modes
982
983 Here, @var{type} should be @code{\major} or @code{\minor} to get
984 @var{pitch}-major or @var{pitch}-minor, respectively.  You may also
985 use the standard mode names (also called ``church modes''): @code{\ionian},
986 @code{\locrian}, @code{\aeolian}, @code{\mixolydian}, @code{\lydian},
987 @code{\phrygian}, and @code{\dorian}.
988
989 This command sets the context property
990 @code{Staff.keySignature}.  Non-standard key signatures
991 can be specified by setting this property directly.
992
993 Accidentals and key signatures often confuse new users, because
994 unaltered notes get natural signs depending on the key signature.  For
995 more information, see @ref{More about pitches}.
996
997
998 @commonprop
999
1000 A natural sign is printed to cancel any previous accidentals.  This
1001 can be suppressed by setting the @code{Staff.printKeyCancellation}
1002 property.
1003
1004 @lilypond[quote,fragment,raggedright,fragment,verbatim,relative=2]
1005 \key d \major
1006 a b cis d
1007 \key g \minor
1008 a bes c d
1009 \set Staff.printKeyCancellation = ##f
1010 \key d \major
1011 a b cis d
1012 \key g \minor
1013 a bes c d
1014 @end lilypond
1015
1016
1017 @seealso
1018
1019 Program reference: @internalsref{KeyCancellation}, @internalsref{KeySignature}.
1020
1021
1022 @node Time signature
1023 @subsection Time signature
1024
1025 @cindex Time signature
1026 @cindex meter
1027 @cindex @code{\time}
1028
1029 Time signature indicates the metrum of a piece: a regular pattern of
1030 strong and weak beats.  It is denoted by a fraction at the start of the
1031 staff.
1032
1033 The time signature is set with the @code{\time} command
1034
1035 @lilypond[quote,raggedright,fragment,verbatim]
1036 \time 2/4 c'2 \time 3/4 c'2.
1037 @end lilypond
1038
1039 @commonprop
1040
1041 The symbol that is printed can be customized with the @code{style}
1042 property.  Setting it to @code{#'()} uses fraction style for 4/4 and
1043 2/2 time,
1044
1045 @lilypond[fragment,quote,raggedright,verbatim]
1046 \time 4/4 c'1
1047 \time 2/2 c'1
1048 \override Staff.TimeSignature #'style = #'()
1049 \time 4/4 c'1
1050 \time 2/2 c'1
1051 @end lilypond
1052
1053 There are many more options for its layout.  See @ref{Ancient time
1054 signatures} for more examples.
1055
1056 @code{\time} sets the property @code{timeSignatureFraction},
1057 @code{beatLength} and @code{measureLength} in the @code{Timing}
1058 context, which is normally aliased to @internalsref{Score}.  The
1059 property @code{measureLength} determines where bar lines should be
1060 inserted, and how automatic beams should be generated.  Changing the
1061 value of @code{timeSignatureFraction} also causes the symbol to be
1062 printed.
1063
1064 More options are available through the Scheme function
1065 @code{set-time-signature}.  In combination with the
1066 @internalsref{Measure_grouping_engraver}, it will create
1067 @internalsref{MeasureGrouping} signs.  Such signs ease reading
1068 rhythmically complex modern music.  In the following example, the 9/8
1069 measure is subdivided in 2, 2, 2 and 3.  This is passed to
1070 @code{set-time-signature} as the third argument @code{(2 2 2 3)}
1071
1072 @lilypond[quote,raggedright,verbatim]
1073 \score {
1074   \relative c'' {
1075     #(set-time-signature 9 8 '(2 2 2 3))
1076     g8[ g] d[ d] g[ g] a8[( bes g]) |
1077     #(set-time-signature 5 8 '(3 2))
1078     a4. g4
1079   }
1080   \layout {
1081     \context {
1082       \Staff
1083       \consists "Measure_grouping_engraver"
1084     }
1085   }
1086 }
1087 @end lilypond
1088
1089 @seealso
1090
1091 Program reference: @internalsref{TimeSignature}, and @internalsref{Timing_translator}.
1092
1093
1094 @refbugs
1095
1096 Automatic beaming does not use the measure grouping specified with
1097 @code{set-time-signature}.
1098
1099
1100 @node Partial measures
1101 @subsection Partial measures
1102
1103 @cindex anacrusis
1104 @cindex upbeat
1105 @cindex partial measure
1106 @cindex measure, partial
1107 @cindex shorten measures
1108 @cindex @code{\partial}
1109
1110 Partial measures, such as an anacrusis or upbeat, are entered using the
1111
1112 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
1113 \partial 16*5 c16 cis d dis e | a2. c,4 | b2
1114 @end lilypond
1115
1116 The syntax for this command is
1117
1118 @example
1119 \partial @var{duration}
1120 @end example
1121
1122 This is internally translated into
1123
1124 @example
1125 \set Timing.measurePosition = -@var{length of duration}
1126 @end example
1127
1128 The property @code{measurePosition} contains a rational number
1129 indicating how much of the measure has passed at this point.
1130
1131
1132 @refbugs
1133
1134 This command does not take into account grace notes at the start of
1135 the music.  When a piece starts with graces notes in the pickup, then
1136 the @code{\partial} should follow the grace notes
1137
1138 @lilypond[verbatim,quote,raggedright,relative,fragment]
1139 \grace f16
1140 \partial 4
1141 g4
1142 a2 g2
1143 @end lilypond
1144
1145
1146 @node Bar lines
1147 @subsection Bar lines
1148
1149 @cindex Bar lines
1150 @cindex @code{\bar}
1151 @cindex measure lines
1152 @cindex repeat bars
1153
1154 Bar lines delimit measures, but are also used to indicate
1155 repeats.  Normally they are inserted automatically.  Line
1156 breaks may only happen on bar lines.
1157
1158 Special types of bar lines can be forced with the @code{\bar} command
1159
1160 @lilypond[quote,raggedright,relative=2,fragment,verbatim]
1161 c4 \bar "|:" c4
1162 @end lilypond
1163
1164 The following bar types are available
1165
1166 @lilypondfile[raggedright,quote]{bar-lines.ly}
1167
1168 To allow a line break where there is no visible bar line, use
1169
1170 @example
1171 \bar ""
1172 @end example
1173
1174 @noindent
1175 This will insert an invisible bar line and allow line breaks at this
1176 point.
1177
1178 In scores with many staves, a @code{\bar} command in one staff is
1179 automatically applied to all staves.  The resulting bar lines are
1180 connected between different staves of a StaffGroup
1181
1182 @lilypond[quote,raggedright,fragment,verbatim]
1183 <<
1184   \context StaffGroup <<
1185     \new Staff {
1186       e'4 d'
1187       \bar "||"
1188       f' e'
1189     }
1190     \new Staff { \clef bass c4 g e g }
1191   >>
1192   \new Staff { \clef bass c2 c2 }
1193 >>
1194 @end lilypond
1195
1196 @cindex @code{whichBar}
1197 @cindex @code{repeatCommands}
1198 @cindex @code{defaultBarType}
1199
1200 The command @code{\bar }@var{bartype} is a short cut for doing
1201 @code{\set Timing.whichBar = }@var{bartype}.  Whenever @code{whichBar}
1202 is set to a string, a bar line of that type is created.
1203
1204 A bar line is created whenever the @code{whichBar} property is set.
1205 At the start of a measure it is set to the contents of
1206 @code{Timing.defaultBarType}.  The contents of @code{repeatCommands} are used
1207 to override default measure bars.
1208
1209 You are encouraged to use @code{\repeat} for repetitions.  See
1210 @ref{Repeats}.
1211
1212
1213 @seealso
1214
1215 In this manual: @ref{Repeats}, @ref{System start delimiters}.
1216
1217 Program reference: @internalsref{BarLine} (created at
1218 @internalsref{Staff} level), @internalsref{SpanBar} (across staves).
1219
1220 Examples: @inputfileref{input/@/test,bar@/-lines@/.ly},
1221
1222
1223 @node Unmetered music
1224 @subsection Unmetered music
1225
1226 @cindex cadenza
1227 @cindex @code{\cadenzaOn}
1228 @cindex @code{\cadenzaOff}
1229
1230 Bar lines and bar numbers are calculated automatically.  For unmetered
1231 music (cadenzas, for example), this is not desirable.  To turn off
1232 automatic bar lines and bar numbers, use the commands @code{\cadenzaOn}
1233 and @code{\cadenzaOff}.
1234
1235 @lilypond[verbatim,quote,raggedright,relative=2,fragment]
1236 c4 d e d
1237 \cadenzaOn
1238 c4 c d8 d d f4 g4.
1239 \cadenzaOff
1240 \bar "|"
1241 d4 e d c
1242 @end lilypond
1243
1244
1245 @refbugs
1246
1247 LilyPond will only insert page breaks at a barline.  Unless the unmetered
1248 music ends before the end of the staff line, you will need to insert
1249 invisible bar lines
1250
1251 @example
1252 \bar ""
1253 @end example
1254
1255 @noindent
1256 to indicate where line breaks can occur.
1257
1258
1259 @node System start delimiters
1260 @subsection System start delimiters
1261
1262 @cindex start of system
1263 @cindex Staff, multiple
1264 @cindex bracket, vertical
1265 @cindex brace, vertical
1266 @cindex grand staff
1267 @cindex staff group
1268 @cindex staff, choir
1269
1270 Many scores consist of more than one staff.  These staves can be
1271 joined in four different ways
1272
1273 @itemize @bullet
1274 @item The group is started with a brace at the left, and bar lines are
1275 connected.  This is done with the @internalsref{GrandStaff} context.
1276
1277 @lilypond[verbatim,raggedright,quote]
1278 \new GrandStaff
1279 \relative <<
1280   \new Staff { c1 c }
1281   \new Staff { c c }
1282 >>
1283 @end lilypond
1284
1285 @item The group is started with a bracket, and bar lines are connected.
1286 This is done with the
1287 @internalsref{StaffGroup} context
1288
1289 @lilypond[verbatim,raggedright,quote]
1290 \new StaffGroup
1291 \relative <<
1292   \new Staff { c1 c }
1293   \new Staff { c c }
1294 >>
1295 @end lilypond
1296
1297 @item The group is started with a bracket, but bar lines are not
1298 connected.  This is done with the @internalsref{ChoirStaff} context.
1299
1300 @lilypond[verbatim,raggedright,quote]
1301 \new ChoirStaff
1302 \relative <<
1303   \new Staff { c1 c }
1304   \new Staff { c c }
1305 >>
1306 @end lilypond
1307
1308 @item The group is started with a vertical line.  Bar lines are not
1309 connected.  This is the default for the score.
1310
1311 @lilypond[verbatim,raggedright,quote]
1312 \relative <<
1313   \new Staff { c1 c }
1314   \new Staff { c c }
1315 >>
1316 @end lilypond
1317 @end itemize
1318
1319
1320 @seealso
1321
1322 The bar lines at the start of each system are
1323 @internalsref{SystemStartBar}, @internalsref{SystemStartBrace}, and
1324 @internalsref{SystemStartBracket}.  Only one of these types is created
1325 in every context, and that type is determined by the property
1326 @code{systemStartDelimiter}.
1327
1328
1329 @node Staff symbol
1330 @subsection Staff symbol
1331
1332 @cindex adjusting staff symbol
1333
1334 Notes, dynamic signs, etc., are grouped
1335 with a set of horizontal lines, called a staff (plural `staves').  In
1336 LilyPond, these lines are drawn using a separate layout object called
1337 staff symbol.
1338
1339 The staff symbol may be tuned in the number, thickness and distance
1340 of lines, using properties.  This is demonstrated in the example files
1341 @inputfileref{input/@/test,staff@/-lines@/.ly},
1342 @inputfileref{input/@/test,staff@/-size@/.ly}.
1343
1344 In addition, staves may be started and stopped at will. This is done
1345 with @code{\startStaff} and @code{\stopStaff}.
1346
1347 @lilypond[verbatim,relative=2,fragment]
1348 b4 b
1349 \override Staff.StaffSymbol #'line-count = 2
1350 \stopStaff \startStaff
1351 b b
1352 \revert Staff.StaffSymbol #'line-count
1353 \stopStaff \startStaff
1354 b b  
1355 @end lilypond
1356
1357 In combination with Frenched staves, this may be used to typeset ossia
1358 sections. An example is in @inputfileref{input/@/test@/,ossia.ly},
1359 shown here
1360
1361 @cindex ossia
1362
1363 @lilypondfile{ossia.ly}
1364
1365 @cindex staff lines, setting number of
1366 @cindex staff lines, setting thickness of
1367 @cindex thickness of staff lines, setting
1368 @cindex number of staff lines, setting
1369
1370 @seealso
1371
1372 Program reference: @internalsref{StaffSymbol}.
1373
1374 Examples: @inputfileref{input/@/test,staff@/-lines@/.ly},
1375 @inputfileref{input/@/test@/,ossia.ly},
1376 @inputfileref{input/@/test,staff@/-size@/.ly}.
1377
1378
1379
1380 @node Connecting notes
1381 @section Connecting notes
1382
1383 This section deals with notation that affects groups of notes.
1384
1385 @menu
1386 * Ties::                        
1387 * Slurs::                       
1388 * Phrasing slurs::              
1389 * Automatic beams::             
1390 * Manual beams::                
1391 * Grace notes::                 
1392 @end menu
1393
1394
1395 @node Ties
1396 @subsection Ties
1397
1398 @cindex tie
1399 @cindex @code{~}
1400
1401 A tie connects two adjacent note heads of the same pitch.  The tie in
1402 effect extends the length of a note.  Ties should not be confused with
1403 slurs, which indicate articulation, or phrasing slurs, which indicate
1404 musical phrasing.  A tie is entered using the tilde symbol `@code{~}'
1405
1406 @lilypond[quote,raggedright,fragment,verbatim]
1407 e' ~ e' <c' e' g'> ~ <c' e' g'>
1408 @end lilypond
1409
1410 When a tie is applied to a chord, all note heads whose pitches match
1411 are connected.  When no note heads match, no ties will be created.
1412
1413 A tie is just a way of extending a note duration, similar to the
1414 augmentation dot.  The following example shows two ways of notating
1415 exactly the same concept
1416
1417 @lilypond[quote,fragment,raggedright]
1418 \time 3/4 c'2. c'2 ~ c'4
1419 @end lilypond
1420
1421 @noindent
1422 Ties are used either when the note crosses a bar line, or when dots
1423 cannot be used to denote the rhythm.  When using ties, larger note
1424 values should be aligned to subdivisions of the measure, eg.
1425
1426 @lilypond[fragment,quote,raggedright]
1427 \relative {
1428   r8 c8 ~ c2 r4 | r8^"not" c2 ~ c8 r4
1429 }
1430 @end lilypond
1431
1432 If you need to tie a lot of notes over bars, it may be easier to use
1433 automatic note splitting (see @ref{Automatic note splitting}).  This
1434 mechanism automatically splits long notes, and ties them across bar
1435 lines.
1436
1437
1438 @commonprop
1439
1440 Ties are sometimes used to write out arpeggios.  In this case, two tied
1441 notes need not be consecutive.  This can be achieved by setting the
1442 @code{tieWaitForNote} property to true.  For example,
1443
1444 @lilypond[fragment,verbatim,relative=1,raggedright]
1445 \set tieWaitForNote = ##t
1446 \grace { c16[~ e~ g]~ } <c, e g>4   
1447 @end lilypond
1448
1449
1450 @refcommands
1451
1452
1453 @cindex @code{\tieUp}
1454 @code{\tieUp},
1455 @cindex @code{\tieDown}
1456 @code{\tieDown},
1457 @cindex @code{\tieNeutral}
1458 @code{\tieNeutral},
1459 @cindex @code{\tieDotted}
1460 @code{\tieDotted},
1461 @cindex @code{\tieDashed}
1462 @code{\tieDashed},
1463 @cindex @code{\tieSolid}
1464 @code{\tieSolid}.
1465
1466
1467 @seealso
1468
1469 In this manual: @ref{Automatic note splitting}.
1470
1471 Program reference: @internalsref{Tie}.
1472
1473
1474 @refbugs
1475
1476 Switching staves when a tie is active will not produce a slanted tie.
1477
1478 Formatting of ties is a difficult subject.  The results are often not
1479 optimal.
1480
1481
1482 @node Slurs
1483 @subsection Slurs
1484
1485 @cindex Slurs
1486
1487 A slur indicates that notes are to be played bound or
1488 @emph{legato}.  They are entered using parentheses
1489
1490 @lilypond[quote,raggedright,relative=2,fragment,verbatim]
1491 f( g a) a8 b( a4 g2 f4)
1492 <c e>2( <b d>2)
1493 @end lilypond
1494
1495 The direction of a slur can be specified with
1496 @code{\slur@emph{DIR}}, where @code{@emph{DIR}} is
1497 either @code{Up}, @code{Down}, or @code{Neutral} (automatically
1498 selected).
1499
1500 However, there is a convenient shorthand for forcing slur
1501 directions.  By adding @code{_} or @code{^} before the opening
1502 parentheses, the direction is also set.  For example,
1503
1504 @lilypond[relative=2,raggedright,quote,verbatim,fragment]
1505 c4_( c) c^( c)
1506 @end lilypond
1507
1508 Only one slur can be printed at once.  If you need to print a long
1509 slur over a few small slurs, please see @ref{Phrasing slurs}.
1510
1511
1512 @commonprop
1513
1514 Some composers write two slurs when they want legato chords.  This can
1515 be achieved in LilyPond by setting @code{doubleSlurs},
1516
1517 @lilypond[verbatim,raggedright,relative,fragment,quote]
1518 \set doubleSlurs = ##t
1519 <c e>4 ( <d f> <c e> <d f> )
1520 @end lilypond
1521
1522
1523 @refcommands
1524
1525 @cindex @code{\slurUp}
1526 @code{\slurUp},
1527 @cindex @code{\slurDown}
1528 @code{\slurDown},
1529 @cindex @code{\slurNeutral}
1530 @code{\slurNeutral},
1531 @cindex @code{\slurDashed}
1532 @code{\slurDashed},
1533 @cindex @code{\slurDotted}
1534 @code{\slurDotted},
1535 @cindex @code{\slurSolid}
1536 @code{\slurSolid}.
1537
1538 @seealso
1539
1540 Program reference: @seeinternals{Slur}.
1541
1542
1543 @node Phrasing slurs
1544 @subsection Phrasing slurs
1545
1546 @cindex phrasing slurs
1547 @cindex phrasing marks
1548
1549 A phrasing slur (or phrasing mark) connects notes and is used to
1550 indicate a musical sentence.  It is written using @code{\(} and @code{\)}
1551 respectively
1552
1553 @lilypond[quote,raggedright,fragment,verbatim,relative=1]
1554 \time 6/4 c'\( d( e) f( e) d\)
1555 @end lilypond
1556
1557 Typographically, the phrasing slur behaves almost exactly like a
1558 normal slur.  However, they are treated as different objects.  A
1559 @code{\slurUp} will have no effect on a phrasing slur; instead, use
1560 @code{\phrasingSlurUp}, @code{\phrasingSlurDown}, and
1561 @code{\phrasingSlurNeutral}.
1562
1563 You cannot have simultaneous phrasing slurs.
1564
1565
1566 @refcommands
1567
1568 @cindex @code{\phrasingSlurUp}
1569 @code{\phrasingSlurUp},
1570 @cindex @code{\phrasingSlurDown}
1571 @code{\phrasingSlurDown},
1572 @cindex @code{\phrasingSlurNeutral}
1573 @code{\phrasingSlurNeutral}.
1574
1575
1576 @seealso
1577
1578 Program reference: @internalsref{PhrasingSlur}.
1579
1580
1581 @node Automatic beams
1582 @subsection Automatic beams
1583
1584 LilyPond inserts beams automatically
1585
1586 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
1587 \time 2/4 c8 c c c \time 6/8 c c c c8. c16 c8
1588 @end lilypond
1589
1590 When these automatic decisions are not good enough, beaming can be
1591 entered explicitly.  It is also possible to define beaming patterns
1592 that differ from the defaults.  See @ref{Setting automatic beam behavior}
1593 for details.
1594
1595 Individual notes may be marked with @code{\noBeam} to prevent them
1596 from being beamed
1597
1598 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
1599 \time 2/4 c8 c\noBeam c c
1600 @end lilypond
1601
1602
1603 @seealso
1604
1605 Program reference: @internalsref{Beam}.
1606
1607
1608 @node Manual beams
1609 @subsection Manual beams
1610
1611 @cindex beams, manual
1612 @cindex @code{]}
1613 @cindex @code{[}
1614
1615 In some cases it may be necessary to override the automatic beaming
1616 algorithm.  For example, the autobeamer will not put beams over rests
1617 or bar lines.  Such beams are specified manually by marking the begin
1618 and end point with @code{[} and @code{]}
1619
1620 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
1621 {
1622   r4 r8[ g' a r8] r8 g[ | a] r8
1623 }
1624 @end lilypond
1625
1626
1627 @commonprop
1628
1629 @cindex @code{stemLeftBeamCount}
1630 @cindex @code{stemRightBeamCount}
1631
1632 Normally, beaming patterns within a beam are determined automatically.
1633 If necessary, the properties @code{stemLeftBeamCount} and
1634 @code{stemRightBeamCount} can be used to override the defaults.  If
1635 either property is set, its value will be used only once, and then it
1636 is erased
1637
1638 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
1639 {
1640    f8[ r16
1641       f g a]
1642    f8[ r16
1643    \set stemLeftBeamCount = #1
1644       f g a]
1645 }
1646 @end lilypond
1647
1648 The property @code{subdivideBeams} can be set in order to subdivide
1649 all 16th or shorter beams at beat positions, as defined by the
1650 @code{beatLength} property.
1651
1652 @lilypond[fragment,quote,relative=2,verbatim]
1653 c16[ c c c c c c c]
1654 \set subdivideBeams = ##t
1655 c16[ c c c c c c c]
1656 \set Score.beatLength = #(ly:make-moment 1 8)
1657 c16[ c c c c c c c]
1658 @end lilypond
1659 @cindex @code{subdivideBeams}
1660
1661 Line breaks are normally forbidden when beams cross bar lines.  This
1662 behavior can be changed by setting @code{allowBeamBreak}.
1663
1664 @cindex @code{allowBeamBreak}
1665 @cindex beams and line breaks
1666 @cindex beams, kneed
1667 @cindex kneed beams
1668 @cindex auto-knee-gap
1669
1670
1671 @refbugs
1672
1673 Kneed beams are inserted automatically when a large gap is detected
1674 between the note heads.  This behavior can be tuned through the object.
1675
1676 Automatically kneed cross-staff beams cannot be used together with
1677 hidden staves.  See @ref{Hiding staves}.
1678
1679 Beams do not avoid collisions with symbols around the notes, such as
1680 texts and accidentals.
1681
1682
1683 @node Grace notes
1684 @subsection Grace notes
1685
1686 @cindex @code{\grace}
1687 @cindex ornaments
1688 @cindex grace notes
1689 @cindex appoggiatura
1690 @cindex acciaccatura
1691
1692 Grace notes are ornaments that are written out.  The most common ones
1693 are acciaccatura, which should be played as very short.  It is denoted
1694 by a slurred small note with a slashed stem.  The appoggiatura is a
1695 grace note that takes a fixed fraction of the main note, and is
1696 denoted as a slurred note in small print without a slash.  They
1697 are entered with the commands @code{\acciaccatura} and
1698 @code{\appoggiatura}, as demonstrated in the following example
1699
1700 @lilypond[quote,raggedright,relative=2,verbatim,fragment]
1701 b4 \acciaccatura d8 c4 \appoggiatura e8 d4
1702 \acciaccatura { g16[ f] } e4
1703 @end lilypond
1704
1705 Both are special forms of the @code{\grace} command.  By prefixing this
1706 keyword to a music expression, a new one is formed, which will be
1707 printed in a smaller font and takes up no logical time in a measure.
1708
1709 @lilypond[quote,raggedright,relative=2,verbatim,fragment]
1710 c4 \grace c16 c4
1711 \grace { c16[ d16] } c2 c4
1712 @end lilypond
1713
1714 @noindent
1715 Unlike @code{\acciaccatura} and @code{\appoggiatura}, the
1716 @code{\grace} command does not start a slur.
1717
1718 Internally, timing for grace notes is done using a second, `grace'
1719 timing.  Every point in time consists of two rational numbers: one
1720 denotes the logical time, one denotes the grace timing.  The above
1721 example is shown here with timing tuples
1722
1723 @lilypond[quote,raggedright]
1724 <<
1725   \relative c''{
1726     c4 \grace c16 c4 \grace {
1727     c16[ d16] } c2 c4
1728   }
1729   \new Lyrics \lyricmode {
1730     \override LyricText #'font-family = #'typewriter
1731
1732     \markup { (0,0) } 4
1733     \grace { \markup {
1734       ( \fraction 1 4 , \fraction -1 16 ) } 16 }
1735     \markup { (\fraction 1 4 , 0 ) } 4
1736     \grace {
1737       \markup { (\fraction 2 4 , \fraction "-1" 8 ) } 16
1738       \markup { (\fraction 2 4 , \fraction "-1" 16 ) } 16
1739     }
1740     \markup { ( \fraction 2 4 , 0 ) }
1741   }
1742 >>
1743 @end lilypond
1744
1745 The placement of grace notes is synchronized between different staves.
1746 In the following example, there are two sixteenth grace notes for
1747 every eighth grace note
1748
1749 @lilypond[quote,raggedright,relative=2,verbatim,fragment]
1750 << \new Staff { e4 \grace { c16[ d e f] } e4 }
1751    \new Staff { c4 \grace { g8[ b] } c4 } >>
1752 @end lilypond
1753
1754 If you want to end a note with a grace, use the @code{\afterGrace}
1755 command.  It takes two arguments: the main note, and the grace notes
1756 following the main note. 
1757
1758 @lilypond[raggedright, verbatim,relative=2,fragment]
1759 c1 \afterGrace d1 { c16[ d] } c4   
1760 @end lilypond
1761
1762 This will put the grace notes after a ``space'' lasting 3/4 of the
1763 length of the main note.  The fraction 3/4 can be changed by setting
1764 @code{afterGraceFraction}, ie.
1765
1766 @example
1767 afterGraceFraction = #(cons 7 8) 
1768 @end example
1769
1770 @noindent
1771 will put the grace note at 7/8 of the main note. 
1772
1773 The same effect can be achieved manually by doing
1774
1775 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
1776 \context Voice {
1777   << { d1^\trill_( }
1778      { s2 \grace { c16[ d] } } >>
1779   c4)
1780 }
1781 @end lilypond
1782
1783 @noindent
1784 By adjusting the duration of the skip note (here it is a half-note),
1785 the space between the main-note and the grace is adjusted.
1786
1787 A @code{\grace} section will introduce special typesetting settings,
1788 for example, to produce smaller type, and set directions.  Hence, when
1789 introducing layout tweaks, they should be inside the grace section,
1790 for example,
1791 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
1792 \new Voice {
1793   \acciaccatura {
1794     \stemDown
1795     f16->
1796     \stemNeutral
1797   }
1798   g4
1799 }
1800 @end lilypond
1801
1802 @noindent
1803 The overrides should also be reverted inside the grace section.
1804
1805 The layout of grace sections can be changed throughout the music using
1806 the function @code{add-grace-property}.  The following example
1807 undefines the Stem direction for this grace, so stems do not always
1808 point up.
1809
1810 @example
1811 \new Staff @{
1812   #(add-grace-property 'Voice 'Stem 'direction '())
1813   @dots{}
1814 @}
1815 @end example
1816
1817 @noindent
1818 Another option is to change the variables @code{startGraceMusic},
1819 @code{stopGraceMusic}, @code{startAcciaccaturaMusic},
1820 @code{stopAcciaccaturaMusic}, @code{startAppoggiaturaMusic},
1821 @code{stopAppoggiaturaMusic}.  More information is in the file
1822 @file{ly/@/grace@/-init@/.ly}.
1823
1824
1825 @seealso
1826
1827 Program reference: @internalsref{GraceMusic}.
1828
1829
1830 @refbugs
1831
1832 A score that starts with a @code{\grace} section needs an explicit
1833 @code{\context Voice} declaration, otherwise the main note and the grace
1834 note end up on different staves.
1835
1836 Grace note synchronization can also lead to surprises.  Staff notation,
1837 such as key signatures, bar lines, etc., are also synchronized.  Take
1838 care when you mix staves with grace notes and staves without, for example,
1839
1840 @lilypond[quote,raggedright,relative=2,verbatim,fragment]
1841 << \new Staff { e4 \bar "|:" \grace c16 d4 }
1842    \new Staff { c4 \bar "|:" d4 } >>
1843 @end lilypond
1844
1845 @noindent
1846 This can be remedied by inserting grace skips, for the above example
1847
1848 @example
1849 \new Staff @{ c4 \bar "|:" \grace s16 d4 @}
1850 @end example
1851
1852 Grace sections should only be used within sequential music
1853 expressions.  Nesting or juxtaposing grace sections is not supported,
1854 and might produce crashes or other errors.
1855
1856
1857
1858 @node Expressive marks
1859 @section Expressive marks
1860
1861 Expressive marks help musicians to bring more to the music than simple
1862 notes and rhythms.
1863
1864 @menu
1865 * Articulations::               
1866 * Fingering instructions::      
1867 * Dynamics::                    
1868 * Breath marks::                
1869 * Running trills::              
1870 * Glissando::                   
1871 * Arpeggio::                    
1872 @end menu
1873
1874
1875 @node Articulations
1876 @subsection Articulations
1877
1878 @cindex Articulations
1879 @cindex scripts
1880 @cindex ornaments
1881
1882 A variety of symbols can appear above and below notes to indicate
1883 different characteristics of the performance.  They are added to a note
1884 by adding a dash and the character signifying the
1885 articulation.  They are demonstrated here
1886
1887 @lilypondfile[quote,raggedright]{script-abbreviations.ly}
1888
1889 The meanings of these shorthands can be changed.  See
1890 @file{ly/@/script@/-init@/.ly} for examples.
1891
1892 The script is automatically placed, but the direction can be forced as
1893 well.  Like other pieces of LilyPond code, @code{_} will place them
1894 below the staff, and @code{^} will place them above.
1895
1896 @lilypond[quote,raggedright,fragment,verbatim]
1897 c''4^^ c''4_^
1898 @end lilypond
1899
1900 Other symbols can be added using the syntax
1901 @var{note}@code{\}@var{name}.  Again, they
1902 can be forced up or down using @code{^} and @code{_},
1903 e.g.,
1904
1905 @lilypond[quote,raggedright,verbatim,fragment,relative=2]
1906 c\fermata c^\fermata c_\fermata
1907 @end lilypond
1908
1909 @cindex accent
1910 @cindex marcato
1911 @cindex staccatissimo
1912 @cindex espressivo
1913 @cindex fermata
1914 @cindex stopped
1915 @cindex staccato
1916 @cindex portato
1917 @cindex tenuto
1918 @cindex upbow
1919 @cindex downbow
1920 @cindex foot marks
1921 @cindex organ pedal marks
1922 @cindex turn
1923 @cindex open
1924 @cindex flageolet
1925 @cindex reverseturn
1926 @cindex trill
1927 @cindex prall
1928 @cindex mordent
1929 @cindex prallprall
1930 @cindex prallmordent
1931 @cindex prall, up
1932 @cindex prall, down
1933 @cindex mordent
1934 @cindex thumb marking
1935 @cindex segno
1936 @cindex coda
1937 @cindex varcoda
1938
1939 Here is a chart showing all scripts available,
1940
1941 @lilypondfile[raggedright,quote]{script-chart.ly}
1942
1943
1944 @commonprop
1945
1946 The vertical ordering of scripts is controlled with the
1947 @code{script-priority} property.  The lower this number, the closer it
1948 will be put to the note.  In this example, the
1949 @internalsref{TextScript} (the sharp symbol) first has the lowest
1950 priority, so it is put lowest in the first example.  In the second, the
1951 prall trill (the @internalsref{Script}) has the lowest, so it is on the
1952 inside.  When two objects have the same priority, the order in which
1953 they are entered decides which one comes first.
1954
1955 @lilypond[verbatim,relative=3,raggedright,fragment,quote]
1956 \once \override TextScript #'script-priority = #-100
1957 a4^\prall^\markup { \sharp }
1958
1959 \once \override Script #'script-priority = #-100
1960 a4^\prall^\markup { \sharp }
1961 @end lilypond
1962
1963
1964 @seealso
1965
1966 Program reference: @internalsref{Script}.
1967
1968
1969 @refbugs
1970
1971 These signs appear in the printed output but have no effect on the
1972 MIDI rendering of the music.
1973
1974
1975 @node Fingering instructions
1976 @subsection Fingering instructions
1977
1978 @cindex fingering
1979 @cindex finger change
1980
1981 Fingering instructions can be entered using
1982 @example
1983 @var{note}-@var{digit}
1984 @end example
1985 For finger changes, use markup texts
1986
1987 @lilypond[quote,verbatim,raggedright,fragment,relative=1]
1988 c4-1 c-2 c-3 c-4
1989 c^\markup { \finger "2 - 3" }
1990 @end lilypond
1991
1992 You can use the thumb-script to indicate that a note should be
1993 played with the thumb (e.g., in cello music)
1994 @lilypond[quote,verbatim,raggedright,fragment,relative=2]
1995 <a_\thumb a'-3>8 <b_\thumb b'-3>
1996 @end lilypond
1997
1998 Fingerings for chords can also be added to individual notes
1999 of the chord by adding them after the pitches
2000 @lilypond[quote,verbatim,raggedright,fragment,relative=2]
2001 < c-1 e-2 g-3 b-5 >4
2002 @end lilypond
2003
2004
2005 @commonprop
2006
2007 You may exercise greater control over fingering chords by
2008 setting @code{fingeringOrientations}
2009
2010 @lilypond[quote,verbatim,raggedright,fragment,relative=1]
2011 \set fingeringOrientations = #'(left down)
2012 <c-1 es-2 g-4 bes-5 > 4
2013 \set fingeringOrientations = #'(up right down)
2014 <c-1 es-2 g-4 bes-5 > 4
2015 @end lilypond
2016
2017 Using this feature, it is also possible to put fingering instructions
2018 very close to note heads in monophonic music,
2019
2020 @lilypond[verbatim,raggedright,quote,fragment]
2021 \set fingeringOrientations = #'(right)
2022 <es'-2>4
2023 @end lilypond
2024
2025
2026 @seealso
2027
2028 Program reference: @internalsref{Fingering}.
2029
2030 Examples: @inputfileref{input/@/regression,finger@/-chords@/.ly}.
2031
2032
2033 @node Dynamics
2034 @subsection Dynamics
2035
2036 @cindex Dynamics
2037 @cindex @code{\ppp}
2038 @cindex @code{\pp}
2039 @cindex @code{\p}
2040 @cindex @code{\mp}
2041 @cindex @code{\mf}
2042 @cindex @code{\f}
2043 @cindex @code{\ff}
2044 @cindex @code{\fff}
2045 @cindex @code{\ffff}
2046 @cindex @code{\fp}
2047 @cindex @code{\sf}
2048 @cindex @code{\sff}
2049 @cindex @code{\sp}
2050 @cindex @code{\spp}
2051 @cindex @code{\sfz}
2052 @cindex @code{\rfz}
2053
2054 Absolute dynamic marks are specified using a command after a note
2055 @code{c4\ff}.  The available dynamic marks are @code{\ppp},
2056 @code{\pp}, @code{\p}, @code{\mp}, @code{\mf}, @code{\f}, @code{\ff},
2057 @code{\fff}, @code{\fff}, @code{\fp}, @code{\sf}, @code{\sff},
2058 @code{\sp}, @code{\spp}, @code{\sfz}, and @code{\rfz}.
2059
2060 @lilypond[quote,verbatim,raggedright,fragment,relative=2]
2061 c\ppp c\pp c \p c\mp c\mf c\f c\ff c\fff
2062 c2\fp c\sf c\sff c\sp c\spp c\sfz c\rfz
2063 @end lilypond
2064
2065 @cindex @code{\<}
2066 @cindex @code{\>}
2067 @cindex @code{\!}
2068
2069 A crescendo mark is started with @code{\<} and terminated with
2070 @code{\!} or an absolute dynamic.  A decrescendo is started with
2071 @code{\>} and is also terminated with @code{\!} or an absolute
2072 dynamic.  Because these marks are bound to notes, you must
2073 use spacer notes if multiple marks are needed during one note
2074
2075 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
2076 c\< c\! d\> e\!
2077 << f1 { s4 s4\< s4\! \> s4\! } >>
2078 @end lilypond
2079 This may give rise to very short hairpins.  Use @code{minimum-length}
2080 in @internalsref{Voice}.@internalsref{Hairpin} to lengthen them, for
2081 example
2082
2083 @example
2084 \override Staff.Hairpin #'minimum-length = #5
2085 @end example
2086
2087 @cindex crescendo
2088 @cindex decrescendo
2089 @cindex diminuendo
2090
2091 You can also use a text saying @emph{cresc.} instead of hairpins
2092
2093 @lilypond[quote,raggedright,fragment,relative=2,verbatim]
2094 \setTextCresc
2095 c\< d e f\!
2096 \setHairpinCresc
2097 e\> d c b\!
2098 \setTextDecresc
2099 c\> d e f\!
2100 \setTextDim
2101 e\> d c b\!
2102 @end lilypond
2103
2104 You can also supply your own texts
2105 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
2106 \set crescendoText = \markup { \italic "cresc. poco" }
2107 \set crescendoSpanner = #'dashed-line
2108 a'2\< a a a\!\mf
2109 @end lilypond
2110
2111 To create new dynamic marks or text that should be aligned
2112 with dynamics, see @ref{New dynamic marks}.
2113
2114
2115 @refcommands
2116
2117 @cindex @code{\dynamicUp}
2118 @code{\dynamicUp},
2119 @cindex @code{\dynamicDown}
2120 @code{\dynamicDown},
2121 @cindex @code{\dynamicNeutral}
2122 @code{\dynamicNeutral}.
2123
2124
2125 @seealso
2126
2127 Program reference: @internalsref{DynamicText}, @internalsref{Hairpin}.
2128 Vertical positioning of these symbols is handled by
2129 @internalsref{DynamicLineSpanner}.
2130
2131
2132 @node Breath marks
2133 @subsection Breath marks
2134
2135 Breath marks are entered using @code{\breathe}
2136
2137 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
2138 c'4 \breathe d4
2139 @end lilypond
2140
2141
2142 @commonprop
2143
2144 The glyph of the breath mark can be tuned by overriding the
2145 @code{text} property of the @code{BreathingSign} layout object with
2146 any markup text.  For example,
2147 @lilypond[quote,raggedright,fragment,verbatim,relative=1]
2148 c'4
2149 \override BreathingSign #'text
2150   = #(make-musicglyph-markup "scripts.rvarcomma")
2151 \breathe
2152 d4
2153 @end lilypond
2154
2155 @seealso
2156
2157 Program reference: @internalsref{BreathingSign}.
2158
2159 Examples: @inputfileref{input/@/regression,breathing@/-sign@/.ly}.
2160
2161
2162 @node Running trills
2163 @subsection Running trills
2164
2165 Long running trills are made with @code{\startTrillSpan} and
2166 @code{\stopTrillSpan},
2167
2168 @lilypond[verbatim,raggedright,relative=2,quote,fragment]
2169 \new Voice {
2170   << { c1 \startTrillSpan }
2171      { s2. \grace { d16[\stopTrillSpan e] } } >>
2172   c4 }
2173 @end lilypond
2174
2175
2176 @refcommands
2177
2178 @code{\startTrillSpan},
2179 @cindex @code{\startTrillSpan}
2180 @code{\stopTrillSpan}.
2181 @cindex @code{\stopTrillSpan}
2182
2183
2184 @seealso
2185
2186 Program reference: @internalsref{TrillSpanner}.
2187
2188
2189 @node Glissando
2190 @subsection Glissando
2191
2192 @cindex Glissando
2193 @cindex @code{\glissando}
2194
2195 A glissando is a smooth change in pitch.  It is denoted by a line or a
2196 wavy line between two notes.  It is requested by attaching
2197 @code{\glissando} to a note
2198
2199 @lilypond[quote,raggedright,fragment,relative=2,verbatim]
2200 c2\glissando c'
2201 \override Glissando #'style = #'zigzag
2202 c2\glissando c,
2203 @end lilypond
2204
2205
2206 @seealso
2207
2208 Program reference: @internalsref{Glissando}.
2209
2210 Example files: @file{input/@/regression/@/glissando@/.ly}.
2211
2212
2213 @refbugs
2214
2215 Printing text over the line (such as @emph{gliss.}) is not supported.
2216
2217
2218 @node Arpeggio
2219 @subsection Arpeggio
2220
2221 @cindex Arpeggio
2222 @cindex broken chord
2223 @cindex @code{\arpeggio}
2224
2225 You can specify an arpeggio sign (also known as broken chord) on a
2226 chord by attaching an @code{\arpeggio} to a chord
2227
2228 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
2229 <c e g c>\arpeggio
2230 @end lilypond
2231
2232 A square bracket on the left indicates that the player should not
2233 arpeggiate the chord
2234
2235 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
2236 \arpeggioBracket
2237 <c' e g c>\arpeggio
2238 @end lilypond
2239
2240 The direction of the arpeggio is sometimes denoted by adding an
2241 arrowhead to the wiggly line
2242
2243 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
2244 \context Voice {
2245   \arpeggioUp
2246   <c e g c>\arpeggio
2247   \arpeggioDown
2248   <c e g c>\arpeggio
2249 }
2250 @end lilypond
2251
2252
2253 @commonprop
2254
2255 When an arpeggio crosses staves, you may attach an arpeggio to the chords
2256 in both staves and set
2257 @internalsref{PianoStaff}.@code{connectArpeggios}
2258
2259 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
2260 \context PianoStaff <<
2261   \set PianoStaff.connectArpeggios = ##t
2262   \new Staff { <c' e g c>\arpeggio }
2263   \new Staff { \clef bass <c,, e g>\arpeggio }
2264 >>
2265 @end lilypond
2266
2267
2268 @refcommands
2269
2270 @code{\arpeggio},
2271 @cindex @code{\arpeggioUp}
2272 @code{\arpeggioUp},
2273 @cindex @code{\arpeggioDown}
2274 @code{\arpeggioDown},
2275 @cindex @code{\arpeggioNeutral}
2276 @code{\arpeggioNeutral},
2277 @cindex @code{\arpeggioBracket}
2278 @code{\arpeggioBracket}.
2279
2280
2281 @seealso
2282
2283 Notation manual: @ref{Ties}, for writing out arpeggios.
2284
2285 Program reference: @internalsref{Arpeggio}.
2286
2287
2288 @refbugs
2289
2290 It is not possible to mix connected arpeggios and unconnected
2291 arpeggios in one @internalsref{PianoStaff} at the same point in time.
2292
2293
2294
2295 @node Polyphony
2296 @section Polyphony
2297
2298 Polyphony in music refers to having more than one voice occuring in
2299 a piece of music.  Polyphony in LilyPond refers to having more than
2300 one voice on the same staff.
2301
2302 @menu
2303 * Basic polyphony::             
2304 * Explicitly instantiating voices::  
2305 * Collision Resolution::        
2306 @end menu
2307
2308
2309 @node Basic polyphony
2310 @subsection Basic polyphony
2311
2312 @cindex polyphony
2313
2314 The easiest way to enter fragments with more than one voice on a staff
2315 is to enter each voice as a sequence (with @code{@{...@}}), and combine 
2316 them simultaneously, separating the voices with @code{\\}
2317
2318 @cindex @code{\\}
2319
2320 @lilypond[quote,verbatim,fragment]
2321 \new Staff \relative c' {
2322   c16 d e f
2323   <<
2324     { g4 f e | d2 e2 } \\
2325     { r8 e4 d c8 ~ | c b16 a b8 g ~ g2 } \\
2326     { s2. | s4 b4 c2 }
2327   >>
2328 }
2329 @end lilypond
2330
2331 The separator causes @internalsref{Voice} contexts@footnote{Polyphonic
2332 voices are sometimes called ``layers'' in other notation packages}
2333 @cindex layers
2334 to be instantiated.  They bear the names @code{"1"}, @code{"2"}, etc.  In
2335 each of these contexts, vertical direction of slurs, stems, etc., is set
2336 appropriately.  
2337
2338 These voices are all seperate from the voice that contains the notes just 
2339 outside the @code{<< \\ >>} construct.  This should be noted when making 
2340 changes at the voice level.  This also means that slurs and ties cannot go 
2341 into or out of a @code{<< \\ >>} construct.  Conversely, parallel voices
2342 from separate @code{<< \\ >>} constructs on the same staff are the the
2343 same voice.  Here is the same example, with different noteheads for each
2344 voice.  Note that the change to the note-head style in the main voice does not affect
2345 the inside of the @code{<< \\ >>} constructs.  Also, the change to the second
2346 voice in the first @code{<< \\ >>} construct is effective in the second
2347 @code{<< \\ >>}, and the voice is tied accross the two constructs.
2348
2349 @lilypond[quote,verbatim,fragment]
2350 \new Staff \relative c' {
2351   \override NoteHead #'style = #'cross
2352   c16 d e f
2353   <<    
2354     { g4 f e } \\
2355     { \override NoteHead #'style = #'triangle
2356     r8 e4 d c8 ~ }
2357   >> |
2358   <<
2359     { d2 e2 } \\ 
2360     { c8 b16 a b8 g ~ g2 } \\
2361     { \override NoteHead #'style = #'slash s4 b4 c2 }
2362   >>
2363 }
2364 @end lilypond
2365
2366 Polyphony does not change the relationship of notes within a
2367 @code{\relative @{ @}} block.  Each note is calculated relative
2368 to the note immediately preceding it.
2369
2370 @example
2371 \relative @{ noteA << noteB \\ noteC >> noteD @}
2372 @end example
2373
2374 @code{noteC} is relative to @code{noteB}, not @code{noteA};
2375 @code{noteD} is relative to @code{noteC}, not @code{noteB} or
2376 @code{noteA}.
2377
2378 @node Explicitly instantiating voices
2379 @subsection Explicitly instantiating voices
2380
2381 @internalsref{Voice} contexts can also also be instantiated manually
2382 inside a @code{<< >>} block to create polyphonic music, using 
2383 @code{\voiceOne}, up to @code{\voiceFour} to assign stem directions 
2384 and a horizontal shift for each part.
2385
2386 Specifically,
2387 @example
2388 << \upper \\ \lower >>
2389 @end example
2390
2391 @noindent
2392 is equivalent to
2393
2394 @example
2395 <<
2396   \context Voice = "1" @{ \voiceOne \upper @}
2397   \context Voice = "2" @{ \voiceTwo \lower @}
2398 >>
2399 @end example
2400
2401 The @code{\voiceXXX} commands set the direction of stems, slurs, ties,
2402 articulations, text annotations, augmentation dots of dotted
2403 notes, and fingerings.  @code{\voiceOne} and @code{\voiceThree} make
2404 these objects point upwards, while @code{\voiceTwo} and @code{\voiceFour}
2405 make them point downwards.  
2406 The command @code{\oneVoice} will revert back to the normal setting.
2407
2408 An expression that appears directly inside a @code{<< >>} belongs to 
2409 the main voice.  This is useful when extra voices appear while the main
2410 voice is playing.  Here is a more correct rendition of the example from
2411 the previous section.  The crossed noteheads demonstrate that the main
2412 melody is now in a single voice context.
2413
2414 @lilypond[quote,raggedright,verbatim]
2415 \new Staff \relative c' {
2416   \override NoteHead #'style = #'cross
2417   c16 d e f 
2418   \voiceOne
2419   <<    
2420     { g4 f e | d2 e2 }
2421     \context Voice="1" { \voiceTwo
2422       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2 
2423       \oneVoice
2424     }
2425     \new Voice { \voiceThree 
2426       s2. | s4 b4 c2 
2427       \oneVoice
2428     }
2429   >>
2430   \oneVoice
2431 }
2432 @end lilypond
2433
2434 The correct definition of the voices allows the melody to be slurred.
2435 @lilypond[quote,raggedright,verbatim]
2436 \new Staff \relative c' {
2437   c16^( d e f 
2438   \voiceOne
2439   <<    
2440     { g4 f e | d2 e2) }  
2441     \context Voice="1" { \voiceTwo
2442       r8 e4 d c8 ~ | c8 b16 a b8 g ~ g2 
2443       \oneVoice
2444     }
2445     \new Voice { \voiceThree 
2446       s2. s4 b4 c2 
2447       \oneVoice
2448     }
2449   >>
2450   \oneVoice
2451 }
2452 @end lilypond
2453
2454 Avoiding the @code{\\} seperator also allows nesting polyphony 
2455 constructs, which in some case might be a more natural way to typeset
2456 the music.
2457
2458 @lilypond[quote,raggedright,verbatim]
2459 \new Staff \relative c' {
2460   c16^( d e f 
2461   \voiceOne
2462   <<    
2463     { g4 f e | d2 e2) }  
2464     \context Voice="1" { \voiceTwo
2465       r8 e4 d c8 ~ | 
2466       <<
2467         {c8 b16 a b8 g ~ g2} 
2468         \new Voice { \voiceThree 
2469           s4 b4 c2 
2470           \oneVoice
2471         }
2472       >>
2473     \oneVoice
2474     }
2475   >>
2476   \oneVoice
2477 }
2478 @end lilypond
2479
2480
2481 @node Collision Resolution
2482 @subsection Collision Resolution
2483
2484 Normally, note heads with a different number of dots are not merged, but
2485 when the object property @code{merge-differently-dotted} is set in
2486 the @internalsref{NoteCollision} object, they are merged
2487 @lilypond[quote,verbatim,fragment,raggedright,relative=2]
2488 \context Voice << {
2489   g8 g8
2490   \override Staff.NoteCollision
2491     #'merge-differently-dotted = ##t
2492   g8 g8
2493 } \\ { g8.[ f16] g8.[ f16] } >>
2494 @end lilypond
2495
2496 Similarly, you can merge half note heads with eighth notes, by setting
2497 @code{merge-differently-headed}
2498 @lilypond[quote,raggedright,fragment,relative=2,verbatim]
2499 \context Voice << {
2500   c8 c4.
2501   \override Staff.NoteCollision
2502     #'merge-differently-headed = ##t
2503 c8 c4. } \\ { c2 c2 } >>
2504 @end lilypond
2505
2506 LilyPond also vertically shifts rests that are opposite of a stem,
2507 for example
2508
2509 @lilypond[quote,raggedright,fragment,verbatim]
2510 \context Voice << c''4 \\ r4 >>
2511 @end lilypond
2512
2513
2514 @refcommands
2515
2516 @cindex @code{\oneVoice}
2517 @code{\oneVoice},
2518 @cindex @code{\voiceOne}
2519 @code{\voiceOne},
2520 @cindex @code{\voiceTwo}
2521 @code{\voiceTwo},
2522 @cindex @code{\voiceThree}
2523 @code{\voiceThree},
2524 @cindex @code{\voiceFour}
2525 @code{\voiceFour}.
2526
2527 @cindex @code{\shiftOn}
2528 @code{\shiftOn},
2529 @cindex @code{\shiftOnn}
2530 @code{\shiftOnn},
2531 @cindex @code{\shiftOnnn}
2532 @code{\shiftOnnn},
2533 @cindex @code{\shiftOff}
2534 @code{\shiftOff}: these commands specify in what chords of the current
2535 voice should be shifted.  The outer voices (normally: voice one and
2536 two) have @code{\shiftOff}, while the inner voices (three and four)
2537 have @code{\shiftOn}.  @code{\shiftOnn} and @code{\shiftOnnn} define
2538 further shift levels.
2539
2540 When LilyPond cannot cope, the @code{force-hshift}
2541 property of the @internalsref{NoteColumn} object and pitched rests can
2542 be used to override typesetting decisions.
2543
2544 @lilypond[quote,verbatim,raggedright]
2545 \relative <<
2546 {
2547   <d g>
2548   <d g>
2549 } \\ {
2550   <b f'>
2551   \once \override NoteColumn #'force-hshift = #1.7
2552   <b f'>
2553 } >>
2554 @end lilypond
2555
2556
2557 @seealso
2558
2559 Program reference: the objects responsible for resolving collisions are
2560 @internalsref{NoteCollision} and @internalsref{RestCollision}.
2561
2562 Examples:
2563 @inputfileref{input/@/regression,collision@/-dots@/.ly},
2564 @inputfileref{input/@/regression,collision@/-head-chords@/.ly},
2565 @inputfileref{input/@/regression,collision@/-heads@/.ly},
2566 @inputfileref{input/@/regression,collision@/-mesh@/.ly}, and
2567 @inputfileref{input/@/regression,collisions@/.ly}.
2568
2569
2570 @refbugs
2571
2572 When using @code{merge-differently-headed} with an upstem eighth or a
2573 shorter note, and a downstem half note, the eighth note gets the wrong
2574 offset.
2575
2576 There is no support for clusters where the same note occurs with
2577 different accidentals in the same chord.  In this case, it is
2578 recommended to use enharmonic transcription, or to use special cluster
2579 notation (see @ref{Clusters}).
2580
2581
2582
2583 @node Repeats
2584 @section Repeats
2585
2586 Repetition is a central concept in music, and multiple notations exist
2587 for repetitions.
2588
2589 @menu
2590 * Repeat types::                
2591 * Repeat syntax::               
2592 * Repeats and MIDI::            
2593 * Manual repeat commands::      
2594 * Tremolo repeats::             
2595 * Tremolo subdivisions::        
2596 * Measure repeats::             
2597 @end menu
2598
2599
2600 @node Repeat types
2601 @subsection Repeat types
2602
2603 @cindex repeats
2604 @cindex @code{\repeat}
2605
2606 The following types of repetition are supported
2607
2608 @table @code
2609 @item unfold
2610 Repeated music is fully written (played) out.  This is useful when
2611 entering repetitious music.  This is the only kind of repeat that
2612 is included in MIDI output.
2613
2614 @item volta
2615 Repeats are not written out, but alternative endings (volte) are
2616 printed, left to right with brackets.  This is the standard notation
2617 for repeats with alternatives.  These are not played in MIDI output by default.
2618
2619 @ignore
2620 @item fold
2621 Alternative endings are written stacked.  This has limited use but may be
2622 used to typeset two lines of lyrics in songs with repeats, see
2623 @inputfileref{input,star-spangled-banner@/.ly}.
2624 @end ignore
2625
2626 @item tremolo
2627 Make tremolo beams.  These are not played in MIDI output by default.
2628
2629 @item percent
2630 Make beat or measure repeats.  These look like percent signs.  These
2631 are not played in MIDI output by default.  Percent repeats must be
2632 declared within a Voice context.
2633
2634 @end table
2635
2636
2637 @node Repeat syntax
2638 @subsection Repeat syntax
2639
2640 LilyPond has one syntactic construct for specifying different types of
2641 repeats.  The syntax is
2642
2643 @example
2644 \repeat @var{variant} @var{repeatcount} @var{repeatbody}
2645 @end example
2646
2647 If you have alternative endings, you may add
2648 @cindex @code{\alternative}
2649 @example
2650 \alternative @{
2651   @var{alternative1}
2652   @var{alternative2}
2653   @var{alternative3}
2654   @dots{}
2655 @}
2656 @end example
2657
2658 @noindent
2659 where each @var{alternative} is a music expression.  If you do not
2660 give enough alternatives for all of the repeats, the first alternative
2661 is assumed to be played more than once.
2662
2663 Standard repeats are used like this
2664 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
2665 c1
2666 \repeat volta 2 { c4 d e f }
2667 \repeat volta 2 { f e d c }
2668 @end lilypond
2669
2670 With alternative endings
2671 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
2672 c1
2673 \repeat volta 2 {c4 d e f}
2674 \alternative { {d2 d} {f f,} }
2675 @end lilypond
2676
2677 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
2678 \context Staff {
2679   \partial 4
2680   \repeat volta 4 { e | c2 d2 | e2 f2 | }
2681   \alternative { { g4 g g } { a | a a a a | b2. } }
2682 }
2683 @end lilypond
2684
2685 It is possible to shorten volta brackets
2686 by setting @code{voltaSpannerDuration}.  In the next example, the
2687 bracket only lasts one measure, which is a duration of 3/4.
2688
2689 @lilypond[verbatim,raggedright,quote]
2690 \relative c''{
2691   \time 3/4
2692   c c c
2693   \set Staff.voltaSpannerDuration = #(ly:make-moment 3 4)
2694   \repeat "volta" 5 { d d d }
2695   \alternative { { e e e f f f }
2696   { g g g } }
2697 }
2698 @end lilypond
2699
2700
2701 @seealso
2702
2703 Examples:
2704
2705 Brackets for the repeat are normally only printed over the topmost
2706 staff.  This can be adjusted by setting the @code{voltaOnThisStaff}
2707 property; see @inputfileref{input/@/regression,volta@/-multi@/-staff@/.ly}.
2708
2709
2710 @refbugs
2711
2712 @cindex repeat, ambiguous
2713
2714 A nested repeat like
2715
2716 @example
2717 \repeat @dots{}
2718 \repeat @dots{}
2719 \alternative
2720 @end example
2721
2722 @noindent
2723 is ambiguous, since it is is not clear to which @code{\repeat} the
2724 @code{\alternative} belongs.  This ambiguity is resolved by always
2725 having the @code{\alternative} belong to the inner @code{\repeat}.
2726 For clarity, it is advisable to use braces in such situations.
2727
2728 Timing information is not remembered at the start of an alternative,
2729 so after a repeat timing information must be reset by hand, for
2730 example by setting @code{Score.measurePosition} or entering
2731 @code{\partial}.  Similarly, slurs or ties are also not repeated.
2732
2733
2734 @node Repeats and MIDI
2735 @subsection Repeats and MIDI
2736
2737 @cindex expanding repeats
2738 @cindex @code{\unfoldRepeats}
2739
2740 With a little bit of tweaking, all types of repeats can be present
2741 in the MIDI output.  This is achieved by applying the
2742 @code{\unfoldRepeats} music function.  This functions changes all
2743 repeats to unfold repeats.
2744
2745 @lilypond[quote,verbatim,fragment,linewidth=8.0\cm]
2746 \unfoldRepeats {
2747   \repeat tremolo 8 {c'32 e' }
2748   \repeat percent 2 { c''8 d'' }
2749   \repeat volta 2 {c'4 d' e' f'}
2750   \alternative {
2751     { g' a' a' g' }
2752     {f' e' d' c' }
2753   }
2754 }
2755 \bar "|."
2756 @end lilypond
2757
2758 When creating a score file using @code{\unfoldRepeats} for midi, then
2759 it is necessary to make two @code{\score} blocks.  One for MIDI (with
2760 unfolded repeats) and one for notation (with volta, tremolo, and
2761 percent repeats).  For example,
2762
2763 @example
2764 \score @{
2765   @var{..music..}
2766   \layout @{ .. @}
2767 @}
2768 \score @{
2769   \unfoldRepeats @var{..music..}
2770   \midi @{ .. @}
2771 @}
2772 @end example
2773
2774
2775 @node Manual repeat commands
2776 @subsection Manual repeat commands
2777
2778 @cindex @code{repeatCommands}
2779
2780 The property @code{repeatCommands} can be used to control the layout of
2781 repeats.  Its value is a Scheme list of repeat commands.
2782
2783 @table @asis
2784 @item @code{start-repeat}
2785 Print a @code{|:} bar line.
2786
2787 @item @code{end-repeat}
2788 Print a @code{:|} bar line.
2789
2790 @item @code{(volta @var{text})}
2791 Print a volta bracket saying @var{text}: The text can be specified as
2792 a text string or as a markup text, see @ref{Text markup}.  Do not
2793 forget to change the font, as the default number font does not contain
2794 alphabetic characters;
2795
2796 @item @code{(volta #f)}
2797 Stop a running volta bracket.
2798 @end table
2799
2800 @lilypond[quote,raggedright,verbatim,fragment,relative=2]
2801 c4
2802   \set Score.repeatCommands = #'((volta "93") end-repeat)
2803 c4 c4
2804   \set Score.repeatCommands = #'((volta #f))
2805 c4 c4
2806 @end lilypond
2807
2808
2809 @seealso
2810
2811 Program reference: @internalsref{VoltaBracket}, @internalsref{RepeatedMusic},
2812 @internalsref{VoltaRepeatedMusic},
2813 @internalsref{UnfoldedRepeatedMusic}, and
2814 @internalsref{FoldedRepeatedMusic}.
2815
2816
2817 @node Tremolo repeats
2818 @subsection Tremolo repeats
2819
2820 @cindex tremolo beams
2821
2822 To place tremolo marks between notes, use @code{\repeat} with tremolo
2823 style
2824 @lilypond[quote,verbatim,raggedright]
2825 \new Voice \relative c' {
2826   \repeat "tremolo" 8 { c16 d16 }
2827   \repeat "tremolo" 4 { c16 d16 }
2828   \repeat "tremolo" 2 { c16 d16 }
2829 }
2830 @end lilypond
2831
2832 Tremolo marks can also be put on a single note.  In this case, the
2833 note should not be surrounded by braces.
2834 @lilypond[quote,verbatim,raggedright]
2835 \repeat "tremolo" 4 c'16
2836 @end lilypond
2837
2838 Similar output is obtained using the tremolo subdivision, described in
2839 @ref{Tremolo subdivisions}.
2840
2841
2842 @seealso
2843
2844 In this manual: @ref{Tremolo subdivisions}, @ref{Repeats}.
2845
2846 Program reference: @internalsref{Beam}, @internalsref{StemTremolo}.
2847
2848 Example files: @inputfileref{input/@/regression,chord@/-tremolo@/.ly},
2849 @inputfileref{input/@/regression,stem@/-tremolo@/.ly}.
2850
2851
2852 @node Tremolo subdivisions
2853 @subsection Tremolo subdivisions
2854
2855 @cindex tremolo marks
2856 @cindex @code{tremoloFlags}
2857
2858 Tremolo marks can be printed on a single note by adding
2859 `@code{:}[@var{number}]' after the note.  The number indicates the
2860 duration of the subdivision, and it must be at least 8.  A
2861 @var{length} value of 8 gives one line across the note stem.  If the
2862 length is omitted, the last value (stored in @code{tremoloFlags}) is
2863 used
2864
2865 @lilypond[quote,raggedright,verbatim,fragment]
2866 c'2:8 c':32 | c': c': |
2867 @end lilypond
2868
2869
2870 @refbugs
2871
2872 Tremolos entered in this way do not carry over into the MIDI output.
2873
2874
2875 @seealso
2876
2877 In this manual: @ref{Tremolo repeats}.
2878
2879 Elsewhere: @internalsref{StemTremolo}.
2880
2881
2882 @node Measure repeats
2883 @subsection Measure repeats
2884
2885 @cindex percent repeats
2886 @cindex measure repeats
2887
2888 In the @code{percent} style, a note pattern can be repeated.  It is
2889 printed once, and then the pattern is replaced with a special sign.
2890 Patterns of one and two measures are replaced by percent-like signs,
2891 patterns that divide the measure length are replaced by slashes.
2892 Percent repeats must be declared within a @code{Voice} context.
2893
2894 @lilypond[quote,verbatim,raggedright]
2895 \new Voice \relative c' {
2896   \repeat "percent" 4 { c4 }
2897   \repeat "percent" 2 { c2 es2 f4 fis4 g4 c4 }
2898 }
2899 @end lilypond
2900
2901
2902 @seealso
2903
2904 Program reference: @internalsref{RepeatSlash}, @internalsref{PercentRepeat},
2905 @internalsref{PercentRepeatedMusic}, and
2906 @internalsref{DoublePercentRepeat}.
2907