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