]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/refman.itely
clean input/bugs/
[lilypond.git] / Documentation / user / refman.itely
1 @c Note: -*-texinfo-*-
2 @c
3 @c A menu is needed before every deeper *section nesting of @node's; run
4 @c     M-x texinfo-all-menus-update
5 @c to automagically fill in these menus before saving changes
6
7 @c FIXME: singular vs. plural:  Beams/Beam
8
9
10 @macro refbugs
11 @strong{BUGS}
12
13 @end macro
14
15
16 @c .{Reference Manual}
17
18 @node Reference Manual
19 @chapter Reference Manual
20
21 @html
22 <!--- @@WEB-TITLE@@=Reference Manual --->
23 @end html
24
25 This document describes GNU LilyPond and its input format. The last
26 revision of this document was made for LilyPond 1.4.1.  It supposes a
27 passing familiarity with how LilyPond input works. New users are
28 encouraged to study the tutorial first.
29
30
31 @menu
32 * Note entry::                  
33 * Easier music entry::          
34 * Staff notation::              
35 * Polyphony::                   
36 * Beaming::                     
37 * Accidentals::                 
38 * Expressive marks::            
39 * Ornaments::                   
40 * Repeats::                     
41 * Rhythmic music::              
42 * Piano music::                 
43 * Tablatures::                  
44 * Chords::                      
45 * Writing parts::               
46 * Ancient notation ::           
47 * Tuning output::               
48 * Global layout::               
49 * Sound::                       
50 @end menu
51
52 @c FIXME: Note entry vs Music entry at top level menu is confusing.
53 @c . {Note entry}
54 @node Note entry
55 @section Note entry
56 @cindex Note entry
57
58 The most basic forms of music are notes.  Notes on their own don't
59 form valid input, but for the sake of brevity we omit @code{\score}
60 blocks and @code{\paper} declarations.
61
62
63 @menu
64 * Notes::                       
65 * Pitches::                     
66 * Chromatic alterations::       
67 * Rests::                       
68 * Skips::                       
69 * Durations::                   
70 * Ties::                        
71 * Automatic note splitting ::   
72 * Tuplets::                     
73 * Easy Notation note heads ::   
74 @end menu
75
76 @c . {Notes}
77 @node Notes
78 @subsection Notes
79
80
81 A note is printed by specifying its pitch, and then its duration.
82 @lilypond[fragment,verbatim]
83   cis'4 d'8 e'16 c'16
84 @end lilypond
85
86 @c .  {Pitches}
87 @node Pitches
88 @subsection Pitches
89
90 @cindex Pitch names
91 @cindex Note specification
92 @cindex pitches
93 @cindex entering notes
94
95 The verbose syntax for pitch specification is
96
97 @cindex @code{\pitch}
98 @example
99   \pitch @var{scmpitch}
100 @end example
101
102 @var{scmpitch} is a pitch scheme object.
103
104 In Note and Chord mode, pitches may be designated by names.  The default
105 names are the Dutch note names.  The notes are specified by the letters
106 @code{a} through @code{g} (where the octave is formed by notes ranging
107 from @code{c} to @code{b}).  The pitch @code{c} is an octave below
108 middle C and the letters span the octave above that C.
109
110 @cindex note names, Dutch
111
112 In Dutch, a sharp is formed by adding @code{-is} to the end of a pitch
113 name and a flat is formed by adding @code{-es}. Double sharps and double
114 flats are obtained by adding @code{-isis} or @code{-eses}.  @code{aes}
115 and @code{ees} are contracted to @code{as} and @code{es} in Dutch, but
116 both forms are accepted.
117
118 LilyPond has predefined sets of note names for various other languages.
119 To use them, simply include the language specific init file.  For
120 example: @code{\include "english.ly"}.  The available language files and
121 the names they define are:
122
123 @example 
124                         Note Names               sharp       flat
125 nederlands.ly  c   d   e   f   g   a   bes b   -is         -es
126 english.ly     c   d   e   f   g   a   bf  b   -s/-sharp   -f/-flat
127 deutsch.ly     c   d   e   f   g   a   b   h   -is         -es
128 norsk.ly       c   d   e   f   g   a   b   h   -iss/-is    -ess/-es
129 svenska.ly     c   d   e   f   g   a   b   h   -iss        -ess
130 italiano.ly    do  re  mi  fa  sol la  sib si  -d          -b
131 catalan.ly     do  re  mi  fa  sol la  sib si  -d/-s       -b 
132 espanol.ly     do  re  mi  fa  sol la  sib si  -s          -b 
133
134 @end example 
135
136 @cindex @code{'}
137 @cindex @code{,}
138
139
140
141 The optional octave specification takes the form of a series of
142 single quote (`@code{'}') characters or a series of comma
143 (`@code{,}') characters.  Each @code{'} raises the pitch by one
144 octave; each @code{,} lowers the pitch by an octave.
145
146 @lilypond[fragment,verbatim,center]
147   c' c'' es' g' as' gisis' ais'  
148 @end lilypond
149
150 @node Chromatic alterations
151 @subsection Chromatic alterations
152
153 Normally, accidentals are printed automatically, but you may force
154 accidentals in the following ways: A reminder accidental
155 @cindex reminder accidental
156 @cindex @code{?}
157 can be forced by adding an exclamation mark @code{!} after the pitch.  A
158 cautionary accidental,
159 @cindex cautionary accidental
160 @cindex parenthesized accidental
161 i.e., an accidental within parentheses can be obtained by adding the
162 question mark `@code{?}' after the pitch.
163
164 The automatic production of accidentals can be tuned in many
165 ways. Refer to @ref{Accidentals} for more information.
166
167 @c .  {Rests}
168 @node  Rests
169 @subsection Rests
170 @cindex Rests
171
172 A rest is entered like a note, with note name `@code{r}':
173
174 @lilypond[singleline,verbatim]
175 r1 r2 r4 r8
176 @end lilypond
177
178 Whole bar rests centered in the bar are specified using @code{R}, see
179 @ref{Multi measure rests}. See also @seeinternals{Rest}.
180
181 For polyphonic music, it can be convenient to specify the rest position
182 directly. You can do that by entering a note, with the keyword
183 @code{\rest} appended, e.g. Rest collisions will leave these rests alone.
184
185 @lilypond[singleline,verbatim]
186 a'4\rest d'4\rest
187 @end lilypond
188
189
190 @c .  {Skips}
191 @c FIXME: naming.
192 @node Skips
193 @subsection Skips
194 @cindex Skip
195 @cindex Invisible rest
196 @cindex Space note
197
198 An invisible rest, or skip, can be entered like a note with note name
199 @code{s}, or with @code{\skip @var{duration}}:
200
201 @lilypond[singleline,verbatim]
202 a2 s4 a4 \skip 1 a4 
203 @end lilypond
204
205 The @code{s} syntax  is only available in Note mode and Chord mode. 
206 In other situations, you should use the @code{\skip} command, and it is
207 only available in Note mode and Chord mode.
208
209 @c FIXME: in lyrics mode, we have " " and _
210
211 In Lyrics mode, you can use `@code{" "}' and `@code{_}':
212 @lilypond[singleline,verbatim]
213 <
214   \context Lyrics \lyrics { lah2 di4 " " dah2 _4 di }
215   \notes\relative c'' { a2 a4 a a2 a4 a }
216 >
217 @end lilypond
218
219 The unabbreviated `@code{\skip} @var{duration}' also works outside of
220 note mode:
221
222 @lilypond[singleline,verbatim]
223 \score {
224   \context Staff <
225     { \time 4/8 \skip 2 \time 4/4 } 
226     \notes\relative c'' { a2 a1 }
227   >
228 }
229 @end lilypond
230
231 The skip command is merely a empty musical placeholder. It does not
232 produce any output, not even transparent output.
233
234
235 @c .  {Durations}
236 @node Durations
237 @subsection Durations
238
239
240 @cindex duration
241 @cindex @code{\duration}
242
243
244 In Note, Chord, and Lyrics mode, durations may be designated by numbers
245 and dots: durations are entered as their reciprocal values.  For notes
246 longer than a whole you must use identifiers.
247
248 @example 
249  c'\breve  
250 c'1 c'2 c'4 c'8 c'16 c'32 c'64 c'64 
251 r\longa r\breve  
252 r1 r2 r4 r8 r16 r32 r64 r64 
253 @end example 
254
255
256 @lilypond[]
257 \score {
258   \notes \relative c'' {
259     a\breve  \autoBeamOff
260     a1 a2 a4 a8 a16 a32 a64 a64 
261     r\longa r\breve  
262     r1 r2 r4 r8 r16 r32 r64 r64 
263   }
264   \paper {
265     \translator {
266       \StaffContext
267         \remove "Clef_engraver"
268         \remove "Staff_symbol_engraver"
269         \remove "Time_signature_engraver"
270         \consists "Pitch_squash_engraver"
271     }
272   }
273 }
274 @end lilypond
275
276
277 If the duration is omitted then it is set to the previous duration
278 entered.  At the start of parsing a quarter note is assumed.  The
279 duration can be followed by dots (`@code{.}')  to obtain dotted note
280 lengths.
281 @cindex @code{.}
282
283 @lilypond[fragment,verbatim,center]
284   a'4. b'4.. c'8.
285 @end lilypond
286 @cindex @code{r}
287 @cindex @code{s}
288
289 You can alter the length of duration by a fraction @var{N/M} by
290 appending `@code{*}@var{N/M}' (or `@code{*}@var{N}' if @var{M=1}). This
291 will not affect the appearance of the notes or rests produced.
292
293 Durations can also be produced through GUILE extension mechanism. 
294 @lilypond[verbatim,fragment]
295  c\duration #(make-duration 2 1)
296 @end lilypond
297
298
299 @node Ties
300 @subsection Ties
301
302 @cindex Tie
303 @cindex ties
304 @cindex @code{~}
305
306 A tie connects two adjacent note heads of the same pitch.  The tie in
307 effect extends the length of a note. A tie is entered with @code{~}.
308
309 @lilypond[fragment,verbatim,center]
310   e' ~ e' <c' e' g'> ~ <c' e' g'>
311 @end lilypond
312
313 When ties are used with chords, all note heads whose pitches match are
314 connected.  Ties are indicated using the tilde symbol `@code{~}'.  If
315 you try to tie together chords which have no common pitches then no
316 ties will be created.
317
318 If you want less  ties created for a chord, you can  set
319 @code{Voice.sparseTies} to true. In this case, a single tie is used
320 for every tied chord.
321 @lilypond[fragment,verbatim,center]
322   \property Voice.sparseTies = ##t
323   <c' e' g'> ~ <c' e' g'>
324 @end lilypond
325
326 In its meaning a tie is just a way of extending a note duration, similar
327 to the augmentation dot: the following example are two ways of notating
328 exactly the same concept.
329 @c
330 @lilypond[fragment, singleline]
331 \time 3/4 c'2. c'2 ~ c'4
332 @end lilypond
333 Ties should not be confused with slurs, which indicate articulation,
334 and phrasing slurs, which indicate musical phrasing.
335
336 See also  @seeinternals{Tie}.
337
338
339 @refbugs
340
341 At present, the tie is represented as a separate event, temporally
342 located in between the notes.  Tieing only a subset of the note heads
343 of a chord is not supported in a simple way.  It can be achieved by
344 moving the tie-engraver into the Thread context and turning on and off
345 ties per Thread.
346
347 Switching staffs when a tie is active will not work.
348
349 @node Automatic note splitting 
350 @subsection Automatic note splitting
351 @c FIXME: This subsection doesn't belong in @ref{Note entry}.
352
353 There is a facility for automatically converting long notes to  tied
354 notes. This is done by replacing the @code{Note_heads_engraver} by the
355 @code{Completion_heads_engraver}. 
356
357 @lilypond[verbatim,center]
358 \score{
359   \notes\relative c'{ \time 2/4
360   c2. c8 d4 e f g a b c8 c2 b4 a g16 f4 e d c8. c2 
361   }
362   \paper{ \translator{
363       \ThreadContext
364       \remove "Note_heads_engraver"
365       \consists "Completion_heads_engraver"
366   } } }
367 @end lilypond
368
369 This engraver splits all running notes at the bar line, and inserts
370 ties. One of its uses is to debug complex scores: if the measures are
371 not entirely filled, then the ties exactly show how much each measure
372 is off.
373
374 @refbugs
375
376 Not all durations (especially those containing tuplets) can be
377 represented exactly; the engraver will not insert tuplets. 
378
379 @node Tuplets
380 @subsection Tuplets
381
382 @cindex tuplets
383 @cindex triplets
384 @cindex @code{\times}
385
386 Tuplets are made out of a music expression by multiplying all duration
387 with a fraction.
388
389 @cindex @code{\times}
390 @example
391   \times @var{fraction} @var{musicexpr}
392 @end example
393
394 The duration of @var{musicexpr} will be multiplied by the fraction. 
395 In print, the fraction's denominator will be printed over the notes,
396 optionally with a bracket.  The most common tuplet is the triplet in
397 which 3 notes have the length of 2, so the notes are 2/3 of
398 their written length:
399
400 @lilypond[fragment,verbatim,center]
401   g'4 \times 2/3 {c'4 c' c'} d'4 d'4
402 @end lilypond
403
404 The property @code{tupletSpannerDuration} specifies how long each bracket
405 should last.  With this, you can make lots of tuplets while typing
406 @code{\times} only once, thus  saving typing work.
407
408 @lilypond[fragment,  relative, singleline, verbatim]
409 \property Voice.tupletSpannerDuration = #(make-moment 1 4)
410 \times 2/3 { c'8 c c c c c }
411 @end lilypond
412
413 The format of the number is determined by the property
414 @code{tupletNumberFormatFunction}. The default prints only the
415 denominator, but if you set it to the Scheme function
416 @code{fraction-tuplet-formatter}, Lilypond will print @var{num}:@var{den}
417 instead.
418
419
420 @cindex @code{tupletNumberFormatFunction}
421 @cindex tuplet formatting 
422
423 See also @seeinternals{TupletBracket}.
424
425 @refbugs
426
427 Nested tuplets are not formatted automatically. In this case, outer
428 tuplet brackets should be moved automatically.
429
430 @node Easy Notation note heads 
431 @subsection Easy Notation note heads
432
433 @cindex easy notation
434 @cindex Hal Leonard
435
436 A entirely different type of note head is the "easyplay" note head: a
437 note head that includes a note name.  It is used in some publications by
438 Hal-Leonard Inc.  music publishers.
439
440 @lilypond[singleline,verbatim,26pt]
441 \score {
442   \notes { c'2 e'4 f' | g'1 }
443   \paper { \translator { \EasyNotation } } 
444 }
445 @end lilypond
446
447 Note that @code{EasyNotation} overrides a @internalsref{Score} context.  You
448 probably will want to print it with magnification or a large font size to make it more
449 readable.
450
451
452 @cindex Xdvi
453 @cindex ghostscript
454
455 If you view the result with Xdvi, then staff lines will show through
456 the letters.  Printing the PostScript file obtained with ly2dvi does
457 produce the correct result.
458
459
460 @node Easier music entry
461 @section Easier music entry
462 @cindex Music entry
463 @menu
464 * Graphical interfaces::        
465 * Relative octaves::            
466 * Bar check::                   
467 * Point and click::             
468 * Skipping corrected music::    
469 @end menu
470
471 When entering music with LilyPond, it is easy to introduce errors. This
472 section deals with tricks and features that help you enter music, and
473 find and correct mistakes.
474
475 @node Graphical interfaces
476 @subsection Graphical interfaces
477
478 @cindex GUI
479 @cindex graphical interface
480 @cindex sequencer
481 @cindex RoseGarden
482 @cindex Denemo
483 @cindex NoteEdit
484 @cindex MIDI
485
486 One way to avoid entering notes using the keyboard, is to use  a
487 graphical user interface.  The following programs are known to have
488 a lilypond export option:
489
490 @itemize @bullet
491 @item
492 @uref{http://denemo.sourceforge.net/, Denemo}, was once intended as
493 LilyPond graphical user interface.  It run on Gnome/GTK.
494 @item
495 @uref{http://rnvs.informatik.tu-chemnitz.de/~jan/noteedit/noteedit.html,noteedit}
496 NoteEdit is a graphical score editor that runs under KDE/Qt.
497 @item
498 @uref{http://rosegarden.sf.net/,RoseGarden}
499 once was an inspiration for naming LilyPond. Nowadays, it has been
500 rewritten from scratch, and supports LilyPond export as of version
501 0.1.6.
502 @end itemize
503
504 Another option is to enter the music using your favorite MIDI
505 sequencer, and then import it using midi2ly. midi2ly is described in
506 @ref{Importing MIDI}.
507
508 @c .  {Relative}
509 @node Relative octaves
510 @subsection Relative octaves
511 @cindex Relative
512 @cindex relative octave specification
513
514 Octaves are specified by adding @code{'} and @code{,} to pitch names.
515 When you copy existing music, it is easy to accidentally put a pitch in
516 the wrong octave and hard to find such an error.  To prevent these
517 errors, LilyPond features octave entry.
518
519 @cindex @code{\relative}
520 @example
521   \relative @var{startpitch} @var{musicexpr}
522 @end example
523
524 The octave of notes that appear in @var{musicexpr} are calculated as
525 follows: If no octave changing marks are used, the basic interval
526 between this and the last note is always taken to be a fourth or less
527 (This distance is determined without regarding alterations; a
528 @code{fisis} following a @code{ceses} will be put above the
529 @code{ceses})
530
531 The octave changing marks @code{'} and @code{,} can be added to raise or
532 lower the pitch by an extra octave.  Upon entering relative mode, an
533 absolute starting pitch must be specified that will act as the
534 predecessor of the first note of @var{musicexpr}.
535
536 Entering music that changes octave frequently  is easy in relative mode.
537 @lilypond[fragment,singleline,verbatim,center]
538   \relative c'' {
539     b c d c b c bes a 
540   }
541 @end lilypond
542
543 And octave changing marks are used for intervals greater than a fourth.
544 @lilypond[fragment,verbatim,center]
545   \relative c'' {
546     c g c f, c' a, e'' }
547 @end lilypond
548
549 If the preceding item is a chord, the first note of the chord is used
550 to determine the first note of the next chord. However, other notes
551 within the second chord are determined by looking at the immediately
552 preceding note.
553
554 @lilypond[fragment,verbatim,center]
555   \relative c' {
556     c <c e g> 
557     <c' e g>
558     <c, e' g>
559   }
560 @end lilypond 
561 @cindex @code{\notes}
562
563 The pitch after the @code{\relative} contains a note name.  To parse
564 the pitch as a note name, you have to be in note mode, so there must
565 be a surrounding @code{\notes} keyword (which is not
566 shown here).
567
568 The relative conversion will not affect @code{\transpose},
569 @code{\chords} or @code{\relative} sections in its argument.  If you
570 want to use relative within transposed music, you must place an
571 additional @code{\relative} inside the @code{\transpose}.
572
573
574 @c .  {Bar check}
575 @node Bar check
576 @subsection Bar check
577 @cindex Bar check
578
579 @cindex bar check
580 @cindex @code{barCheckSynchronize}
581 @cindex @code{|}
582
583
584 Whenever a bar check is encountered during interpretation, a warning
585 message is issued if it doesn't fall at a measure boundary.  This can
586 help you find errors in the input.  Depending on the value of
587 @code{barCheckSynchronize}, the beginning of the measure will be
588 relocated, so this can also be used to shorten measures.
589
590 A bar check is entered using the bar symbol, @code{|}:
591 @example
592   \time 3/4 c2 e4 | g2.
593 @end example
594
595
596
597 @cindex skipTypesetting
598
599 Failed bar checks are most often caused by entering incorrect
600 durations. Incorrect durations often completely garble up the score,
601 especially if it is polyphonic, so you should start correcting the score
602 by scanning for failed bar checks and incorrect durations.  To speed up
603 this process, you can use @code{skipTypesetting} (See @ref{Skipping
604 corrected music})). 
605
606 @c .  {Point and click}
607 @node Point and click
608 @subsection Point and click
609 @cindex poind and click
610
611 Point and click lets you find notes in the input by clicking on them in
612 the Xdvi window. This makes it very easy to find input that causes some
613 error in the sheet music.
614
615 To use it, you need the following software
616 @itemize @bullet
617 @item A dvi viewer that supports src specials.
618 @itemize @bullet
619 @item Plain Xdvi, version 22.36 or newer.  Available from
620 @uref{ftp://ftp.math.berkeley.edu/pub/Software/TeX/xdvi.tar.gz,ftp.math.berkeley.edu}.
621
622   Note that most @TeX{} distributions ship with xdvik, which is a
623   different and less well maintained program. To find out which xdvi you
624   are running, try @code{xdvi --version} or @code{xdvi.bin --version}.
625 @item KDVI.  A dvi viewer for KDE.  You need KDVI from KDE 3.0 or
626 newer.  Enablle the menu Settings -> Inverse search. 
627 @end itemize
628 @item An editor with a client/server interface (or a lightweight GUI editor).
629 @itemize @bullet
630 @item Emacs. Emacs is an extensible text-editor.  It is available from
631 @uref{http://www.gnu.org/software/emacs/}.  You need version 21 to use
632 column location.
633 @item XEmacs. Xemacs is very similar to emacs.
634 @item NEdit.  NEdit runs under Windows, and Unix.
635   It is available from @uref{http://www.nedit.org}.
636 @item GVim.  GVim is a lightweight GUI variant of VIM, the popular VI
637 clone.  It is available from @uref{http://www.vim.org}.
638 @end itemize
639 @end itemize
640
641
642 Xdvi must be configured to find the @TeX{} fonts and music
643 fonts. Refer to the Xdvi documentation for more information.
644
645 To use point-and-click, add one of these lines to the top of your .ly
646 file.
647 @example
648 #(set! point-and-click line-location)
649 @end example
650 @cindex line-location
651
652 When viewing, Control-Mousebutton 1 will take you to the originating
653 spot in the @file{.ly} file.  Control-Mousebutton 2 will show all
654 clickable boxes.
655
656 If you correct large files with point-and-click, be sure to start
657 correcting at the end of the file. When you start at the top, and
658 insert one line, all following locations will be off by a line.
659
660 @cindex Emacs
661 For using point-and-click with emacs,  add the following
662 In your emacs startup file (usually @file{~/.emacs}), 
663 @example
664 (server-start)
665 @end example
666
667 Make sure that the environment variable @var{XEDITOR} is set to
668 @example
669 emacsclient --no-wait +%l %f
670 @end example
671 @cindex @var{XEDITOR}
672 If you use xemacs instead of emacs, you use @code{(gnuserve-start)} in
673 your @file{.emacs}, and set @code{XEDITOR} to @code{gnuclient -q +%l %f}
674
675 For using Vim, set @code{XEDITOR} to @code{gvim +%l %f}, or use this
676 argument with xdvi's @code{-editor} option.
677 @cindex NEdit
678 For using NEdit, set @code{XEDITOR} to @code{nc -noask +%l %f}, or
679 use this argument with xdvi's @code{-editor} option.
680
681 If can also make your editor jump to the exact location of the note
682 you clicked. This is only supported on Emacs. Users of version 20 must
683 apply the patch @file{emacsclient.patch}. Users of version 21 must
684 apply @file{server.el.patch} (version 21.2 and earlier).  At the top
685 of the @code{ly} file, replace the @code{set!} line with the following
686 line,
687 @example
688 #(set! point-and-click line-column-location)
689 @end example
690 @cindex line-colomn-location
691 and set @code{XEDITOR} to @code{emacsclient --no-wait +%l:%c %f}.
692
693 @refbugs
694
695 When you convert the @TeX{} file to PostScript using @code{dvips}, it
696 will complain about not finding @code{src:X:Y} files. These complaints
697 are harmless, and can be ignored.
698
699 @node Skipping corrected music
700 @subsection Skipping corrected music
701
702 The property @code{Score.skipTypesetting} can be used to switch on and
703 off typesetting completely during the interpretation phase. When
704 typesetting is switched off, the music is processed much more quickly.
705 You can use this to skip over the parts of a score that you have already
706 checked for errors. 
707
708 @lilypond[fragment,singleline,verbatim]
709 \relative c'' { c8 d
710 \property Score.skipTypesetting = ##t
711   e f g a g c, f e d
712 \property Score.skipTypesetting = ##f
713 c d b bes a g c2 } 
714 @end lilypond
715
716
717
718
719 @node Staff notation
720 @section Staff notation
721
722 This section deals with music notation that occurs on staff level,
723 such as keys, clefs and time signatures.
724
725 @cindex Staff notation
726
727 @menu
728 * Key signature::               
729 * Clef::                        
730 * Time signature::              
731 * Unmetered music::             
732 * Bar lines::                   
733 @end menu
734
735 @c .  {Key}
736 @node Key signature
737 @subsection Key signature
738 @cindex Key
739
740 @cindex @code{\key}
741
742 Setting or changing the key signature is done with the @code{\key}
743 command.
744 @example
745   @code{\key} @var{pitch} @var{type}
746 @end example
747
748 @cindex @code{\minor}
749 @cindex @code{\major}
750 @cindex @code{\minor}
751 @cindex @code{\ionian}
752 @cindex @code{\locrian}
753 @cindex @code{\aeolian}
754 @cindex @code{\mixolydian}
755 @cindex @code{\lydian}
756 @cindex @code{\phrygian}
757 @cindex @code{\dorian}
758
759 Here, @var{type} should be @code{\major} or @code{\minor} to get
760 @var{pitch}-major or @var{pitch}-minor, respectively.
761 The standard mode names @code{\ionian},
762 @code{\locrian}, @code{\aeolian}, @code{\mixolydian}, @code{\lydian},
763 @code{\phrygian}, and @code{\dorian} are also defined.
764
765 This command sets the context property @code{Staff.keySignature}. 
766 Non-standard key signatures can be specified by setting this property
767 directly.
768
769 The printed signature is a @internalsref{KeySignature} grob, typically
770 created in @internalsref{Staff} context.
771
772 @cindex @code{keySignature}
773
774 @c .  {Clef}
775 @node Clef
776 @subsection Clef
777 @cindex @code{\clef}
778
779 The clef can be set or changed with the @code{\clef} command:
780 @lilypond[fragment,verbatim]
781   \key f\major  c''2 \clef alto g'2
782 @end lilypond
783
784 Supported clef-names include 
785 @c Moved standard clefs to the top /MB
786 @table @code
787 @item treble, violin, G, G2
788 G clef on 2nd line
789 @item alto, C
790  C clef on 3rd line
791 @item tenor
792  C clef on 4th line
793 @item bass, F
794  F clef on 4th line
795 @item french
796  G clef on 1st line, so-called French violin clef
797 @item soprano
798  C clef on 1st line
799 @item mezzosoprano
800  C clef on 2nd line
801 @item baritone
802  C clef on 5th line
803 @item varbaritone
804  F clef on 3rd line
805 @item subbass
806  F clef on 5th line
807 @item percussion
808  percussion 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.  Note that you have to
813 enclose @var{clefname} in quotes if you use underscores or digits in the
814 name. For example,
815 @example
816         \clef "G_8"
817 @end example
818
819 The grob for this symbol is @internalsref{Clef}. 
820
821
822 This command is equivalent to setting @code{clefGlyph},
823 @code{clefPosition} (which controls the Y position of the clef),
824 @code{centralCPosition} and @code{clefOctavation}. A clef is created
825 when any of these properties are changed.
826
827
828 @c .  {Time signature}
829 @node Time signature
830 @subsection Time signature
831 @cindex Time signature
832 @cindex meter
833 @cindex @code{\time}
834
835 The time signature is set or changed by the @code{\time}
836 command.
837 @lilypond[fragment,verbatim]
838  \time 2/4 c'2 \time 3/4 c'2. 
839 @end lilypond
840
841 The actual symbol that's printed can be customized with the @code{style}
842 property. Setting it to @code{#'()} uses fraction style for 4/4 and
843 2/2 time.
844
845
846 The grob for this symbol is @internalsref{TimeSignature}.  There are
847 many more options for its layout. They are selected through the
848 @code{style} grob property. See @file{input/test/time.ly} for more
849 examples.
850
851 This command sets the property @code{timeSignatureFraction},
852 @code{beatLength} and @code{measureLength}.  The property
853 @code{timeSignatureFraction} determine where bar lines should be
854 inserted, and how automatic beams should be generated.  Changing the
855 value of @code{timeSignatureFraction} also causes a time signature
856 symbol to be printed.
857
858 @c .   {Partial}
859 @subsection Partial
860 @cindex Partial
861 @cindex anacrusis
862 @cindex upbeat
863 @cindex partial measure
864 @cindex measure, partial
865 @cindex shorten measures
866 @cindex @code{\partial}
867
868 Partial measures, for example in upbeats, are entered using the
869 @code{\partial} command:
870 @lilypond[fragment,verbatim]
871 \partial 4* 5/16  c'16 c4 f16 a'2. ~ a'8. a'16 | g'1
872 @end lilypond
873
874 The syntax for this command is 
875 @example
876   \partial @var{duration} 
877 @end example
878 This is  internally translated into
879 @example
880   \property Score.measurePosition = -@var{length of duration}
881 @end example
882 @cindex @code{|}
883 The property @code{measurePosition} contains a rational number
884 indicating how much of the measure has passed at this point.
885
886
887 @node Unmetered music
888 @subsection Unmetered music
889
890 Bar lines and bar numbers are calculated automatically. For unmetered
891 music (e.g. cadenzas), this is not desirable.  The commands
892 @code{\cadenzaOn} and @code{\cadenzaOff} can be used to switch off the
893 timing information:
894
895 @lilypond[fragment,relative,singleline,verbatim]
896 c'2.
897 \cadenzaOn
898 c2
899 \cadenzaOff
900 c4 c4 c4 
901 @end lilypond
902
903 The property @code{Score.timing} can be used to switch off this
904 automatic timing
905
906 @c .   {Bar lines}
907 @node Bar lines
908 @subsection Bar lines
909 @cindex Bar lines
910
911 @cindex @code{\bar}
912 @cindex measure lines
913 @cindex repeat bars
914
915 Bar lines are inserted automatically, but if you need a special type
916 of barline, you can force one using the @code{\bar} command:
917 @lilypond[fragment,verbatim] c4 \bar "|:" c4
918 @end lilypond
919
920 The following bar types are available
921 @lilypond[fragment,  relative, singleline, verbatim]
922 c4
923 \bar "|" c
924 \bar "" c
925 \bar "|:" c
926 \bar "||" c
927 \bar ":|" c
928 \bar ".|" c
929 \bar ".|." c
930 \bar "|." 
931 @end lilypond
932
933 You are encouraged to use @code{\repeat} for repetitions.  See
934 @ref{Repeats}.
935
936 In scores with many staffs, the barlines are automatically placed at
937 top level, and they are connected between different staffs of a
938 @internalsref{StaffGroup}:
939 @lilypond[fragment, verbatim]
940 < \context StaffGroup <
941   \context Staff = up { e'4 d'
942      \bar "||"
943      f' e' }
944   \context Staff = down { \clef bass c4 g e g } >
945 \context Staff = pedal { \clef bass c2 c2 } >
946 @end lilypond
947
948 The grobs that are created at @internalsref{Staff} level. The name is
949 @internalsref{BarLine}.
950
951 The command @code{\bar @var{bartype}} is a short cut for
952 doing  @code{\property Score.whichBar = @var{bartype}}
953 Whenever @code{whichBar} is set to a string, a bar line of that type is
954 created.  @code{whichBar} is usually set automatically: at the start of
955 a measure it is set to @code{defaultBarType}. The contents of
956 @code{repeatCommands} is used to override default measure bars.
957
958 @code{whichBar} can also be set directly, using @code{\property} or
959 @code{\bar  }.  These settings take precedence over the automatic
960 @code{whichBar} settings. 
961
962
963 @cindex Bar_line_engraver
964 @cindex whichBar
965 @cindex repeatCommands
966 @cindex defaultBarType
967
968
969
970 @c .   {Polyphony}
971 @node Polyphony
972 @section Polyphony
973 @cindex polyphony
974
975 The easiest way to enter such fragments with more than one voice on a
976 staff is to split chords using the separator @code{\\}.  You can use
977 it for small, short-lived voices (make a chord of voices) or for
978 single chords:
979
980 @lilypond[verbatim,fragment]
981 \context Voice = VA \relative c'' {
982  c4 < { f d e  } \\ { b c2 } > c4 < g' \\ b, \\  f \\ d >
983 }
984 @end lilypond
985
986 The separator causes @internalsref{Voice} contexts to be instantiated,
987 bearing the names @code{"1"}, @code{"2"}, etc.
988
989 Sometimes, it is necessary to instantiate these contexts by hand: For
990 Instantiate a separate Voice context for each part, and use
991 @code{\voiceOne}, up to @code{\voiceFour} to assign a stem directions
992 and horizontal shift for each part.
993 @c
994
995 @lilypond[singleline, verbatim]
996 \relative c''
997 \context Staff < \context Voice = VA { \voiceOne cis2 b  }
998   \context Voice = VB { \voiceThree b4 ais ~ ais4 gis4 } 
999   \context Voice = VC { \voiceTwo fis4~  fis4 f ~ f  } >
1000 @end lilypond
1001
1002 The identifiers @code{\voiceOne} to @code{\voiceFour} set directions
1003 ties, slurs and stems, and set shift directions.
1004
1005 If you want more than four voices, you can also manually set
1006 horizontal shifts and stem directions, as is shown  in the following example:
1007 @lilypond[fragment, verbatim]
1008   \context Staff \notes\relative c''<
1009        \context Voice=one {
1010        \shiftOff \stemUp e4
1011        }
1012        \context Voice=two {
1013           \shiftOn \stemUp cis
1014        }
1015        \context Voice=three {
1016          \shiftOnn \stemUp ais
1017        }
1018        \context Voice=four {
1019           \shiftOnnn \stemUp fis
1020        }
1021   >
1022 @end lilypond
1023
1024
1025 Normally, note heads with a different number of dots are not merged, but
1026 if you set the grob property @code{merge-differently-dotted}, they are:
1027 @lilypond[verbatim,fragment,singleline]
1028 \context Voice < {
1029      g'8 g'8 
1030      \property Staff.NoteCollision \override
1031         #'merge-differently-dotted = ##t
1032      g'8 g'8
1033   } \\ { [g'8. f16] [g'8. f'16] } 
1034   >
1035 @end lilypond
1036
1037 Similarly, you can merge half note heads with eighth notes, by setting
1038 @code{merge-differently-headed}:
1039 @lilypond[fragment, relative=2,verbatim]
1040 \context Voice < {
1041     c8 c4.
1042     \property Staff.NoteCollision
1043       \override #'merge-differently-headed = ##t
1044     c8 c4. } \\ { c2 c2 } >
1045 @end lilypond
1046
1047 LilyPond also vertically shifts rests that are opposite of a stem. 
1048
1049 @lilypond[singleline,fragment,verbatim]
1050 \context Voice < c''4 \\  r4 >
1051 @end lilypond
1052
1053 See also @internalsref{NoteCollision} and @internalsref{RestCollision}
1054
1055 @refbugs
1056
1057 Resolving collisions is a very intricate subject, and LilyPond only
1058 handles a few situations. When it can not cope, you are advised to use
1059 @code{force-hshift} of the @internalsref{NoteColumn} grob and pitched
1060 rests to override typesetting decisions.
1061
1062 @node Beaming
1063 @section Beaming
1064
1065 Beams are used to group short notes into chunks that are aligned with
1066 the metrum. They are inserted automatically in most cases.
1067
1068 @lilypond[fragment,verbatim, relative=2]
1069 \time 2/4 c8 c c c \time 6/8 c c c c8. c16  c8
1070 @end lilypond
1071
1072 If you're not satisfied with the automatic beaming, you can enter the
1073 beams explicitly. If you have beaming patterns that differ from the
1074 defaults, you can also set the patterns for automatic beamer.
1075
1076 See also @internalsref{Beam}.
1077
1078 @c .    {Manual beams}
1079 @cindex Automatic beams
1080 @subsection Manual beams
1081 @cindex beams, manual
1082 @cindex @code{]}
1083 @cindex @code{[}
1084
1085 In some cases it may be necessary to override LilyPond's automatic
1086 beaming algorithm.  For example, the auto beamer will not beam over
1087 rests or bar lines, If you want that, specify the begin and end point
1088 manually using a @code{[} before the first beamed note and a @code{]}
1089 after the last note:
1090
1091 @lilypond[fragment,relative,verbatim]
1092   \context Staff {
1093     r4 [r8 g' a r8] r8 [g | a] r8
1094   }
1095 @end lilypond
1096
1097 @cindex @code{stemLeftBeamCount}
1098
1099 Normally, beaming patterns within a beam are determined automatically.
1100 When this mechanism fouls up, the properties
1101 @code{Voice.stemLeftBeamCount} and @code{Voice.stemRightBeamCount} can
1102 be used to control the beam subdivision on a stem.  If you set either
1103 property, its value will be used only once, and then it is erased.
1104
1105 @lilypond[fragment,relative,verbatim]
1106   \context Staff {
1107     [f8 r16 f g a]
1108     [f8 r16 \property Voice.stemLeftBeamCount = #1 f g a]
1109   }
1110 @end lilypond
1111 @cindex @code{stemRightBeamCount}
1112
1113
1114 The property @code{subdivideBeams} can be set in order to subdivide
1115 all 16th or shorter beams at beat positions.  This accomplishes the
1116 same effect as twiddling with @code{stemLeftBeamCount} and
1117 @code{stemRightBeamCount}, but it take less typing.
1118
1119
1120 @example
1121 [c16 c c c c c c c]
1122 \property Voice.subdivideBeams = ##t
1123 [c16 c c c c c c c]
1124 [c32 c c c c c c c c c c c c c c c]
1125 \property Score.beatLength = #(make-moment 1 8)
1126 [c32 c c c c c c c c c c c c c c c]
1127 @end example
1128 @lilypond[]
1129 \score {
1130     \notes \relative c' {
1131         [c16 c c c c c c c]
1132         \property Voice.subdivideBeams = ##t
1133         [c16 c c c c c c c]
1134         [c32 c c c c c c c c c c c c c c c]
1135         \property Score.beatLength = #(make-moment 1 8)
1136         [c32 c c c c c c c c c c c c c c c]
1137     }
1138 }
1139 @end lilypond
1140 @cindex subdivideBeams
1141
1142 Kneed beams are inserted automatically, when a large gap between two
1143 adjacent beamed notes is detected. This behavior can be tuned through
1144 the grob property @code{auto-knee-gap}.
1145
1146 @cindex beams, kneed
1147 @cindex kneed beams
1148 @cindex auto-knee-gap
1149 @cindex hara kiri
1150
1151
1152 @c TODO -> why this ref? Document? 
1153 @cindex @code{neutral-direction}
1154
1155 @refbugs
1156
1157 Auto knee beams can not be used together with hara kiri staffs.
1158
1159 [TODO from bugs]
1160
1161 The Automatic beamer does not put @strong{unfinished} beams on the
1162 last notes of a score.
1163
1164 Formatting of ties is a difficult subject. LilyPond often does not
1165 give optimal results.
1166
1167 @menu
1168 * Setting automatic beam behavior ::  
1169 @end menu
1170
1171 @ignore
1172 @no de Beam typography
1173 @sub section Beam typography
1174
1175 One of the strong points of LilyPond is how beams are formatted. Beams
1176 are quantized, meaning that the left and right endpoints beams start
1177 exactly on staff lines. Without quantization, small wedges of white
1178 space appear between the beam and staff line, and this looks untidy.
1179
1180 Beams are also slope-damped: melodies that go up or down should also
1181 have beams that go up or down, but the slope of the beams should be
1182 less than the slope of the notes themselves.
1183
1184 Some beams should be horizontal. These are so-called concave beams. 
1185
1186 [TODO: some pictures.]
1187 @end ignore
1188
1189 @c .    {Automatic beams}
1190 @node Setting automatic beam behavior 
1191 @subsection Setting automatic beam behavior 
1192
1193 @cindex @code{autoBeamSettings}
1194 @cindex @code{(end * * * *)}
1195 @cindex @code{(begin * * * *)}
1196 @cindex automatic beams, tuning
1197 @cindex tuning automatic beaming
1198
1199 In normal time signatures, automatic beams can start on any note but can
1200 only end in a few positions within the measure: beams can end on a beat,
1201 or at durations specified by the properties in
1202 @code{Voice.autoBeamSettings}. The defaults for @code{autoBeamSettings}
1203 are defined in @file{scm/auto-beam.scm}.
1204
1205 The value of @code{autoBeamSettings} is changed using
1206 @code{\override} and unset using @code{\revert}:
1207 @example
1208 \property Voice.autoBeamSettings \override #'(@var{BE} @var{P} @var{Q} @var{N} @var{M}) = @var{dur}
1209 \property Voice.autoBeamSettings \revert #'(@var{BE} @var{P} @var{Q} @var{N} @var{M})
1210 @end example
1211 Here, @var{BE} is the symbol @code{begin} or @code{end}. It determines
1212 whether the rule applies to begin or end-points.  The quantity
1213 @var{P}/@var{Q} refers to the length of the beamed notes (and `@code{*
1214 *}' designates notes of any length), @var{N}/@var{M} refers to a time
1215 signature (wildcards, `@code{* *}' may be entered to designate all time
1216 signatures).
1217
1218 For example, if you want automatic beams to end on every quarter note,
1219 you can use the following:
1220 @example
1221 \property Voice.autoBeamSettings \override
1222     #'(end * * * *) = #(make-moment 1 4)
1223 @end example
1224 Since the duration of a quarter note is 1/4 of a whole note, it is
1225 entered as @code{(make-moment 1 4)}.
1226
1227 The same syntax can be used to specify beam starting points. In this
1228 example, automatic beams can only end on a dotted quarter note. 
1229 @example
1230 \property Voice.autoBeamSettings \override
1231     #'(end * * * *) = #(make-moment 3 8)
1232 @end example
1233 In 4/4 time signature, this means that automatic beams could end only on
1234 3/8 and on the fourth beat of the measure (after 3/4, that is 2 times
1235 3/8 has passed within the measure).
1236
1237 You can also restrict rules to specific time signatures. A rule that
1238 should only be applied in @var{N}/@var{M} time signature is formed by
1239 replacing the second asterisks by @var{N} and @var{M}. For example, a
1240 rule for 6/8 time exclusively looks like
1241 @example
1242 \property Voice.autoBeamSettings \override
1243     #'(begin * * 6 8) =  ... 
1244 @end example
1245
1246 If you want a rule to apply to certain types of beams, you can use the
1247 first pair of asterisks. Beams are classified according to the shortest
1248 note they contain. For a beam ending rule that only applies to beams
1249 with 32nd notes (and no shorter notes), you would use @code{(end 1
1250 32 * *)}.
1251
1252 @c not true
1253 @c Automatic beams can not be put on the last note in a score.
1254
1255 If a score ends while an automatic beam has not been ended and is still
1256 accepting notes, this last beam will not be typeset at all.
1257
1258 @cindex automatic beam generation
1259 @cindex autobeam
1260 @cindex @code{Voice.autoBeaming}
1261 @cindex lyrics
1262
1263 For melodies that have lyrics, you may want to switch off 
1264 automatic beaming. This is done by setting @code{Voice.autoBeaming} to
1265 @code{#f}. 
1266
1267
1268 @refbugs
1269
1270 It is not possible to specify beaming parameters for beams with mixed
1271 durations, that differ from the beaming parameters of all separate
1272 durations, i.e., you'll have to specify manual beams to get:
1273 @lilypond[fragment,singleline,relative]
1274   \property Voice.autoBeamSettings
1275   \override #'(end * * * *) = #(make-moment 3 8)
1276   \time 12/8 c'8 c c c16 c c c c c [c c c c] c8 c c4
1277 @end lilypond
1278
1279 It is not possible to specify beaming parameters that act differently in
1280 different parts of a measure. This means that it is not possible to use
1281 automatic beaming in irregular meters such as @code{5/8}.
1282
1283 @node Accidentals
1284 @section Accidentals
1285 @cindex Accidentals
1286 This section describes how to change the way that LilyPond automatically
1287 inserts accidentals before the running notes.
1288
1289 @menu
1290 * Using the predefined accidental macros::  
1291 * Defining your own accidental typesettings::  
1292 @end menu
1293
1294 @node Using the predefined accidental macros
1295 @subsection Using the predefined accidental macros
1296 The constructs for describing the accidental typesetting rules are
1297 quite hairy, so non-experts should stick to the macros defined in
1298 @file{ly/property-init.ly}.
1299 @cindex @file{property-init.ly}
1300
1301 The normal way of using the macros is to enter the macro name right after the
1302 creation of the context in which the accidental typesetting described
1303 by the macro is to take effect. I.e. if you want to use
1304 piano-accidentals in a pianostaff then you issue
1305 @code{\pianoAccidentals} first thing after the creation of the piano
1306 staff:
1307 @example
1308 \score @{
1309     \notes \relative c'' <
1310         \context Staff = sa @{ cis4 d e2 @}
1311         \context GrandStaff <
1312             \pianoAccidentals
1313             \context Staff = sb @{ cis4 d e2 @}
1314             \context Staff = sc @{ es2 c @}
1315         >
1316         \context Staff = sd @{ es2 c @}
1317     >
1318 @}
1319 @end example
1320 @lilypond[singleline]
1321 \score {
1322     \notes \relative c'' <
1323         \context Staff = sa { cis4 d e2 }
1324         \context GrandStaff <
1325             \pianoAccidentals
1326             \context Staff = sb { cis4 d e2 }
1327             \context Staff = sc { es2 c }
1328         >
1329         \context Staff = sd { es2 c }
1330     >
1331     \paper {
1332         \translator {
1333             \StaffContext
1334             minimumVerticalExtent = #'(-4.0 . 4.0)
1335         }
1336     }
1337 }
1338 @end lilypond
1339
1340 The macros are:
1341 @table @code
1342 @item \defaultAccidentals
1343       @cindex @code{\defaultAccidentals}
1344       This is the default typesetting behaviour. It should correspond
1345       to 18th century common practice: Accidentals are
1346       remembered to the end of the measure in which they occur and
1347       only on their own octave.
1348
1349 @item \voiceAccidentals
1350       @cindex @code{\voiceAccidentals}
1351       The normal behaviour is to remember the accidentals on
1352       Staff-level.
1353       This macro, however, typesets accidentals individually for each
1354       voice.
1355       Apart from that the rule is similar to
1356       @code{\defaultAccidentals}.
1357
1358       Warning: This leads to some weird and often unwanted results
1359       because accidentals from one voice DO NOT get cancelled in other
1360       voices:
1361 @lilypond[singleline,relative,fragment,verbatim]
1362     \context Staff <
1363         \voiceAccidentals
1364         \context Voice=va { \voiceOne es g }
1365         \context Voice=vb { \voiceTwo c, e }
1366     >
1367 @end lilypond
1368       Hence you should only use @code{\voiceAccidentals}
1369       if the voices are to be read solely by
1370       individual musicians. if the staff should be readable also
1371       by one musician/conductor then you should use
1372       @code{\modernVoiceAccidentals} or @code{\modernVoiceCautionaries}
1373       instead.
1374
1375 @item \modernAccidentals
1376       @cindex @code{\modernAccidentals}
1377       This rule should correspond to the common practice in the 20th
1378       century.
1379       The rule is a bit more complex than @code{\defaultAccidentals}:
1380       You get all the same accidentals, but temporary
1381       accidentals also get cancelled in other octaves. Further more,
1382       in the same octave, they also get cancelled in the following measure:
1383 @lilypond[singleline,fragment,verbatim]
1384       \modernAccidentals
1385       cis' c'' cis'2 | c'' c'
1386 @end lilypond
1387
1388 @item \modernCautionaries
1389       @cindex @code{\modernCautionaries}
1390      This rule is similar to @code{\modernAccidentals}, but the
1391      ``extra'' accidentals (the ones not typeset by
1392      @code{\defaultAccidentals}) are typeset as cautionary accidentals
1393      (i.e. in reduced size):
1394 @lilypond[singleline,fragment,verbatim]
1395       \modernCautionaries
1396       cis' c'' cis'2 | c'' c'
1397 @end lilypond
1398
1399 @item \modernVoiceAccidentals
1400       @cindex @code{\modernVoiceAccidentals}
1401       Multivoice accidentals to be read both by musicians playing one voice
1402       and musicians playing all voices.
1403
1404       Accidentals are typeset for each voice, but they ARE cancelled
1405       across voices in the same @internalsref{Staff}.
1406
1407 @item \modernVoiceCautionaries
1408       @cindex @code{\modernVoiceCautionaries}
1409       The same as @code{\modernVoiceAccidentals}, but with the
1410       extra accidentals (the ones not typeset by
1411       @code{\voiceAccidentals}) typeset as cautionaries.
1412       Notice that even though all accidentals typeset by
1413       @code{\defaultAccidentals} ARE typeset by this macro then some
1414       of them are typeset as cautionaries.
1415
1416 @item \pianoAccidentals
1417       @cindex @code{\pianoAccidentals}
1418       20th century practice for piano notation. Very similar to
1419       @code{\modernAccidentals} but accidentals also get cancelled
1420       across the staves in the same @internalsref{GrandStaff} or
1421       @internalsref{PianoStaff}.
1422
1423 @item \pianoCautionaries
1424       @cindex @code{\pianoCautionaries}
1425       As @code{\pianoAccidentals} but with the extra accidentals
1426       typeset as cationaries.
1427
1428 @item \noResetKey
1429       @cindex @code{\noResetKey}
1430       Same as @code{\defaultAccidentals} but with accidentals lasting
1431       ``forever'' and not only until the next measure:
1432 @lilypond[singleline,fragment,verbatim,relative]
1433       \noResetKey
1434       c1 cis cis c
1435 @end lilypond
1436
1437 @item \forgetAccidentals
1438       @cindex @code{\forgetAccidentals}
1439       This is sort of the opposite of @code{\noResetKey}: Accidentals
1440       are not remembered at all - and hence all accidentals are
1441       typeset relative to the key signature, regardless of what was
1442       before in the music:
1443 @lilypond[singleline,fragment,verbatim,relative]
1444       \forgetAccidentals
1445       \key d\major c4 c cis cis d d dis dis
1446 @end lilypond
1447 @end table
1448
1449 @node Defining your own accidental typesettings
1450 @subsection Defining your own accidental typesettings
1451
1452 This section must be considered gurus-only, and hence it must be
1453 sufficient with a short description of the system and a reference to
1454 the internal documentation.
1455
1456 The idea of the algorithm is to try several different rules and then
1457 use the rule that gives the highest number of accidentals.
1458 Each rule cosists of
1459 @table @asis
1460 @item Context:
1461       In which context is the rule applied. I.e. if context is
1462       @internalsref{Score} then all staves share accidentals, and if
1463       context is @internalsref{Staff} then all voices in the same
1464       staff share accidentals, but staves don't - like normally.
1465 @item Octavation:
1466       Whether the accidental changes all octaves or only the current
1467       octave.
1468 @item Lazyness:
1469       Over how many barlines the accidental lasts.
1470       If lazyness is @code{-1} then the accidental is forget
1471       immidiately, and if lazyness is @code{#t} then the accidental
1472       lasts forever.
1473 @end table
1474
1475 As described in the internal documentation of
1476 @reng{Accidental_engraver}, the properties @code{autoAccidentals} and
1477 @code{autoCautionaries} contain lists of rule descriptions. Notice
1478 that the contexts must be listed from in to out - that is
1479 @internalsref{Thread} before @internalsref{Voice},
1480 @internalsref{Voice} before @internalsref{Staff}, etc. 
1481 see the macros in @file{ly/property-init.ly} for examples of how the
1482 properties are set.
1483
1484 @refbugs
1485
1486 Currently the simultaneous notes are considered to be entered in
1487 sequential mode. This means that in a chord the accidentals are
1488 typeset as if the notes in the chord happened one at a time - in the
1489 order in which they appear in the input file.
1490
1491 Of course this is only a problem when you have simultainous notes
1492 which accidentals should depend on each other.
1493 Notice that the problem only occurs when using non-default accidentals
1494 - as the default accidentals only depend on other accidentals on the
1495 same staff and same pitch and hence cannot depend on other
1496 simultainous notes.
1497
1498 This example shows two examples of the same music giving different
1499 accidentals depending on the order in which the notes occur in the
1500 input file:
1501
1502 @lilypond[singleline,fragment,verbatim]
1503 \property Staff.autoAccidentals = #'( Staff (any-octave . 0) )
1504 cis'4 <c'' c'> r2 | cis'4 <c' c''> r2 | <cis' c''> r | <c'' cis'> r | 
1505 @end lilypond
1506
1507 The only solution is to manually insert the problematic
1508 accidentals using @code{!} and @code{?}.
1509
1510 @node Expressive marks
1511 @section Expressive marks
1512
1513 @c .   {Slurs}
1514 @menu
1515 * Slurs ::                      
1516 * Phrasing slurs::              
1517 * Breath marks::                
1518 * Tempo::                       
1519 * Text spanners::               
1520 @end menu
1521
1522 @node Slurs 
1523 @subsection Slurs
1524 @cindex Slurs
1525
1526 A slur indicates that notes are to be played bound or @emph{legato}.
1527 They are entered using parentheses:
1528 @lilypond[fragment,verbatim,center]
1529   f'()g'()a' [a'8 b'(] a'4 g'2 )f'4
1530 @end lilypond
1531
1532 See also @seeinternals{Slur}.
1533
1534 Slurs avoid crossing stems, and are generally attached to note heads.
1535 However, in some situations with beams, slurs may be attached to stem
1536 ends.  If you want to override this layout you can do this through the
1537 grob-property @code{attachment} of @internalsref{Slur} in
1538 @internalsref{Voice} context It's value is a pair of symbols, specifying
1539 the attachment type of the left and right end points.
1540
1541 @lilypond[fragment,relative,verbatim]
1542   \slurUp
1543   \property Voice.Stem \set #'length = #5.5
1544   g'8(g)g4
1545   \property Voice.Slur \set #'attachment = #'(stem . stem)
1546   g8(g)g4
1547 @end lilypond
1548
1549 If a slur would strike through a stem or beam, the slur will be moved
1550 away upward or downward. If this happens, attaching the slur to the
1551 stems might look better:
1552
1553 @lilypond[fragment,relative,verbatim]
1554   \stemUp \slurUp
1555   d32( d'4 )d8..
1556   \property Voice.Slur \set #'attachment = #'(stem . stem)
1557   d,32( d'4 )d8..
1558 @end lilypond
1559
1560 @ignore
1561 Similarly, the curvature of a slur is adjusted to stay clear of note
1562 heads and stems.  When that would increase the curvature too much, the
1563 slur is reverted to its default shape.  The threshold for this
1564 decision is in @internalsref{Slur}'s grob-property @code{beautiful}.
1565 It is loosely related to the enclosed area between the slur and the
1566 notes.  Usually, the default setting works well, but in some cases you
1567 may prefer a curved slur when LilyPond decides for a vertically moved
1568 one.  You can indicate this preference by increasing the
1569 @code{beautiful} value:
1570
1571 @lilyp ond[verbatim,singleline,relative]
1572   \stemDown \slurUp
1573   c16( a' f' a a f a, )c,
1574   c( a' f' a a f d, )c
1575   \property Voice.Slur \override #'beautiful = #5.0
1576   c( a' f' a a f d, )c
1577 @end lilypond
1578 @end ignore
1579
1580 @refbugs
1581
1582 Producing nice slurs is a difficult problem, and LilyPond currently
1583 uses a simple, empiric method to produce slurs. In some cases, the
1584 results of this method are ugly.
1585
1586 @ignore
1587 This is reflected by the
1588 @code{beautiful} property, which it is an arbitrary parameter in the
1589 slur formatter.  Useful values can only be determined by trial and
1590 error.
1591 @end ignore
1592
1593 @cindex Adjusting slurs
1594
1595 @node Phrasing slurs
1596 @subsection Phrasing slurs
1597
1598 @cindex phrasing slurs
1599 @cindex phrasing marks
1600
1601 A phrasing slur (or phrasing mark) connects chords and is used to
1602 indicate a musical sentence. It is started using @code{\(} and @code{\)}
1603 respectively.
1604
1605 @lilypond[fragment,verbatim,center,relative]
1606   \time 6/4 c' \(  d () e f () e  \) d
1607 @end lilypond
1608
1609 Typographically, the phrasing slur behaves almost exactly like a normal
1610 slur. See also  @seeinternals{PhrasingSlur}.
1611
1612
1613 @node Breath marks
1614 @subsection Breath marks
1615
1616 Breath marks are entered using @code{\breathe}.  See also
1617 @seeinternals{BreathingSign}.
1618
1619 @lilypond[fragment,relative]
1620 c'4 \breathe d4
1621 @end lilypond
1622
1623
1624 @c .  {Tempo}
1625 @node Tempo
1626 @subsection Tempo
1627 @cindex Tempo
1628 @cindex beats per minute
1629 @cindex metronome marking
1630
1631 Metronome settings can be entered as follows:
1632
1633 @cindex @code{\tempo}
1634 @example
1635   \tempo @var{duration} = @var{perminute} 
1636 @end example
1637
1638 For example, @code{\tempo 4 = 76} requests output with 76 quarter notes
1639 per minute.
1640   
1641 @refbugs
1642   
1643 The tempo setting is not printed, but is only used in the MIDI
1644 output. You can trick lily into producing a metronome mark,
1645 though. Details are in @ref{Text markup}.
1646   
1647
1648
1649 @node Text spanners
1650 @subsection Text spanners
1651 @cindex Text spanners
1652
1653 Some textual indications, e.g. rallentando or accelerando, often extend
1654 over many measures. This is indicated by following the text with a
1655 dotted line.  You can create such texts using text spanners. The syntax
1656 is as follows:
1657 @example
1658 \spanrequest \start "text"
1659 \spanrequest \stop "text"
1660 @end example
1661 LilyPond will respond by creating a @internalsref{TextSpanner} grob (typically
1662 in @internalsref{Voice} context).  The string to be printed, as well as the
1663 style is set through grob properties.
1664
1665 An application---or rather, a hack---is to fake octavation indications.
1666 @lilypond[fragment,relative,verbatim]
1667  \relative c' {  a''' b c a
1668   \property Voice.TextSpanner \set #'type = #'dotted-line
1669   \property Voice.TextSpanner \set #'edge-height = #'(0 . 1.5)
1670   \property Voice.TextSpanner \set #'edge-text = #'("8va " . "")
1671   \property Staff.centralCPosition = #-13
1672   a\spanrequest \start "text" b c a \spanrequest \stop "text" }
1673 @end lilypond
1674
1675
1676 @c .  {Ornaments}
1677 @node Ornaments
1678 @section Ornaments
1679 @cindex Ornaments
1680 @menu
1681 * Articulations::               
1682 * Text scripts::                
1683 * Grace notes::                 
1684 * Glissando ::                  
1685 * Dynamics::                    
1686 @end menu
1687
1688 @c .   {Articulation}
1689 @node Articulations
1690 @subsection Articulations
1691 @cindex Articulations
1692
1693 @cindex articulations
1694 @cindex scripts
1695 @cindex ornaments
1696
1697 A variety of symbols can appear above and below notes to indicate
1698 different characteristics of the performance. They are added to a note
1699 by adding a dash and the the character signifying the
1700 articulation. They are demonstrated here.
1701 @lilypond[singleline]
1702   \score {
1703     \notes \context Voice {
1704       \property Voice.TextScript \set #'font-family = #'typewriter
1705       \property Voice.TextScript \set #'font-shape = #'upright
1706       c''4-._"c-."      s4
1707       c''4--_"c-{}-"    s4
1708       c''4-+_"c-+"      s4
1709       c''4-|_"c-|"      s4
1710       c''4->_"c->"      s4
1711       c''4-^_"c-\\^{ }" s4
1712     }
1713   }
1714 @end lilypond
1715
1716 The script is automatically placed, but if you need to force
1717 directions, you can use @code{_} to force them down, or @code{^} to
1718 put them up:
1719 @lilypond[fragment, verbatim]
1720   c''4^^ c''4_^
1721 @end lilypond
1722
1723
1724 Other symbols can be added using the syntax
1725 @var{note}@code{-\}@var{name}. Again, they can be forced up or down
1726 using @code{^} and @code{_}.
1727
1728 @cindex accent      
1729 @cindex marcato      
1730 @cindex staccatissimo
1731 @cindex fermata 
1732 @cindex stopped     
1733 @cindex staccato     
1734 @cindex tenuto        
1735 @cindex upbow
1736 @cindex downbow
1737 @cindex foot marks
1738 @cindex organ pedal marks
1739 @cindex turn         
1740 @cindex open          
1741 @cindex flageolet
1742 @cindex reverseturn 
1743 @cindex trill        
1744 @cindex prall         
1745 @cindex mordent
1746 @cindex prallprall  
1747 @cindex prallmordent 
1748 @cindex prall, up
1749 @cindex prall, down
1750 @cindex mordent
1751 @cindex thumb marking
1752 @cindex segno         
1753 @cindex coda
1754
1755 @lilypond[]
1756   \score {
1757     <
1758       \property Score.LyricText \override #'font-family =#'typewriter
1759       \property Score.LyricText \override #'font-shape = #'upright
1760       \context Staff \notes {
1761         c''-\accent      c''-\marcato      c''-\staccatissimo c''^\fermata 
1762         c''-\stopped     c''-\staccato     c''-\tenuto        c''-\upbow
1763         c''-\downbow     c''^\lheel        c''-\rheel         c''^\ltoe
1764         c''-\rtoe        c''-\turn         c''-\open          c''-\flageolet
1765         c''-\reverseturn c''-\trill        c''-\prall         c''-\mordent
1766         c''-\prallprall  c''-\prallmordent c''-\upprall       c''-\downprall
1767         c''-\upmordent   c''-\downmordent  c''-\pralldown     c''-\prallup
1768         c''-\lineprall   c''-\thumb        c''-\segno         c''-\coda
1769       }
1770       \context Lyrics \lyrics {
1771         accent__      marcato__      staccatissimo__ fermata
1772         stopped__     staccato__     tenuto__        upbow
1773         downbow__     lheel__        rheel__         ltoe
1774         rtoe__        turn__         open__          flageolet
1775         reverseturn__ trill__        prall__         mordent
1776         prallprall__  prallmordent__ uprall__        downprall
1777         upmordent__   downmordent__  pralldown__  prallup__
1778         lineprall__   thumb__       segno__        coda
1779       }
1780     >
1781     \paper {
1782       linewidth = 5.875\in
1783       indent    = 0.0
1784     }
1785   }
1786 @end lilypond
1787
1788
1789 @cindex fingering
1790
1791 Fingering instructions can also be entered in this shorthand. For
1792 finger changes, use markup texts:
1793 @c
1794 @lilypond[verbatim, singleline, fragment]
1795       c'4-1 c'4-2 c'4-3 c'4-4
1796       c^#'(finger "2-3")
1797 @end lilypond
1798
1799
1800 @cindex @code{\script}
1801 @cindex scripts
1802 @cindex superscript
1803 @cindex subscript
1804
1805 See also @seeinternals{Script} and @seeinternals{Fingering}.
1806
1807 @refbugs
1808
1809 All of these note ornaments appear in the printed output but have no
1810 effect on the MIDI rendering of the music.
1811
1812 Unfortunately, there is no support for adding fingering instructions or 
1813 ornaments to individual note heads. Some hacks exist, though. See
1814 @file{input/test/script-horizontal.ly}.
1815
1816
1817 @c .  {Text scripts}
1818 @node Text scripts
1819 @subsection Text scripts
1820 @cindex Text scripts
1821
1822 In addition, it is possible to place arbitrary strings of text or markup
1823 text (see @ref{Text markup}) above or below notes by using a string:
1824 @code{c^"text"}. 
1825
1826 By default, these indications do not influence the note spacing, but
1827 by using the command @code{\fatText}, the widths will be taken into
1828 account.
1829 @c
1830 @lilypond[fragment,singleline,verbatim] \relative c' {
1831 c4^"longtext" \fatText c4_"longlongtext" c4 }
1832 @end lilypond
1833
1834 It is possible to use @TeX{} commands in the strings, but this should be
1835 avoided because it makes it impossible for LilyPond to compute the
1836 exact length of the string, which may lead to collisions.  Also, @TeX{}
1837 commands won't work with direct PostScript output.
1838 @c (see @ref{PostScript output}).
1839
1840 Text scripts are created in form of @internalsref{TextScript} grobs, in
1841 @internalsref{Voice} context. 
1842
1843 @ref{Text markup} describes how to change the font or access
1844 special symbols in text scripts.
1845
1846
1847 @c .   {Grace notes}
1848 @node Grace notes
1849 @subsection Grace notes
1850
1851
1852
1853 @cindex @code{\grace}
1854 @cindex ornaments
1855 @cindex grace notes
1856
1857 Grace notes are ornaments  are written out ornaments
1858 @lilypond[relative=2,verbatim,ifragment] 
1859   c4  \grace c16  c4 \grace { [c16 d16] } c4 
1860 @end lilypond
1861
1862 In normal notation, grace notes are supposed to take up no logical
1863 time in a measure. Such an idea is practical for normal notation, but
1864 is not strict enough to put it into a program. The model that LilyPond
1865 uses for grace notes internally is that all timing is done in two
1866 steps:
1867
1868 Every point in musical time consists of two rational numbers: one
1869 denotes the logical time, one denotes the grace timing. The above
1870 example is shown here with timing tuples.
1871
1872 @lilypond[]
1873 \score { \notes \relative c''{ 
1874   c4^"(0,0)"  \grace c16_" "_"(1/4,-1/16)"  c4^"(1/4,0)"  \grace {
1875   [c16_"(2/4,-1/8)"  d16^"(2/4,-1/16)" ] } c4_" "_"(2/4,0)"
1876   }
1877 \paper {  linewidth = 8.\cm }
1878 }
1879 @end lilypond
1880
1881 The advantage of this approach is that you can use almost any lilypond
1882 construction together with grace notes, for example slurs and clef
1883 changes may appear halfway in between grace notes:
1884
1885 @lilypond[relative=2,verbatim,fragment] 
1886   c4  \grace { [ c16 c, \clef bass c, b(] }  )c4 
1887 @end lilypond
1888
1889 The placement of these grace notes is synchronized between different
1890 staffs, using this grace timing.
1891
1892 @lilypond[relative=2,verbatim,fragment] 
1893 < \context Staff = SA { e4 \grace { c16 d e f } e4 }
1894   \context Staff = SB { c4 \grace { g8 b } c4 } >
1895 @end lilypond
1896
1897
1898 Unbeamed eighth notes and shorter by default have a slash through the
1899 stem. This can be controlled with grob property @code{flag-style} of
1900 @internalsref{Stem}. The change in formatting is accomplished by
1901 inserting @code{\startGraceMusic} before handling the grace notes, and
1902 @code{\stopGraceMusic} after finishing the grace notes. You can add to
1903 these definitions to globally change grace note formatting. The
1904 standard definitions are in @file{ly/grace-init.ly}.
1905
1906
1907 @lilypond[fragment,verbatim]
1908 \relative c'' \context Voice {
1909   \grace c8 c4 \grace { [c16 c16] } c4
1910   \grace { 
1911     \property Voice.Stem \override #'flag-style = #'() 
1912     c16 
1913     \property Voice.Stem \revert #'flag-style
1914   } c4
1915 }
1916 @end lilypond
1917
1918 @refbugs
1919
1920 Grace note synchronization can also lead to surprises. Staff notation,
1921 such as key signatures, barlines, etc. are also synchronized. Take
1922 care when you mix staffs with grace notes and staffs without.
1923
1924 @lilypond[relative=2,verbatim,fragment]
1925 < \context Staff = SA { e4 \bar "|:" \grace c16 d4 }
1926   \context Staff = SB { c4 \bar "|:"  d4 } >
1927 @end lilypond
1928
1929 Grace sections should only be used within sequential music
1930 expressions.  Nesting, juxtaposing, or ending sequential music with a
1931 grace section is not supported, and might produce crashes or other
1932 errors.
1933
1934 @menu
1935 * Glissando ::                  
1936 * Dynamics::                    
1937 @end menu
1938
1939
1940
1941 @c .   {Glissando}
1942 @node Glissando 
1943 @subsection Glissando
1944 @cindex Glissando 
1945
1946 @cindex @code{\glissando}
1947
1948 A glissando line can be requested by attaching a @code{\glissando} to
1949 a note:
1950
1951 @lilypond[fragment,relative,verbatim]
1952   c'-\glissando c'
1953 @end lilypond
1954
1955 @refbugs
1956
1957 Printing of an additional text (such as @emph{gliss.}) must be done
1958 manually. See also @seeinternals{Glissando}.
1959
1960
1961
1962 @c .   {Dynamics}
1963 @node Dynamics
1964 @subsection Dynamics
1965 @cindex Dynamics
1966
1967
1968
1969 @cindex @code{\ppp}
1970 @cindex @code{\pp}
1971 @cindex @code{\p}
1972 @cindex @code{\mp}
1973 @cindex @code{\mf}
1974 @cindex @code{\f}
1975 @cindex @code{\ff}
1976 @cindex @code{\fff}
1977 @cindex @code{\ffff}
1978 @cindex @code{\fp}
1979 @cindex @code{\sf}
1980 @cindex @code{\sff}
1981 @cindex @code{\sp}
1982 @cindex @code{\spp}
1983 @cindex @code{\sfz}
1984 @cindex @code{\rfz}
1985
1986
1987 Absolute dynamic marks are specified using an identifier after a
1988 note: @code{c4-\ff}.  The available dynamic marks are: @code{\ppp},
1989 @code{\pp}, @code{\p}, @code{\mp}, @code{\mf}, @code{\f}, @code{\ff},
1990 @code{\fff}, @code{\fff}, @code{\fp}, @code{\sf}, @code{\sff},
1991 @code{\sp}, @code{\spp}, @code{\sfz}, and @code{\rfz}.
1992
1993 @lilypond[verbatim,singleline,fragment,relative]
1994   c'\ppp c\pp c \p c\mp c\mf c\f c\ff c\fff
1995   c2\sf c\rfz
1996 @end lilypond
1997
1998 @cindex @code{\cr}
1999 @cindex @code{\rc}
2000 @cindex @code{\decr}
2001 @cindex @code{\rced}
2002 @cindex @code{\<}
2003 @cindex @code{\>}
2004 @cindex @code{\"!}
2005
2006
2007 A crescendo mark is started with @code{\cr} and terminated with
2008 @code{\rc} (the textual reverse of @code{cr}).  A decrescendo mark is
2009 started with @code{\decr} and terminated with @code{\rced}.  There are
2010 also shorthands for these marks.  A crescendo can be started with
2011 @code{\<} and a decrescendo can be started with @code{\>}.  Either one
2012 can be terminated with @code{\!}.  Note that @code{\!}  must go before
2013 the last note of the dynamic mark whereas @code{\rc} and @code{\rced} go
2014 after the last note.  Because these marks are bound to notes, if you
2015 want several marks during one note, you have to use spacer notes.
2016
2017 @lilypond[fragment,verbatim,center]
2018   c'' \< \! c''   d'' \decr e'' \rced 
2019   < f''1 { s4 s4 \< \! s4 \> \! s4 } >
2020 @end lilypond
2021
2022 You can also use a text saying @emph{cresc.} instead of hairpins. Here
2023 is an example how to do it:
2024
2025 @lilypond[fragment,relative=2,verbatim]
2026   c4 \cresc c4 \endcresc c4
2027 @end lilypond
2028
2029
2030 @cindex crescendo
2031 @cindex decrescendo
2032
2033 You can also supply your own texts:
2034 @lilypond[fragment,relative,verbatim]
2035   \context Voice {
2036     \property Voice.crescendoText = "cresc. poco"
2037     \property Voice.crescendoSpanner = #'dashed-line
2038     a'2\mf\< a a \!a 
2039   }
2040 @end lilypond
2041
2042 @cindex diminuendo
2043
2044 Dynamics are grobs of @internalsref{DynamicText} and
2045 @internalsref{Hairpin}. Vertical positioning of these symbols is
2046 handled by the @internalsref{DynamicLineSpanner} grob.  If you want to
2047 adjust padding or vertical direction of the dynamics, you must set
2048 properties for the @internalsref{DynamicLineSpanner} grob. Predefined
2049 identifiers to set the vertical direction are \dynamicUp and
2050 \dynamicDown.
2051
2052 @cindex direction, of dynamics
2053 @cindex @code{\dynamicDown}
2054 @cindex @code{\dynamicUp}
2055
2056 @c .  {Repeats}
2057 @node Repeats
2058 @section Repeats
2059
2060
2061 @cindex repeats
2062 @cindex @code{\repeat}
2063
2064 To specify repeats, use the @code{\repeat} keyword.  Since repeats
2065 should work differently when played or printed, there are a few
2066 different variants of repeats.
2067
2068 @table @code
2069 @item unfold
2070 Repeated music is fully written (played) out.  Useful for MIDI
2071 output, and entering repetitive music.
2072
2073 @item volta
2074 This is the normal notation: Repeats are not written out, but
2075 alternative endings (voltas) are printed, left to right.
2076
2077 @item fold
2078 Alternative endings are written stacked. This has limited use but may be
2079 used to typeset two lines of lyrics in songs with repeats, see
2080 @file{input/star-spangled-banner.ly}.
2081
2082 @item tremolo
2083 Make tremolo beams.
2084
2085 @item percent
2086 Make beat or measure repeats. These look like percent signs.
2087
2088 @end table  
2089
2090 @menu
2091 * Repeat syntax::               
2092 * Repeats and MIDI::            
2093 * Manual repeat commands::      
2094 * Tremolo repeats::             
2095 * Tremolo subdivisions::        
2096 * Measure repeats::             
2097 @end menu
2098
2099 @node Repeat syntax
2100 @subsection Repeat syntax
2101
2102 The syntax for repeats is
2103
2104 @example
2105   \repeat @var{variant} @var{repeatcount} @var{repeatbody}
2106 @end example
2107
2108 If you have alternative endings, you may add
2109 @cindex @code{\alternative}
2110 @example
2111  \alternative @code{@{} @var{alternative1}
2112             @var{alternative2}
2113             @var{alternative3} @dots{} @code{@}}
2114 @end example
2115 where each @var{alternative} is a music expression.
2116
2117 Normal notation repeats are used like this:
2118 @lilypond[fragment,verbatim]
2119   c'1
2120   \repeat volta 2 { c'4 d' e' f' }
2121   \repeat volta 2 { f' e' d' c' }
2122 @end lilypond
2123
2124 With alternative endings:
2125 @lilypond[fragment,verbatim]
2126   c'1
2127   \repeat volta 2 {c'4 d' e' f'} 
2128   \alternative { {d'2 d'} {f' f} }
2129 @end lilypond
2130
2131 Folded repeats look like this:
2132
2133
2134 @lilypond[fragment,verbatim]
2135   c'1
2136   \repeat fold 2 {c'4 d' e' f'} 
2137   \alternative { {d'2 d'} {f' f} }
2138
2139 @end lilypond
2140
2141 If you don't give enough alternatives for all of the repeats, then
2142 the first alternative is assumed to be repeated often enough to equal
2143 the specified number of repeats.
2144
2145 @lilypond[fragment,verbatim]
2146 \context Staff {
2147   \relative c' {
2148     \partial 4
2149     \repeat volta 4 { e | c2 d2 | e2 f2 | }
2150     \alternative { { g4 g g } { a | a a a a | b2. } }
2151   }
2152 }
2153 @end lilypond
2154
2155 @node Repeats and MIDI
2156 @subsection Repeats and MIDI
2157
2158 @cindex expanding repeats
2159
2160 For instructions on how to unfoldi repeats for MIDI output, see
2161 the example file @file{input/test/unfold-all-repeats.ly}.
2162
2163
2164 @refbugs
2165
2166 Notice that timing information is not remembered at the start of an
2167 alternative, so you have to reset timing information after a repeat,
2168 e.g. using a bar-check (See @ref{Bar check}), setting
2169 @code{Score.measurePosition} or entering @code{\partial}.  Slurs or ties
2170 are also not repeated.
2171
2172 It is possible to nest @code{\repeat}s, although this probably is only
2173 meaningful for unfolded repeats.
2174
2175 Folded repeats offer little more over simultaneous music.
2176
2177 @node Manual repeat commands
2178 @subsection Manual repeat commands
2179
2180 @cindex @code{repeatCommands}
2181
2182 The property @code{repeatCommands} can be used to control the layout of
2183 repeats. Its value is a Scheme list of repeat commands, where each repeat
2184 command can be
2185
2186 @table @code
2187 @item 'start-repeat
2188  Print a |: bar line
2189 @item 'end-repeat
2190  Print a :| bar line
2191 @item (volta . @var{text})
2192   Print a volta bracket saying @var{text}.
2193 @item (volta . #f)
2194   Stop a running volta bracket
2195 @end table
2196
2197 @lilypond[verbatim, fragment]
2198  c''4
2199     \property Score.repeatCommands = #'((volta "93") end-repeat)
2200  c''4 c''4
2201     \property Score.repeatCommands = #'((volta #f))
2202  c''4 c''4
2203 @end lilypond
2204
2205
2206 Repeats brackets are @internalsref{VoltaBracket} grobs.
2207
2208 @node Tremolo repeats
2209 @subsection Tremolo repeats
2210 @cindex tremolo beams
2211
2212 To place tremolo marks between notes, use @code{\repeat} with tremolo
2213 style.  
2214 @lilypond[verbatim,center,singleline]
2215 \score { 
2216   \context Voice \notes\relative c' {
2217     \repeat "tremolo" 8 { c16 d16 }
2218     \repeat "tremolo" 4 { c16 d16 }    
2219     \repeat "tremolo" 2 { c16 d16 }
2220     \repeat "tremolo" 4 c16
2221   }
2222 }
2223 @end lilypond
2224
2225 Tremolo beams are @internalsref{Beam} grobs. Single stem tremolos are
2226 @internalsref{StemTremolo}. The single stem tremolo @emph{must} be
2227 entered without @code{@{} and @code{@}}.  
2228
2229 @refbugs
2230
2231 Only powers of two and undotted notes are supported repeat counts.
2232
2233 @node Tremolo subdivisions
2234 @subsection Tremolo subdivisions
2235 @cindex tremolo marks
2236 @cindex @code{tremoloFlags}
2237
2238 Tremolo marks can be printed on a single note by adding
2239 `@code{:}[@var{length}]' after the note.  The length must be at least 8.
2240 A @var{length} value of 8 gives one line across the note stem.  If the
2241 length is omitted, then then the last value (stored in
2242 @code{Voice.tremoloFlags}) is used.
2243
2244 @lilypond[verbatim,fragment,center]
2245   c'2:8 c':32 | c': c': |
2246 @end lilypond
2247
2248 @refbugs
2249
2250
2251 Tremolos in this style do not carry over into the MIDI output.
2252
2253
2254 @node Measure repeats
2255 @subsection Measure repeats
2256
2257 @cindex percent repeats
2258 @cindex measure repeats
2259
2260 In the @code{percent} style, a note pattern can be repeated. It is
2261 printed once, and then the pattern is replaced with a special sign.
2262 Patterns of a one and two measures are replaced by percent-like signs,
2263 patterns that divide the measure length are replaced by slashes.
2264
2265 @lilypond[verbatim,singleline]
2266  \context Voice { \repeat  "percent" 4  { c'4 }
2267     \repeat "percent" 2 { c'2 es'2 f'4 fis'4 g'4 c''4 }
2268 }
2269 @end lilypond   
2270
2271 The signs are represented by these grobs: @internalsref{RepeatSlash} and
2272 @internalsref{PercentRepeat} and @internalsref{DoublePercentRepeat}.
2273
2274 @refbugs
2275
2276 You can not nest percent repeats, e.g. by filling in the first measure
2277 with slashes, and repeating that measure with percents.
2278
2279 @node Rhythmic music
2280 @section Rhythmic music
2281
2282 Sometimes you might want to show only the rhythm of a melody.  This can
2283 be done with the rhythmic staff. All pitches of notes on such a staff
2284 are squashed, and the  staff itself  looks has  a single staff line:
2285
2286 @lilypond[fragment,relative,verbatim]
2287   \context RhythmicStaff {
2288       \time 4/4
2289       c4 e8 f  g2 | r4 g r2 | g1:32 | r1 |
2290   }
2291 @end lilypond
2292
2293 @menu
2294 * Percussion staves::           
2295 @end menu
2296
2297 @node Percussion staves
2298 @subsection Percussion staves
2299 @cindex percussion
2300 @cindex drums
2301 To typeset more than one piece of percussion to be played by the same
2302 musician one typically uses a multiline staff where each staff
2303 position refers to a specific piece of percussion.
2304
2305 LilyPond is shipped with a bunch of scheme functions which allows you
2306 to do this fairly easily.
2307
2308 The system is based on the general midi drum-pitches.
2309 In order to use the drum pitches you include
2310 @file{ly/drumpitch-init.ly}. This file defines the pitches from the scheme
2311 variable @code{drum-pitch-names} - which definition can be read in
2312 @file{scm/drums.scm}. You see that each piece of percussion has a full
2313 name and an abbreviated name - and you may freely select whether to
2314 refer to the full name or the abbreviation in your music definition.
2315
2316 To typeset the music on a staff you apply the scheme function
2317 @code{drums->paper} to the percussion music. This function takes a
2318 list of percussion instrument names, notehead scripts and staff
2319 positions (that is: pitches relative to the C-clef) and uses this to
2320 transform the input music by moving the pitch, changing the notehead
2321 and (optionally) adding a script:
2322 @lilypond[singleline,verbatim]
2323 \include "drumpitch-init.ly"
2324 up = \notes { crashcymbal4 hihat8 halfopenhihat hh hh hh openhihat }
2325 down = \notes { bassdrum4 snare8 bd r bd sn4 }
2326 \score {
2327     \apply #(drums->paper 'drums) \context Staff <
2328         \clef percussion
2329         \context Voice = up { \voiceOne \up }
2330         \context Voice = down { \voiceTwo \down }
2331     >
2332 }
2333
2334 @end lilypond
2335 In the above example the music was transformed using the list @code{'drums}.
2336 Currently the following lists are defined in @file{scm/drums.scm}:
2337 @table @code
2338 @item 'drums
2339 To typeset a typical drum kit on a five line staff.
2340 @lilypond[]
2341 \include "drumpitch-init.ly"
2342 nam = \lyrics { cymc cyms cymr hh hhc hho hhho hhp cb hc
2343     bd sn ss tomh tommh tomml toml tomfh tomfl }
2344 mus = \notes  { cymc cyms cymr hh hhc hho hhho hhp cb hc
2345     bd sn ss tomh tommh tomml toml tomfh tomfl s16 }
2346 \score {
2347     <
2348         \apply #(drums->paper 'drums) \context Staff <
2349             \clef percussion
2350             \mus
2351         >
2352         \context Lyrics \nam 
2353     >
2354     \paper {
2355         \translator {
2356             \StaffContext
2357             \remove Bar_engraver
2358             \remove Time_signature_engraver
2359             minimumVerticalExtent = #'(-4.0 . 5.0)
2360         }
2361         \translator {
2362             \VoiceContext
2363             \remove Stem_engraver
2364         }
2365    }   
2366 }
2367 @end lilypond
2368 Notice that the scheme supports six different toms.
2369 If you are using fewer toms then you simply select the toms that produce
2370 the desired result - i.e. to get toms on the three middle lines you
2371 use @code{tommh}, @code{tomml} and @code{tomfh}.
2372
2373 Because the general midi contain no rimshots we use the sidestick for
2374 this purpose instead.
2375 @item 'timbales
2376 To typeset timbales on a two line staff.
2377 @lilypond[singleline]
2378 \include "drumpitch-init.ly"
2379 nam = \lyrics { timh ssh timl ssl cb }
2380 mus = \notes  { timh ssh timl ssl cb s16 }
2381 \score {
2382     <
2383         \apply #(drums->paper 'timbales) \context Staff <
2384             \clef percussion
2385             \mus
2386         >
2387         \context Lyrics \nam 
2388     >
2389     \paper {
2390         \translator {
2391             \StaffContext
2392             \remove Bar_engraver
2393             \remove Time_signature_engraver
2394             StaffSymbol \override #'line-count = #2
2395             StaffSymbol \override #'staff-space = #2
2396             minimumVerticalExtent = #'(-3.0 . 4.0)
2397         }
2398         \translator {
2399             \VoiceContext
2400             \remove Stem_engraver
2401         }
2402
2403     }   
2404 }
2405 @end lilypond
2406 @item 'congas
2407 To typeset congas on a two line staff.
2408 @lilypond[singleline]
2409 \include "drumpitch-init.ly"
2410 nam = \lyrics { cgh cgho cghm ssh cgl cglo cglm ssl }
2411 mus = \notes  { cgh cgho cghm ssh cgl cglo cglm ssl s16 }
2412 \score {
2413     <
2414         \apply #(drums->paper 'congas) \context Staff <
2415             \clef percussion
2416             \mus
2417         >
2418         \context Lyrics \nam 
2419     >
2420     \paper {
2421         \translator {
2422             \StaffContext
2423             \remove Bar_engraver
2424             \remove Time_signature_engraver
2425             StaffSymbol \override #'line-count = #2
2426             StaffSymbol \override #'staff-space = #2
2427             minimumVerticalExtent = #'(-3.0 . 4.0)
2428         }
2429         \translator {
2430             \VoiceContext
2431             \remove Stem_engraver
2432         }
2433     }   
2434 }
2435 @end lilypond
2436 @item 'bongos
2437 To typeset bongos on a two line staff.
2438 @lilypond[singleline]
2439 \include "drumpitch-init.ly"
2440 nam = \lyrics { boh boho bohm ssh bol bolo bolm ssl }
2441 mus = \notes  { boh boho bohm ssh bol bolo bolm ssl s16 }
2442 \score {
2443     <
2444         \apply #(drums->paper 'bongos) \context Staff <
2445             \clef percussion
2446             \mus
2447         >
2448         \context Lyrics \nam 
2449     >
2450     \paper {
2451         \translator {
2452             \StaffContext
2453             \remove Bar_engraver
2454             \remove Time_signature_engraver
2455             StaffSymbol \override #'line-count = #2
2456             StaffSymbol \override #'staff-space = #2
2457             minimumVerticalExtent = #'(-3.0 . 4.0)
2458         }
2459         \translator {
2460             \VoiceContext
2461             \remove Stem_engraver
2462         }
2463     }   
2464 }
2465 @end lilypond
2466 @item 'percussion
2467 To typeset all kinds of simple percussion on one line staves.
2468 @lilypond[singleline]
2469 \include "drumpitch-init.ly"
2470 nam = \lyrics { tri trio trim gui guis guil cb cl tamb cab mar hc }
2471 mus = \notes  { tri trio trim gui guis guil cb cl tamb cab mar hc s16 }
2472 \score {
2473     <
2474         \apply #(drums->paper 'percussion) \context Staff <
2475             \clef percussion
2476             \mus
2477         >
2478         \context Lyrics \nam 
2479     >
2480     \paper {
2481         \translator {
2482             \StaffContext
2483             \remove Bar_engraver
2484             \remove Time_signature_engraver
2485             StaffSymbol \override #'line-count = #1
2486             minimumVerticalExtent = #'(-2.0 . 3.0)
2487         }
2488         \translator {
2489             \VoiceContext
2490             \remove Stem_engraver
2491         }
2492     }   
2493 }
2494 @end lilypond
2495 @end table
2496
2497 If you don't like any of the predefined lists you can define your own
2498 list at the top of your file:
2499
2500 @lilypond[singleline, verbatim]
2501 #(define mydrums `(
2502         (bassdrum     default   #f        ,(make-pitch -1 2 0))
2503         (snare        default   #f        ,(make-pitch 0 1 0))
2504         (hihat        cross     #f        ,(make-pitch 0 5 0))
2505         (pedalhihat   xcircle   "stopped" ,(make-pitch 0 5 0))
2506         (lowtom       diamond   #f        ,(make-pitch -1 6 0))
2507 ))
2508 \include "drumpitch-init.ly"
2509 up = \notes { hh8 hh hh hh hhp4 hhp }
2510 down = \notes { bd4 sn bd toml8 toml }
2511 \score {    
2512     \apply #(drums->paper 'mydrums) \context Staff <
2513         \clef percussion
2514         \context Voice = up { \voiceOne \up }
2515         \context Voice = down { \voiceTwo \down }
2516     >
2517 }
2518 @end lilypond
2519
2520 To use a modified existing list instead of building your own from
2521 scratch you can append your modifications to the start of the existing
2522 list:
2523
2524 @example
2525 #(define mydrums (append `(
2526    (bassdrum default #f ,(make-pitch -1 2 0))
2527    (lowtom   diamond #f ,(make-pitch -1 6 0))
2528 ) drums ))
2529 @end example
2530
2531 @c FIXME: Too many levels of headers when using subsubsections.
2532 @c Perhaps junk subsection ``Percussion staves''
2533 @subsubsection Percussion staves with normal staves
2534 When you include @file{drumpitch-init.ly} then the default pitches
2535 are overridden so that you after the inclusion cannot use the common
2536 dutch pitch names anymore. Hence you might wan't to reinclude
2537 @file{nederlands.ly} after the drum-pattern-definitions:
2538 @lilypond[singleline,verbatim]
2539 \include "drumpitch-init.ly"
2540 up = \notes { crashcymbal4 hihat8 halfopenhihat hh hh hh openhihat }
2541 down = \notes { bassdrum4 snare8 bd r bd sn4 }
2542 \include "nederlands.ly"
2543 bass = \notes \transpose c, { a4. e8 r e g e }
2544 \score {
2545     <
2546         \apply #(drums->paper 'drums) \context Staff = drums <
2547             \clef percussion
2548             \context Voice = up { \voiceOne \up }
2549             \context Voice = down { \voiceTwo \down }
2550         >
2551         \context Staff = bass { \clef "F_8" \bass }
2552     >
2553 }
2554 @end lilypond
2555
2556 @subsubsection Percussion midi output
2557 In order to produce correct midi output you need to produce two score
2558 blocks - one for the paper and one for the midi.
2559 To use the percussion channel you set the property @code{instrument}
2560 to @code{'drums}. Because the drum-pitches themself are similar to the
2561 general midi pitches all you have to do is to insert the voices with
2562 none of the scheme functions to get the correct midi output:
2563
2564 @example
2565 \score @{    
2566     \apply #(drums->paper 'mydrums) \context Staff <
2567         \clef percussion
2568         \context Voice = up @{ \voiceOne \up @}
2569         \context Voice = down @{ \voiceTwo \down @}
2570     >
2571     \paper@{@}
2572 @}
2573 \score @{    
2574     \context Staff <
2575         \property Staff.instrument = #'drums
2576         \up \down
2577     >
2578     \midi@{@}
2579 @}
2580 @end example
2581
2582 @refbugs
2583
2584 This scheme is to be considered a temporary implementation. Even
2585 though the scheme will probably keep on working then the future might
2586 bring some other way of typesetting drums, and probably
2587 there will be made no great efforts in keeping things downwards
2588 compatible.
2589
2590 @c . {Piano music}
2591 @node Piano music
2592 @section Piano music
2593
2594 Piano music is an odd type of notation. Piano staves are two normal
2595 staves coupled with a brace.  The staves are largely independent, but
2596 sometimes voices can cross between the two staves.  The
2597 @internalsref{PianoStaff} is especially built to handle this cross-staffing
2598 behavior.  In this section we discuss the @internalsref{PianoStaff} and some
2599 other pianistic peculiarities.
2600
2601 @menu
2602 * Automatic staff changes::     
2603 * Manual staff switches::       
2604 * Pedals::                      
2605 * Arpeggio::                    
2606 * Voice follower lines::        
2607 @end menu 
2608
2609
2610 @c .   {Automatic staff changes}
2611 @node Automatic staff changes
2612 @subsection Automatic staff changes
2613 @cindex Automatic staff changes
2614
2615 Voices can switch automatically between the top and the bottom
2616 staff. The syntax for this is
2617 @example
2618         \autochange Staff \context Voice @{ @dots{}@var{music}@dots{} @}
2619 @end example        
2620 The autochanger switches on basis of pitch (central C is the turning
2621 point), and it looks ahead skipping over rests to switch rests in
2622 advance. Here is a practical example:
2623         
2624 @lilypond[verbatim,singleline]
2625 \score { \notes \context PianoStaff <
2626   \context Staff = "up" {
2627     \autochange Staff \context Voice = VA < \relative c' {
2628        g4 a  b c d r4 a g } > }
2629   \context Staff = "down" {
2630        \clef bass
2631        s1*2
2632 } > }
2633 @end lilypond
2634 Spacer rests are used to prevent the bottom staff from
2635 terminating too soon.
2636
2637
2638 @node Manual staff switches
2639 @subsection Manual staff switches
2640
2641 @cindex manual staff switches
2642 @cindex staff switch, manual
2643
2644 Voices can be switched between staves manually, using the following command:
2645 @example
2646   \translator Staff = @var{staffname} @var{music}
2647 @end example
2648 The string @var{staffname} is the name of the staff. It switches the
2649 current voice from its current staff to the Staff called
2650 @var{staffname}. Typically @var{staffname} is @code{"up"} or
2651 @code{"down"}.
2652
2653 @c .   {Pedals}
2654 @node Pedals
2655 @subsection Pedals
2656 @cindex Pedals
2657
2658 Piano pedal instruction can be expressed using 
2659 @code{\sustainDown}, @code{\sustainUp}, @code{\unaCorda},
2660 @code{\treCorde}, @code{\sostenutoDown} and @code{\sostenutoUp}.
2661
2662 These identifiers are shorthands for spanner commands of the types
2663 @internalsref{Sustain}, @internalsref{UnaCorda} and @internalsref{Sostenuto}:
2664
2665 @lilypond[fragment,verbatim]
2666 c''4 \spanrequest \start "Sustain" c''4
2667 c''4 \spanrequest \stop "Sustain"
2668 @end lilypond
2669
2670 The symbols that are printed can be modified by setting
2671 @code{pedal@var{X}Strings}, where @var{X} is one of the pedal types:
2672 Sustain, Sostenuto or UnaCorda.  Refer to the generated documentation of
2673 @rgrob{SustainPedal}, for example, for more information.
2674
2675 Pedals can also be indicated by a sequence of brackets, by setting the 
2676 @code{pedal-type} property of SustainPedal grobs: 
2677
2678 @lilypond[fragment,verbatim]
2679 \property Staff.SustainPedal \override #'pedal-type = #'bracket
2680 c''4 \sustainDown d''4 e''4 a'4
2681 \sustainUp \sustainDown
2682  f'4 g'4 a'4 \sustainUp
2683 @end lilypond
2684
2685 A third style of pedal notation is a mixture of text and brackets,
2686 obtained by setting @code{pedal-type} to @code{mixed}:
2687
2688 @lilypond[fragment,verbatim]
2689 \property Staff.SustainPedal \override #'pedal-type = #'mixed
2690 c''4 \sustainDown d''4 e''4 c'4
2691 \sustainUp \sustainDown
2692  f'4 g'4 a'4 \sustainUp
2693 @end lilypond
2694
2695 The default '*Ped' style for sustain and damper pedals corresponds to
2696 @code{\pedal-type = #'text}. However, @code{mixed} is the default style
2697 for a sostenuto pedal:
2698
2699 @lilypond[fragment,verbatim]
2700 c''4 \sostenutoDown d''4 e''4 c'4 f'4 g'4 a'4 \sostenutoUp
2701 @end lilypond
2702
2703 For fine-tuning of the appearance of a pedal bracket, the properties
2704 @code{edge-width}, @code{edge-height}, and @code{shorten-pair} of
2705 @code{PianoPedalBracket} grobs (see the detailed documentation of
2706 @rgrob{PianoPedalBracket}) can be modified.  For example, the bracket
2707 may be extended to the end of the note head.
2708
2709 @lilypond[fragment,verbatim]
2710 \property Staff.PianoPedalBracket \override
2711    #'shorten-pair = #'(0 . -1.0)
2712 c''4 \sostenutoDown d''4 e''4 c'4
2713 f'4 g'4 a'4 \sostenutoUp
2714 @end lilypond
2715
2716
2717
2718 @c .   {Arpeggio}
2719 @node Arpeggio
2720 @subsection Arpeggio
2721 @cindex Arpeggio
2722
2723 @cindex broken arpeggio
2724 @cindex @code{\arpeggio}
2725
2726 You can specify an arpeggio sign on a chord by attaching an
2727 @code{\arpeggio} to a note of the chord.
2728
2729
2730 @lilypond[fragment,relative,verbatim]
2731   \context Voice <c\arpeggio e g c>
2732 @end lilypond
2733
2734 When an arpeggio crosses staves in piano music, you attach an arpeggio
2735 to the chords in both staves, and set
2736 @code{PianoStaff.connectArpeggios}.
2737
2738 @lilypond[fragment,relative,verbatim]
2739   \context PianoStaff <
2740     \property PianoStaff.connectArpeggios = ##t
2741     \context Voice = one  { <c'\arpeggio e g c> }
2742     \context Voice = other { \clef bass  <c,,\arpeggio e g>}
2743   >  
2744 @end lilypond
2745
2746 This command creates @internalsref{Arpeggio} grobs.  Cross staff arpeggios
2747 are @code{PianoStaff.Arpeggio}.
2748
2749 To add an arrow head to explicitly specify the direction of the
2750 arpeggio, you should set the arpeggio grob property
2751 @code{arpeggio-direction}.
2752
2753 @lilypond[fragment,relative,verbatim]
2754   \context Voice {
2755      \property Voice.Arpeggio \set #'arpeggio-direction = #1
2756      <c\arpeggio e g c>
2757      \property Voice.Arpeggio \set #'arpeggio-direction = #-1
2758      <c\arpeggio e g c>
2759   }
2760 @end lilypond
2761
2762 A square bracket on the left indicates that the player should not
2763 arpeggiate the chord. To draw these brackets, set the
2764 @code{molecule-callback} property of @code{Arpeggio} or
2765 @code{PianoStaff.Arpeggio} grobs to @code{\arpeggioBracket}, and use
2766 @code{\arpeggio} statements within the chords as before.
2767
2768 @lilypond[fragment,relative,verbatim]
2769   \context PianoStaff <
2770     \property PianoStaff.connectArpeggios = ##t
2771     \property PianoStaff.Arpeggio \override
2772         #'molecule-callback = \arpeggioBracket
2773     \context Voice = one  { <c'\arpeggio e g c> }
2774     \context Voice = other { \clef bass  <c,,\arpeggio e g>}
2775   >  
2776 @end lilypond
2777
2778
2779 @refbugs
2780
2781 It is not possible to mix connected arpeggios and unconnected
2782 arpeggios in one PianoStaff at the same time.
2783
2784
2785
2786 @node  Voice follower lines
2787 @subsection Voice follower lines
2788
2789 @cindex follow voice
2790 @cindex staff switching
2791 @cindex cross staff
2792
2793 @cindex @code{followVoice}
2794
2795 Whenever a voice switches to another staff a line connecting the notes
2796 can be printed automatically. This is enabled if the property
2797 @code{PianoStaff.followVoice} is set to true:
2798
2799 @lilypond[fragment,relative,verbatim]
2800   \context PianoStaff <
2801     \property PianoStaff.followVoice = ##t
2802     \context Staff \context Voice {
2803       c1
2804       \translator Staff=two
2805       b2 a
2806     }
2807     \context Staff=two {\clef bass \skip 1*2 }
2808   >  
2809 @end lilypond
2810
2811 The associated grob is @internalsref{VoiceFollower}.
2812
2813
2814 @node Tablatures
2815 @section Tablatures
2816
2817 Tablature notation is used music for plucked string instruments.  It
2818 notates pitches not by using note heads, but by indicating on which
2819 string and fret a note must be played.  LilyPond offers limited
2820 support for tablature, by abusing the fingering system.
2821
2822 @menu
2823 * Tablatures basic::            
2824 * Non-guitar tablatures::       
2825 * Tablature in addition to normal staff::  
2826 @end menu
2827
2828 @node Tablatures basic
2829 @subsection Tablatures basic
2830 @cindex Tablatures basic
2831
2832 Tablature can be typeset with Lilypond by using the
2833 @internalsref{TabStaff} and @internalsref{TabVoice} contexts. As
2834 tablature is a recent feature in Lilypond, most of the guitar special
2835 effects such as hammer, pull, bend are not yet supported.
2836
2837 With the @internalsref{TabStaff}, the string number associated to a note
2838 is given though the fingering mechanism, e.g. @code{c4-3} for a C
2839 quarter on the third string. The string 1 is the lowest one, and the
2840 tuning defaults to the standard guitar tuning (with 6 strings).
2841
2842 @lilypond[fragment,verbatim]
2843   \context TabStaff <
2844     \notes {
2845       \property Staff.Stem \override #'direction = #1
2846       
2847       a,4-2 c'-5 a-4 e'-6
2848       e-3 c'-5 a-4 e'-6
2849     }
2850   >  
2851 @end lilypond
2852
2853
2854 @node Non-guitar tablatures
2855 @subsection Non-guitar tablatures
2856 @cindex Non-guitar tablatures
2857
2858 There are many ways to customize Lilypond tablatures.
2859
2860 First you can change the number of strings, by setting the number of
2861 lines in the @internalsref{TabStaff}.  You can change the strings
2862 tuning. A string tuning is given as a Scheme list with one integer
2863 number for each string, the number being the pitch of an open string.
2864
2865 Finally, it is possible to change the Scheme function to format the
2866 tablature note text. The default is @var{fret-number-tablature-format},
2867 which uses the fret number, but for some instruments that may not use
2868 this notation, just create your own tablature-format function. This
2869 function takes three argument: the string number, the string tuning and
2870 the note pitch.
2871
2872
2873 @node Tablature in addition to normal staff
2874 @subsection Tablature in addition to normal staff
2875 @cindex Tablature in addition to normal staff
2876
2877 It is possible to typeset both tablature and a "normal" staff, as
2878 commonly done in many parts.
2879
2880 A common trick for that is to put the notes in a variables, and to hide
2881 the fingering information (which correspond to the string number) for
2882 the standard staff.
2883
2884 @lilypond[verbatim]
2885   part = \notes {
2886     a,4-2 c'-5 a-4 e'-6
2887     e-3 c'-5 a-4 e'-6
2888   }
2889   \score{
2890     \context StaffGroup <
2891       \context Staff <
2892         % Hide fingering number
2893         \property Staff.Fingering \override #'transparent = ##t
2894
2895         \part
2896       >
2897       \context TabStaff <
2898         \property Staff.Stem \override #'direction = #1
2899
2900         \part
2901       >
2902     >
2903   }
2904 @end lilypond
2905
2906
2907 @c . {Chords}
2908 @node Chords
2909 @section Chords
2910 @cindex Chords
2911
2912 LilyPond has support for both entering and printing chords. 
2913 @lilypond[verbatim,singleline]
2914 twoWays = \notes \transpose c'' {
2915   \chords {
2916     c1 f:sus4 bes/f
2917   }
2918   <c e g>
2919   <f bes c'>
2920   <f bes d'>
2921   }
2922
2923 \score {
2924    < \context ChordNames \twoWays
2925      \context Voice \twoWays > }
2926 @end lilypond
2927
2928 This example also shows that the chord printing routines do not try to
2929 be intelligent. If you enter @code{f bes d}, it does not interpret
2930 this as an inversion.
2931
2932 As you can see chords really are a set of pitches. They are internally
2933 stored as simultaneous music expressions. This means you can enter
2934 chords by name and print them as notes, enter them as notes and print
2935 them as chord names, or (the most common case) enter them by name, and
2936 print them as name.
2937
2938 @menu
2939 * Chords mode::                 
2940 * Printing named chords::       
2941 @end menu
2942
2943 @c .  {Chords mode}
2944 @node Chords mode
2945 @subsection Chords mode
2946 @cindex Chords mode
2947
2948 Chord mode is a mode where you can input sets of pitches using common
2949 names.  It is introduced by the keyword @code{\chords}.  It is similar
2950 to note mode, but words are also looked up in a chord modifier table
2951 (containing @code{maj}, @code{dim}, etc). Dashes and carets are used
2952 to indicate chord additions and subtractions, so articulation scripts
2953 can not be entered in Chord mode.
2954
2955 Throughout these examples, chords have been shifted around the staff
2956 using @code{\transpose}.
2957
2958 @lilypond[fragment,verbatim]
2959 \transpose c'' {
2960   \chords {
2961     c1  c:3-       c:7     c:8
2962     c:9 c:9-.5+.7+ c:3-.5- 
2963   }
2964 }
2965 @end lilypond
2966
2967 @cindex @code{aug}
2968 @cindex @code{dim}
2969 @cindex @code{maj}
2970 @cindex @code{sus}
2971
2972 The second type of modifier that may appear after the @code{:} is a
2973 named modifier.  Named modifiers are listed in the file
2974 @file{chord-modifiers.ly}.  The available modifiers are @code{m} and
2975 @code{min} which lower the 3rd half a step, `@code{aug}' which
2976 raises the 5th, `@code{dim}' which lowers the 5th,
2977 `@code{maj}' which adds a raised 7th, and `@code{sus}'
2978 which replaces the 5th with a 4th.
2979
2980 @lilypond[fragment,verbatim]
2981 \transpose c'' {
2982   \chords {
2983     c1:m c:min7 c:maj c:aug c:dim c:sus
2984   }
2985 }
2986 @end lilypond
2987  
2988
2989 Chord subtractions are used to eliminate notes from a chord.  The
2990 notes to be subtracted are listed after a @code{^} character,
2991 separated by dots.
2992
2993 @lilypond[fragment,verbatim,center]
2994   \transpose c'' {
2995     \chords {
2996       c1^3 c:7^5.3 c:8^7
2997     }
2998   }
2999 @end lilypond 
3000 @cindex @code{/}
3001
3002 Chord inversions can be specified by appending `@code{/}' and the name
3003 of a single note to a chord.  In a chord inversion, the inverted note is
3004 transposed down until it is the lowest note in the chord.  If the note
3005 is not in the chord, a warning will be printed.
3006
3007 @lilypond[fragment,verbatim,center]
3008   \transpose c''' {
3009     \chords {
3010       c1 c/e c/g c:7/e
3011     }
3012   }
3013
3014 @end lilypond 
3015 @cindex @code{/+}
3016
3017 Bass notes can be added by `@code{/+}' and
3018 the name of a single note to a chord.  This has the effect of
3019 adding the specified note to the chord, lowered by an octave,
3020 so it becomes the lowest note in the chord.
3021
3022 @lilypond[fragment,verbatim,center]
3023   \transpose c''' {
3024     \chords {
3025       c1 c/+c c/+g c:7/+b
3026     }
3027   }
3028
3029 @end lilypond 
3030
3031 The formal syntax for named chords is as follows:
3032 @example
3033   @var{tonic}[@var{duration}][@code{-}@var{modifiers}][@code{^}@var{subtractions}][@code{/}@var{inversion}][@code{/+}@var{bass}].
3034 @end example
3035
3036 @var{tonic} should be the tonic note of the chord, and @var{duration} is
3037 the chord duration in the usual notation.  There are two kinds of
3038 modifiers.  One type is formed by @emph{chord additions}. Additions are
3039 obtained by listing intervals separated by dots.  An interval is written
3040 by its number with an optional @code{+} or @code{-} to indicate raising
3041 or lowering by half a step.  Chord additions have two effects: they adds
3042 the specified interval and all lower odd numbered intervals to the
3043 chord, and they may lower or raise the specified interval.
3044
3045
3046 @refbugs
3047
3048 Implementation details are gory. For example @code{c:4} not only adds
3049 a fourth, but also removes the third.
3050
3051
3052 @c .  {Printing named chords}
3053 @node Printing named chords
3054 @subsection Printing named chords
3055
3056 @cindex printing chord names
3057 @cindex chord names
3058 @cindex chords
3059
3060 For displaying printed chord names, use the @internalsref{ChordNames} context.
3061 The chords may be entered either using the notation described above, or
3062 directly using simultaneous music.
3063
3064 @lilypond[verbatim,singleline]
3065 scheme = \notes {
3066   \chords {a1 b c} <d f g>  <e g b>
3067 }
3068 \score {
3069   \notes<
3070     \context ChordNames \scheme
3071     \context Staff \transpose c'' \scheme
3072   >
3073 }
3074 @end lilypond
3075
3076 You can make the chord changes stand out by setting
3077 @code{ChordNames.chordChanges} to true.  This will only display chord
3078 names when there's a change in the chords scheme and at the start of a
3079 new line.
3080
3081 @lilypond[verbatim]
3082 scheme = \chords {
3083   c1:m c:m \break c:m c:m d
3084 }
3085 \score {
3086   \notes <
3087     \context ChordNames {
3088         \property ChordNames.chordChanges = ##t
3089         \scheme }
3090     \context Staff \transpose c'' \scheme
3091   >
3092 \paper{linewidth= 9.\cm}
3093 }
3094 @end lilypond
3095
3096 LilyPond examines chords specified as lists of notes to determine a name
3097 to give the chord. LilyPond will not try to identify chord inversions or
3098 an added bass note, which may result in strange chord names when chords
3099 are entered as a list of pitches:
3100
3101 @lilypond[verbatim,center,singleline]
3102 scheme = \notes {
3103   <c'1 e' g'>
3104   <e' g' c''>
3105   <e e' g' c''>
3106 }
3107
3108 \score {
3109   <
3110     \context ChordNames \scheme
3111     \context Staff \scheme
3112   >
3113 }
3114 @end lilypond
3115
3116
3117 By default, a chord name system proposed by Harald Banter (See
3118 @ref{Literature}) is used. The system is very regular and predictable.
3119 Typical American style chord names may be selected by setting the
3120 @code{style} property of the @code{ChordNames.ChordName} grob to
3121 @code{'american}. Similarly @code{'jazz} selects Jazz chordnames.
3122
3123 Routines that determine the names to be printed are written in Scheme,
3124 and may be customized by the user.  The code can be found in
3125 @file{scm/chord-name.scm}.  Here's an example showing the differences in
3126 chord name styles:
3127
3128 @c too long?
3129 @c maybe just junk verbatim option?
3130 @lilypond[verbatim,singleline]
3131 scheme = \chords {
3132   c1 c:5^3 c:4^3 c:5+
3133   c:m7+ c:m5-.7
3134   c:5-.7 c:5+.7
3135   c:9^7
3136 }
3137
3138 \score {
3139   \notes <
3140     \context ChordNames = banter \scheme
3141     \context ChordNames = american {
3142       \property ChordNames.ChordName \override
3143         #'style = #'american \scheme }
3144     \context ChordNames = jazz {
3145       \property ChordNames.ChordName \override
3146         #'style = #'jazz \scheme }
3147     \context Staff \transpose c'' \scheme
3148   >
3149 }
3150 @end lilypond
3151
3152
3153 @node Writing parts
3154 @section Writing parts
3155
3156 Orchestral music involves some special notation, both in the full score,
3157 as in the individual parts. This section explains how to tackle common
3158 problems in orchestral music.
3159
3160
3161 @c .  {Transpose}
3162 @menu
3163 * Rehearsal marks::             
3164 * Bar numbers::                 
3165 * Instrument names::            
3166 * Transpose::                   
3167 * Multi measure rests::         
3168 * Automatic part combining::    
3169 * Hara kiri staves::            
3170 * Sound output for transposing instruments::  
3171 @end menu
3172
3173 @c .   {Rehearsal marks}
3174 @node Rehearsal marks
3175 @subsection Rehearsal marks
3176 @cindex Rehearsal marks
3177 @cindex mark
3178 @cindex @code{\mark}
3179
3180 To print a  rehearsal mark, use the @code{\mark} command. 
3181 @lilypond[fragment,verbatim]
3182 \relative c'' {
3183   c1 \mark "A"
3184   c1 \mark \default
3185   c1 \mark \default 
3186   c1 \mark "12"
3187   c1 \mark \default
3188   c1 \mark #'(music "scripts-segno") 
3189   c1
3190 }
3191 @end lilypond
3192
3193 As you can see, the mark is incremented automatically if you use
3194 @code{\mark \default}. The value to use is stored in the property
3195 @code{rehearsalMark} is used and automatically incremented.  The grob
3196 is @internalsref{RehearsalMark} in @internalsref{Score} context. See
3197 @code{input/test/boxed-molecule.ly} if you need boxes around the
3198 marks.
3199
3200 @node Bar numbers
3201 @subsection Bar numbers
3202
3203
3204 @cindex bar numbers
3205 @cindex measure numbers
3206 @cindex currentBarNumber
3207
3208 Bar numbers are printed by default at the start of the line.  The
3209 number itself is a property that can be set by modifying the
3210 @code{currentBarNumber} property, i.e.
3211 @example
3212   \property Score.currentBarNumber = #217
3213 @end example
3214
3215 If you want boxed bar numbers, see the example file
3216 @code{input/test/boxed-molecule.ly}.
3217
3218 See also @seeinternals{BarNumber}.
3219
3220 @refbugs
3221
3222 Printing bar numbers at regular intervals is not implemented.
3223 Barnumbers can collide with the StaffGroup, if there is one at the
3224 top. To solve this, You have to twiddle with the
3225 @internalsref{padding} property of @internalsref{BarNumber} if your
3226 score starts with a @internalsref{StaffGroup}.
3227
3228 @node Instrument names
3229 @subsection Instrument names
3230
3231 In scores, the instrument name is printed before the staff. This can
3232 be done by setting @code{Staff.instrument} and
3233 @code{Staff.instr}. This will print a string before the start of the
3234 staff. For the first start, @code{instrument} is used, for the next
3235 ones @code{instr} is used.
3236
3237 @lilypond[verbatim,singleline]
3238   \property Staff.instrument = "ploink " { c''4 }  
3239 @end lilypond
3240
3241 You can also use markup texts to construct more complicated instrument
3242 names:
3243
3244
3245 @lilypond[verbatim,singleline]
3246 #(define text-flat
3247   '((font-relative-size . -2 ) (music "accidentals--1")))
3248
3249 \score { \notes {
3250   \property Staff.instrument = #`((kern . 0.5) (lines
3251     "2 Clarinetti" (columns "     (B" ,text-flat ")")))
3252     c'' 4 }
3253 }
3254 @end lilypond
3255
3256
3257 @refbugs
3258
3259 When you put a name on a grand staff or piano staff the width of the
3260 brace is not taken into account. You must add extra spaces to the end of
3261 the name to avoid a collision.
3262
3263 @node Transpose
3264 @subsection Transpose
3265 @cindex Transpose
3266 @cindex transposition of pitches
3267 @cindex @code{\transpose}
3268
3269 A music expression can be transposed with @code{\transpose}.  The syntax
3270 is
3271 @example
3272   \transpose @var{pitch} @var{musicexpr}
3273 @end example
3274
3275 This means that middle C in @var{musicexpr} is transposed to
3276 @var{pitch}.
3277
3278 @code{\transpose} distinguishes between enharmonic pitches: both
3279 @code{\transpose cis'} or @code{\transpose des'} will transpose up half
3280 a tone.  The first version will print sharps and the second version
3281 will print flats.
3282
3283 @lilypond[singleline, verbatim]
3284 mus =\notes { \key d \major cis d fis g }
3285 \score { \notes \context Staff {
3286   \clef "F" \mus
3287   \clef "G"
3288   \transpose g'' \mus
3289   \transpose f'' \mus
3290 }}
3291 @end lilypond
3292
3293 If you want to use both @code{\transpose} and @code{\relative}, then
3294 you must use @code{\transpose} first.  @code{\relative} will have no
3295 effect music that appears inside a @code{\transpose}.
3296
3297 @c .  {Multi measure rests}
3298 @node  Multi measure rests
3299 @subsection Multi measure rests
3300 @cindex Multi measure rests
3301
3302 @cindex @code{R}
3303
3304 Multi measure rests are entered using `@code{R}'. It is specifically
3305 meant for full bar rests and for entering parts: the rest can expand to
3306 fill a score with 
3307 rests, or it can be printed as a single multimeasure rest This expansion
3308 is controlled by the property @code{Score.skipBars}. If this is set to true,
3309 Lily will not expand empty measures, and the appropriate number is added
3310 automatically.
3311
3312 @lilypond[fragment,verbatim]
3313  \time 3/4 r2. | R2. | R2.*2
3314  \property Score.skipBars = ##t R2.*17  R2.*4
3315 @end lilypond
3316
3317 Notice that the @code{R2.} is printed as a whole rest, centered in the
3318 measure. 
3319
3320 @cindex whole rests for a full measure 
3321
3322 The grob for this object is @internalsref{MultiMeasureRest}.
3323
3324 @refbugs
3325
3326 Currently, there is no way to automatically condense multiple rests
3327 into a single multimeasure rest. Multi measure rests do not take part
3328 in rest collisions.
3329
3330 @cindex condensing rests
3331
3332 @node Automatic part combining
3333 @subsection Automatic part combining
3334 @cindex automatic part combining
3335 @cindex part combiner
3336
3337
3338 Automatic part combining is used to merge two parts of music onto a
3339 staff in an intelligent way.  It is aimed primarily at typesetting
3340 orchestral scores.  When the two parts are identical for a period of
3341 time, only one is shown.  In places where the two parts differ, they
3342 are typeset as separate voices, and stem directions are set
3343 automatically.  Also, solo and @emph{a due} parts can be identified
3344 and marked.
3345
3346 The syntax for part combining is
3347
3348 @example
3349   \partcombine @var{context} @var{musicexpr1} @var{musicexpr2}
3350 @end example
3351 where the pieces of music @var{musicexpr1} and @var{musicexpr2} will be
3352 combined into one context of type @var{context}.  The music expressions
3353 must be interpreted by contexts whose names should start with @code{one}
3354 and @code{two}.
3355
3356 The most useful function of the part combiner is to combine parts into
3357 one voice, as common for wind parts in orchestral scores:
3358
3359 @lilypond[verbatim,singleline,fragment]
3360   \context Staff <
3361     \context Voice=one \partcombine Voice
3362       \context Thread=one \relative c'' {
3363         g a () b r
3364       }
3365       \context Thread=two \relative c'' {
3366         g r4 r f
3367       }
3368   >
3369 @end lilypond
3370
3371 Notice that the first @code{g} appears only once, although it was
3372 specified twice (once in each part).  Stem, slur and tie directions are
3373 set automatically, depending whether there is a solo or unisono. The
3374 first part (with context called @code{one}) always gets up stems, and
3375 `solo', while the second (called @code{two}) always gets down stems and
3376 `Solo II'.
3377
3378 If you just want the merging parts, and not the textual markings, you
3379 may set the property @var{soloADue} to false.
3380
3381 @lilypond[verbatim,singleline,fragment]
3382   \context Staff <
3383     \property Staff.soloADue = ##f
3384     \context Voice=one \partcombine Voice
3385       \context Thread=one \relative c'' {
3386         b4 a c g
3387       }
3388       \context Thread=two \relative c'' {
3389         d,2 a4 g'
3390       }
3391   >
3392 @end lilypond
3393
3394 There are a number of other properties that you can use to tweak the
3395 behavior of part combining, refer to the automatically generated
3396 documentation of @reng{Thread_devnull_engraver} and
3397 @reng{Voice_devnull_engraver}. Look at the documentation of the
3398 responsible engravers, @code{Thread_devnull_engraver},
3399 @code{Voice_devnull_engraver} and @code{A2_engraver}.
3400
3401 @refbugs
3402
3403 In @code{soloADue} mode, when the two voices play the same notes on and
3404 off, the part combiner may typeset @code{a2} more than once in a
3405 measure.
3406
3407 @lilypond[fragment,singleline]
3408   \context Staff <
3409     \context Voice=one \partcombine Voice
3410       \context Thread=one \relative c'' {
3411         c b c b c a c a
3412       }
3413       \context Thread=two \relative c'' {
3414         b b b b f a f a
3415       }
3416   >
3417 @end lilypond
3418
3419 @cindex @code{Thread_devnull_engraver}
3420 @cindex @code{Voice_engraver}
3421 @cindex @code{A2_engraver}
3422
3423 @node Hara kiri staves
3424 @subsection Hara kiri staves
3425
3426 In orchestral scores, staff lines that only have rests are usually removed.
3427 This saves some space.  LilyPond also supports this through the hara
3428 kiri@footnote{Hara kiri, also called Seppuku, is the ritual suicide of
3429 the Japanese Samourai warriors.} staff. This staff commits suicide when
3430 it finds itself to be empty after the line-breaking process.  It will
3431 not disappear when it contains normal rests, you must use multi measure
3432 rests.
3433
3434 The hara kiri staff is specialized version of the @internalsref{Staff}
3435 context. It is available as the context identifier
3436 @code{\HaraKiriStaffContext}.  Observe how the second staff in this
3437 example disappears in the second line.
3438
3439 @lilypond[verbatim]
3440 \score  {
3441   \notes \relative c' <
3442     \context Staff = SA { e4 f g a \break c1 }
3443     \context Staff = SB { c4 d e f \break R1 }
3444   >
3445   \paper {
3446     linewidth = 6.\cm 
3447     \translator { \HaraKiriStaffContext }
3448   }
3449 }
3450 @end lilypond
3451
3452
3453 @node Sound output for transposing instruments
3454 @subsection Sound output for transposing instruments
3455
3456 When you want to make a MIDI file from a score containing transposed
3457 and untransposed instruments, you have to instruct LilyPond the pitch
3458 offset (in semitones) for the transposed instruments. This is done
3459 using the @code{transposing} property. It does not affect printed
3460 output.
3461
3462 @cindex @code{transposing}
3463
3464 @example
3465         \property Staff.instrument = #"Cl. in B-flat"
3466         \property Staff.transposing = #-2
3467 @end example
3468
3469
3470
3471 @c . {Custodes}
3472 @node Ancient notation 
3473 @section Ancient notation
3474
3475 @menu
3476 * Ancient note heads::          
3477 * Custodes::                    
3478 * Ancient clefs ::              
3479 * Figured bass::                
3480 @end menu
3481
3482
3483 @node Ancient note heads
3484 @subsection Ancient note heads
3485
3486  To get a longa note head, you have to use mensural note heads. This
3487 is accomplished by setting the @code{style} property of the
3488 NoteHead grob to @code{mensural}. There is also a note head style
3489 @code{baroque} which gives mensural note heads for @code{\longa} and
3490 @code{\breve} but standard note heads for shorter notes.
3491
3492 @lilypond[fragment,singleline,verbatim]
3493  \property Voice.NoteHead \set #'style = #'mensural
3494  \property Voice.NoteHead \set #'font-family = #'ancient
3495  a'\longa
3496 @end lilypond
3497
3498 @node Custodes
3499 @subsection Custodes
3500
3501 @cindex Custos
3502 @cindex Custodes
3503
3504 A @emph{custos} (plural: @emph{custodes}; latin word for `guard') is a
3505 staff context symbol that appears at the end of a staff line.  It
3506 anticipates the pitch of the first note(s) of the following line and
3507 thus helps the player or singer to manage line breaks during
3508 performance, thus enhancing readability of a score.
3509
3510 @lilypond[verbatim]
3511 \score {
3512   \notes { c'1 \break
3513         \property Staff.Custos \set #'style = #'mensural
3514         d' }
3515   \paper {
3516     \translator {
3517       \StaffContext
3518       \consists Custos_engraver
3519     }
3520   }
3521 }
3522 @end lilypond
3523
3524 Custodes were frequently used in music notation until the 17th century.
3525 There were different appearances for different notation styles.
3526 Nowadays, they have survived only in special forms of musical notation
3527 such as via the @emph{editio vaticana} dating back to the beginning of
3528 the 20th century.
3529
3530 For typesetting custodes, just put a @code{Custos_engraver} into the
3531 @internalsref{Staff} context when declaring the @code{\paper} block.  In this
3532 block, you can also globally control the appearance of the custos symbol
3533 by setting the custos @code{style} property.  Currently supported styles
3534 are @code{vaticana}, @code{medicaea}, @code{hufnagel} and
3535 @code{mensural}.
3536
3537 @example
3538 \paper @{
3539   \translator @{
3540       \StaffContext
3541       \consists Custos_engraver
3542       Custos \override #'style = #'mensural
3543   @}
3544 @}
3545 @end example
3546
3547 The property can also be set locally, for example in a @code{\notes}
3548 block:
3549
3550 @example
3551 \notes @{
3552   \property Staff.Custos \override #'style = #'vaticana
3553   c'1 d' e' d' \break c' d' e' d'
3554 @}
3555 @end example
3556
3557 @node Ancient clefs 
3558 @subsection Ancient clefs
3559
3560 LilyPond supports a variety of clefs, many of them ancient. These can
3561 be selected from the @code{ancient} font family, by setting
3562 @code{Staff.clefGlyph}) to one of the following values
3563
3564 @table @code
3565 @item clefs-C
3566  modern style C clef
3567 @item clefs-F
3568  modern style F clef
3569 @item clefs-G
3570  modern style G clef
3571 @item clefs-vaticana_do
3572  Editio Vaticana style do clef
3573 @item clefs-vaticana_fa
3574  Editio Vaticana style fa clef
3575 @item clefs-medicaea_do
3576  Editio Medicaea style do clef
3577 @item clefs-medicaea_fa
3578  Editio Medicaea style fa clef
3579 @item clefs-mensural1_c
3580  modern style mensural C clef
3581 @item clefs-mensural2_c
3582  historic style small mensural C clef
3583 @item clefs-mensural3_c
3584  historic style big mensural C clef
3585 @item clefs-mensural1_f
3586  historic style traditional mensural F clef
3587 @item clefs-mensural2_f
3588  historic style new mensural F clef
3589 @item clefs-mensural_g
3590  historic style mensural G clef
3591 @item clefs-hufnagel_do
3592  historic style hufnagel do clef
3593 @item clefs-hufnagel_fa
3594  historic style hufnagel fa clef
3595 @item clefs-hufnagel_do_fa
3596  historic style hufnagel combined do/fa clef
3597 @item clefs-percussion
3598  modern style percussion clef
3599 @end table
3600
3601 @emph{Modern style} means ``as is typeset in current editions.''
3602 @emph{Historic style} means ``as was typeset or written in contemporary
3603 historic editions''.  @emph{Editio XXX style} means ``as is/was printed in
3604 Editio XXX.''
3605
3606 @cindex Vaticana, Editio
3607 @cindex Medicaea, Editio
3608 @cindex hufnagel clefs
3609
3610
3611 @node Figured bass
3612 @subsection Figured bass
3613
3614 @cindex Basso continuo
3615
3616 LilyPond has limited support for figured bass:
3617
3618 @lilypond[verbatim,fragment]
3619 <
3620  \context FiguredBass
3621    \figures {
3622         <_! 3+ 5- >4
3623         < [4 6] 8 >
3624    }
3625  \context Voice { c4 g8 }
3626 >
3627 @end lilypond
3628
3629 The support for figured bass consists of two parts: there is an input
3630 mode, introduced by @code{\figures}, where you can enter bass figures
3631 as numbers, and there is a context called @internalsref{FiguredBass}
3632 that takes care of making @internalsref{BassFigure} grobs.
3633
3634 In figures input mode, a group of bass figures is delimited by
3635 @code{<} and @code{>}. The duration is entered after the @code{>}.
3636 @example
3637         <4 6>
3638 @end example
3639 @lilypond[fragment]
3640 \context FiguredBass
3641 \figures { <4 6> }
3642 @end lilypond
3643
3644 Accidentals are added to the numbers if you alterate them by
3645 appending @code{-}, @code{!}  and @code{+}.
3646
3647 @example
3648   <4- 6+ 7!>
3649 @end example
3650 @lilypond[fragment]
3651   \context FiguredBass
3652 \figures { <4- 6+ 7!> }
3653 @end lilypond
3654
3655 Spaces or dashes may be inserted by using @code{_}. Brackets are
3656 introduced with @code{[} and @code{]}.
3657
3658 @example
3659         < [4 6] 8 [_ 12]>
3660 @end example
3661 @lilypond[fragment]
3662  \context FiguredBass
3663 \figures { < [4 6] 8 [_ 12]> }
3664 @end lilypond
3665
3666 Although the support for figured bass may superficially resemble chord
3667 support, it works much simpler: in figured bass simply stores the
3668 numbers, and then prints the numbers you entered. There is no
3669 conversion to pitches, and no realizations of the bass are played in
3670 the MIDI file.
3671
3672
3673 @c . {Tuning output}
3674 @node Tuning output
3675 @section Tuning output
3676
3677 LilyPond tries to take as much formatting as possible out of your
3678 hands. Nevertheless, there are situations where it needs some help, or
3679 where you want to override its decisions. In this section we discuss
3680 ways to do just that.
3681
3682 Formatting is internally done by manipulating so called grobs (graphic
3683 objects). Each grob carries with it a set of properties (grob
3684 properties) specific to that object.  For example, a stem grob has
3685 properties that specify its direction, length and thickness.
3686
3687 The most direct way of tuning the output is by altering the values of
3688 these properties. There are two ways of doing that: first, you can
3689 temporarily change the definition of a certain type of grob, thus
3690 affecting a whole set of objects.  Second, you can select one specific
3691 object, and set a grob property in that object.
3692
3693 @menu
3694 * Tuning groups of grobs ::     
3695 * Tuning per grob ::            
3696 * Font selection::              
3697 * Text markup::                 
3698 @end menu
3699
3700 @node Tuning groups of grobs 
3701 @subsection Tuning groups of grobs 
3702
3703 @cindex grob description
3704
3705
3706
3707 A grob definition is a Scheme association list, that is stored in a
3708 context property.  By assigning to that property (using plain
3709 @code{\property}), you can change the resulting grobs.
3710
3711 @lilypond[verbatim, fragment]
3712 c'4 \property Voice.Stem  = #'()
3713 @end lilypond
3714
3715 The @code{\property} assignment effectively empties the definition of
3716 the Stem object. One of the effects is that the recipe of how it should be
3717 printed is erased, with the effect of rendering it invisible.  The above
3718 assignment is available as a standard identifier, for the case that you
3719 find this useful:
3720
3721 @example
3722   \property Voice.Stem = \turnOff
3723 @end example
3724
3725 @cindex \override
3726 @cindex \revert
3727 @cindex \set
3728
3729 This mechanism is fairly crude, since you can only set, but not modify,
3730 the definition of a grob. For this reason, there is a more advanced
3731 mechanism.
3732
3733 The definition of a grob is actually a list of default grob
3734 properties. For example, the definition of the Stem grob (available in
3735 @file{scm/grob-description.scm}), defines the following values for
3736 @internalsref{Stem}
3737
3738 @example
3739         (thickness . 0.8)
3740         (beamed-lengths . (0.0 2.5 2.0 1.5))
3741         (Y-extent-callback . ,Stem::height)
3742         @var{...}
3743 @end example
3744
3745 You can add a property on top of the existing definition, or remove a
3746 property, thus overriding the system defaults:
3747 @lilypond[verbatim]
3748 c'4 \property Voice.Stem \override #'thickness = #4.0
3749 c'4 \property Voice.Stem \revert #'thickness
3750 c'4
3751 @end lilypond
3752 You should balance @code{\override} and @code{\revert}. If that's too
3753 much work, you can use the @code{\set} shorthand. It performs a revert
3754 followed by an override. The following example gives exactly the same
3755 result as the previous one. 
3756 @lilypond[verbatim]
3757 c'4 \property Voice.Stem \set #'thickness = #4.0
3758 c'4 \property Voice.Stem \set #'thickness = #0.8
3759 c'4
3760 @end lilypond
3761 If you use @code{\set}, you must explicitly restore the default.
3762
3763
3764 Formally the syntax for these constructions is
3765 @example
3766 \property @var{context}.@var{grobname} \override @var{symbol} = @var{value}
3767 \property @var{context}.@var{grobname} \set @var{symbol} = @var{value}
3768 \property @var{context}.@var{grobname} \revert @var{symbol}
3769 @end example
3770 Here @var{symbol} is a Scheme expression of symbol type, @var{context}
3771 and @var{grobname} are strings and @var{value} is a Scheme expression.
3772
3773
3774 If you revert a setting which was not set in the first place, then it
3775 has no effect. However, if the setting was set as a system default, it
3776 may remove the default value, and this may give surprising results,
3777 including crashes.  In other words, @code{\override} and @code{\revert},
3778 must be carefully balanced.
3779
3780 These are examples of correct nesting of @code{\override}, @code{\set},
3781 @code{\revert}. 
3782
3783 A clumsy but correct form:
3784 @example
3785   \override \revert \override \revert \override \revert
3786 @end example
3787
3788 Shorter version of the same:
3789 @example 
3790   \override \set \set  \revert
3791 @end example
3792
3793 A short form, using only @code{\set}. This requires you to know the
3794 default value:
3795 @example
3796   \set \set \set \set @var{to default value}
3797 @end example
3798
3799 If there is no default (i.e. by default, the grob property is unset),
3800 then you can use
3801 @example
3802   \set \set \set \revert
3803 @end example
3804
3805 For the digirati, the grob description is an Scheme association
3806 list. Since a Scheme list is a singly linked list, we can treat it as a
3807 stack, and @code{\override} and @code{\revert} are just push and pop
3808 operations. This pushing and popping is also used for overriding
3809 automatic beaming settings.
3810
3811 @refbugs
3812
3813 LilyPond will hang or crash if @var{value} contains cyclic references.
3814 The backend is not very strict in type-checking grob properties. If you
3815 @code{\revert} properties that are expected to be set by default,
3816 LilyPond may crash.
3817
3818
3819 @cindex adjusting staff symbol
3820 @cindex StaffSymbol, using \property
3821 @cindex staff lines, setting number of
3822
3823 Some grobs are created at the moment that their context is created. An
3824 example of such a grob is the staff itself (i.e. the horizontal lines).
3825 You can not change the appearance of the staff symbol by manipulating
3826 @code{\property Staff.StaffSymbol}.  At the moment that @code{\property
3827 Staff} is interpreted, a Staff context is made, and the StaffSymbol is
3828 created before any @code{\override} is effective. You can deal with this
3829 either overriding properties in a @code{\translator} definition, or by
3830 using @code{\outputproperty}.
3831
3832
3833
3834
3835 @node Tuning per grob 
3836 @subsection Tuning per grob 
3837
3838 @cindex \outputproperty
3839
3840 A second way of tuning grobs is the more arcane @code{\outputproperty}
3841 feature.  The syntax is as follows:
3842 @example
3843 \outputproperty @var{predicate} @var{symbol} = @var{value}
3844 @end example
3845 Here @code{predicate} is a Scheme function taking a grob argument, and
3846 returning a boolean.  This statement is processed by the
3847 @code{Output_property_engraver}.  It instructs the engraver to feed all
3848 grobs that it sees to @var{predicate}. Whenever the predicate returns
3849 true, the grob property @var{symbol} will be set to @var{value}.
3850
3851 You will need to combine this statement with @code{\context} to select
3852 the appropriate context to apply this to.
3853
3854 Here are some random examples. 
3855
3856
3857 In the following example, all note heads occurring at current staff
3858 level, are shifted up and right by setting their @code{extra-offset}
3859 property.
3860
3861 @lilypond[fragment,verbatim,singleline]
3862 \relative c'' { c4
3863   \context Staff \outputproperty
3864   #(make-type-checker 'note-head-interface)
3865   #'extra-offset = #'(0.5 . 0.75)
3866   <c8 e g> }
3867 @end lilypond
3868
3869 @cindex @code{extra-offset}
3870
3871 In this example, the predicate checks the @code{text} grob property, to
3872 shift only the `m.d.' text,  but not the fingering instruction "2".
3873 @lilypond[verbatim,singleline]
3874 #(define (make-text-checker text)
3875    (lambda (grob) (equal? text (ly-get-grob-property grob 'text))))
3876
3877 \score {    
3878   \notes\relative c''' {
3879     \property Voice.Stem \set #'direction = #1
3880     \outputproperty #(make-text-checker "m.d.")
3881       #'extra-offset = #'(-3.5 . -4.5)
3882     a^2^"m.d."    
3883   }
3884 }
3885 @end lilypond
3886
3887 @refbugs
3888
3889 If possible, avoid this feature: the semantics are not very clean, and
3890 the syntax and semantics are up for rewrite.
3891
3892
3893
3894
3895 @node Font selection
3896 @subsection Font selection
3897
3898 The most common thing to change about the appearance of fonts is
3899 their size. The font size of a @internalsref{Voice},
3900 @internalsref{Staff} or @internalsref{Thread} context, can be easily
3901 changed by setting the @code{fontSize} property for that context:
3902 @lilypond[fragment,relative=1]
3903   c4 c4 \property Voice.fontSize = #-1
3904   f4 g4
3905 @end lilypond
3906  This command will not change the size of variable symbols, such as
3907 beams or slurs.  You can use this command to get smaller symbol for
3908 cue notes, but that involves some more subtleties. An elaborate
3909 example of those is in @file{input/test/cue-notes.ly}.
3910
3911 @cindex cue notes
3912 @cindex font size
3913 @cindex size
3914
3915 The font used for printing a grob can be selected by setting
3916 @code{font-name}, e.g.
3917 @example
3918   \property Staff.TimeSignature
3919     \set #'font-name = #"cmr17"
3920 @end example
3921 You may use any font which is available to @TeX{}, such as foreign
3922 fonts or fonts that do not belong to the Computer Modern font family.
3923 Font selection for the standard fonts, @TeX{}'s Computer Modern fonts,
3924 can also be adjusted with a more fine-grained mechanism.  By setting
3925 the grob properties described below, you can select a different font.
3926 All three mechanisms work for every grob that supports
3927 @code{font-interface}.
3928
3929 @table @code
3930 @item font-family
3931  A symbol indicating the general class of the typeface.  Supported are
3932 @code{roman} (Computer Modern), @code{braces} (for piano staff
3933 braces), @code{music} (the standard music font), @code{ancient} (the
3934 ancient notation font) @code{dynamic} (font for dynamic signs) and
3935 @code{typewriter}. 
3936   
3937 @item font-shape
3938   A symbol indicating the shape of the font, there are typically several
3939   font shapes available for each font family. Choices are @code{italic},
3940   @code{caps} and @code{upright} 
3941
3942 @item font-series
3943 A  symbol indicating the series of the font. There are typically several
3944 font series for each font family and shape. Choices are @code{medium}
3945 and @code{bold}. 
3946
3947 @item font-relative-size
3948   A number indicating the size relative the standard size.  For example,
3949   with 20pt staff height, relative size -1  corresponds to 16pt staff
3950   height, and relative size +1 corresponds to 23 pt staff height.
3951
3952 @item font-design-size
3953 A number indicating  the design size of the font. 
3954
3955 This is a feature of the Computer Modern Font: each point size has a
3956 slightly different design. Smaller design sizes are relatively wider,
3957 which enhances readability.
3958 @end table
3959
3960 For any of these properties, the value @code{*} (i.e. the @emph{symbol},
3961 @code{*}, entered as @code{#'*}), acts as a wildcard. This can be used
3962 to override default setting, which are always present. For example:
3963 @example
3964   \property Lyrics . LyricText \override #'font-series = #'bold
3965   \property Lyrics . LyricText \override #'font-family = #'typewriter
3966   \property Lyrics . LyricText \override #'font-shape = #'*
3967 @end example
3968
3969 @cindex @code{font-style}
3970
3971 There are also pre-cooked font selection qualifiers. These are
3972 selected through the grob property @code{font-style}.  For example,
3973 the style @code{finger} selects family @code{number} and relative size
3974 @code{-3}.  Styles available include @code{volta}, @code{finger},
3975 @code{tuplet}, @code{timesig}, @code{mmrest}, @code{script},
3976 @code{large}, @code{Large} and @code{dynamic}. The style sheets and
3977 tables for selecting fonts are located in @file{scm/font.scm}. Refer
3978 to this file for more information.
3979
3980 @cindex magnification
3981
3982 The size of the font may be scaled with the grob property
3983 @code{font-magnification}.  For example, @code{2.0} blows up all
3984 letters by a factor 2 in both directions.
3985
3986 @refbugs
3987
3988 Relative size is not linked to any real size.
3989
3990 There is no style sheet provided for other fonts besides the @TeX{}
3991 family, and the style sheet can not be modified easiyl.
3992
3993 @cindex font selection
3994 @cindex font magnification
3995 @cindex @code{font-interface}
3996
3997
3998 @node Text markup
3999 @subsection Text markup
4000 @cindex text markup
4001 @cindex markup text
4002
4003 LilyPond has an internal mechanism to typeset texts. You can
4004 form text markup expressions by composing scheme expressions
4005 in the following way.
4006
4007 @lilypond[verbatim, singleline]
4008  \relative c' {
4009     \fatText
4010     a^#"upright"
4011     b_#'(bold "bold")
4012     c^#'(italic "italic")
4013     d_#'((bold italic) "ff")
4014     e^#'(dynamic "ff")
4015     f_#'(lines "one" (bold "two"))
4016     g^#'(music "noteheads-2" ((raise . 2.4) "flags-u3"))
4017   }
4018 @end lilypond
4019
4020 Normally, the Scheme markup text is stored in the @code{text} property
4021 of a grob.  Formally, it is defined as follows:
4022
4023 @example
4024 text: string | (head? text+)
4025 head: markup | (markup+)
4026 markup-item: property | abbrev
4027 property: (@var{key} . @var{value})
4028 abbrev: @code{columns lines roman music bold italic named super sub}
4029         @code{overstrike text finger volta timesig mmrest mark script}
4030         @code{large Large dynamic}
4031 @end example
4032
4033 The markup is broken down and converted into a list of grob properties,
4034 which are prepended to the property list.  The @var{key}-@var{value}
4035 pair is a grob property. A list of properties available is included in
4036 the generated documentation for @rint{Text_interface}.
4037
4038 The following abbreviations are defined:
4039 @table @code
4040 @item columns
4041  horizontal mode: set all text on one line (default)
4042 @item lines
4043  vertical mode: set every text on a new line
4044 @item roman
4045  select roman font
4046 @item music
4047  selects the Feta font (the standard font for music notation glyphs),
4048 and uses named lookup
4049
4050 @item bold
4051  select bold series
4052 @item italic
4053  select italic shape
4054 @item named
4055  lookup by character name
4056 @item text
4057  plain text lookup (by character value)
4058 @item super
4059  superscript
4060 @item sub
4061  subscript
4062 @item overstrike
4063  the next text or character overstrikes this one
4064 @item finger
4065  select fingering number fontstyle
4066 @item volta
4067  select volta number fontstyle
4068 @item timesig
4069  select time signature number fontstyle
4070 @item mmrest
4071  select multi measure rest number fontstyle
4072 @item mark
4073  select mark number fontstyle
4074 @item script
4075  select scriptsize roman fontstyle
4076 @item large
4077  select large roman fontstyle
4078 @item Large
4079  select Large roman fontstyle
4080 @item dynamic
4081  select dynamics fontstyle
4082 @end table
4083
4084
4085 @cindex metronome mark
4086
4087 One practical application of complicated markup is to fake a metronome
4088 marking:
4089
4090 @lilypond[verbatim]
4091 #(define note '(columns
4092   (music "noteheads-2" ((kern . -0.1) "flags-stem"))))
4093 #(define eight-note `(columns ,note ((kern . -0.1)
4094   (music ((raise . 3.5) "flags-u3")))))
4095 #(define dotted-eight-note
4096   `(columns ,eight-note (music "dots-dot")))
4097
4098 \score {
4099   \notes\relative c'' {
4100     a1^#`((columns (font-relative-size . -1)) ,dotted-eight-note " = 64")
4101   }
4102   \paper {
4103     linewidth = -1.
4104     \translator{
4105       \ScoreContext
4106       TextScript \override #'font-shape = #'upright
4107     }
4108   }
4109 }
4110 @end lilypond
4111
4112 @refbugs
4113
4114 The syntax and semantics of markup texts are not clean, and both
4115 syntax and semantics are slated for a rewrite.
4116
4117 LilyPond does not do kerning, and there generally spaces texts
4118 slightly too wide.
4119
4120
4121
4122 @node Global layout
4123 @section Global layout
4124
4125 The global layout determined by three factors: the page layout, the
4126 iline breaks and the spacing. These all influence each other: The
4127 choice of spacing determines how densely each system of music is set,
4128 whree line breaks breaks are chosen, and thus ultimately how many
4129 pages a piece of music takes. In this section we will explain how the
4130 lilypond spacing engine works, and how you can tune its results.
4131
4132 Globally spoken, this procedure happens in three steps: first,
4133 flexible distances (``springs'') are chosen, based on durations. All
4134 possible line breaking combination are tried, and the one with the
4135 best results---a layout that has uniform density and requires as
4136 little stretching or cramping as possible---is chosen. When the score
4137 is processed by @TeX{}, page are filled with systems, and page breaks
4138 are chosen whenever the page gets full.
4139
4140 @menu
4141 * Vertical spacing::            
4142 * Horizontal spacing::          
4143 * Font Size::                   
4144 * Line breaking::               
4145 * Page layout::                 
4146 @end menu
4147
4148
4149 @node Vertical spacing
4150 @subsection Vertical spacing
4151
4152 @cindex vertical spacing
4153 @cindex distance between staffs
4154 @cindex staff distance
4155 @cindex between staves, distance
4156
4157 The height of each system is determined automatically by lilypond, to
4158 keep systems from bumping into each other, some minimum distances are
4159 set.  By changing these, you can put staffs closer together, and thus
4160 put more  systems onto one page.
4161
4162 Normally staves are stacked vertically. To make
4163 staves maintain a distance, their vertical size is padded. This is
4164 done with the property @code{minimumVerticalExtent}. It takes a pair
4165 of numbers, so if you want to make it smaller from its, then you could
4166 set
4167 @example
4168   \property Staff.minimumVerticalExtent = #'(-4 . 4)
4169 @end example
4170 This sets the vertical size of the current staff to 4 staff-space on
4171 either side of the center staff line.  The argument of
4172 @code{minimumVerticalExtent} is interpreted as an interval, where the
4173 center line is the 0, so the first number is generally negative.  you
4174 could also make the staff larger at the bottom by setting it to
4175 @code{(-6 . 4)}. The default value is @code{(-6 . 6)}.
4176
4177 Vertical aligment of staves is handled by the
4178 @internalsref{VerticalAlignment} grob, which lives at
4179 @internalsref{Score} level.
4180
4181 The piano staffs are handled a little differently: to make cross-staff
4182 beaming work correctly, it necessary that the distance between staves
4183 is fixed.  This is also done with a @internalsref{VerticalAlignment}
4184 grob, created in @internalsref{PianoStaff}, but a forced distance is
4185 set. This is done with the grob property #'forced-distance. If you
4186 want to override this, use a @code{\translator} block as follows:
4187 @example
4188   \translator @{
4189     \PianoStaffContext
4190     VerticalAlignment \override #'forced-distance = #9
4191   @}
4192 @end example
4193 This would bring the staffs together at a distance of 9 staff spaces,
4194 and again this is measured from the center line of each staff.
4195
4196
4197
4198 @node Horizontal spacing
4199 @subsection Horizontal Spacing
4200
4201 The spacing engine translates differences in durations into
4202 stretchable distances (``springs'') of differing lengths. Longer
4203 durations get more space, shorter durations get less.  The basis for
4204 assigning spaces to durations, is that the shortest durations get a
4205 fixed amount of space, and the longer durations get more: doubling a
4206 duration adds a fixed amount of space to the note.
4207
4208 For example, the following piece contains lots of half, quarter and
4209 8th notes, the eighth note is followed by 1 note head width. The The
4210 quarter note is followed by 2 NHW, the half by 3 NHW, etc.
4211 @lilypond[fragment, verbatim, relative=1]
4212  c2 c4. c8 c4. c8 c4. c8 c8 c8 c4 c4 c4
4213 @end lilypond
4214
4215 These two amounts of space are @code{shortest-duration-space}
4216 @code{spacing-increment}, grob properties of
4217 @internalsref{SpacingSpanner}. Normally @code{spacing-increment} is
4218 set to 1.2, which is the width of a note head, and
4219 @code{shortest-duration-space} is set to 2.0, meaning that the
4220 shortest note gets 2 noteheads of space. For normal notes, this space
4221 is always counted from the left edge of the symbol, so the short notes
4222 in a score is generally followed by one note head width of space.
4223
4224 If one would follow the above procedure exactly, then adding a single
4225 32th note to a score that uses 8th and 16th notes, would widen up the
4226 entire score a lot. The shortest note is no longer a 16th, but a 64th,
4227 thus adding 2 noteheads of space to every note. To prevent this, the
4228 shortest duration for spacing is not the shortest note in the score,
4229 but the most commonly found shortest note.  Notes that are even
4230 shorter this are followed by a space that is proportonial to their
4231 duration relative to the common shortest note.  So if we were to add
4232 only a few 16th notes to the example above, they would be followed by
4233 half a NHW:
4234
4235 @lilypond[fragment, verbatim, relative=1]
4236  c2 c4. c8 c4. [c16 c] c4. c8 c8 c8 c4 c4 c4
4237 @end lilypond
4238
4239 The most common shortest duration is determined as follows: in every
4240 measure, the shortest duration is determined. The most common short
4241 duration, is taken as the basis for the spacing, with the stipulation
4242 that this shortest duration should always be equal to or shorter than
4243 1/8th note. The shortest duration is printed when you run lilypond
4244 with @code{--verbose}.  These durations may also be customized. If you
4245 set the @code{common-shortest-duration} in
4246 @internalsref{SpacingSpanner}, then this sets the base duration for
4247 spacing. The maximum duration for this base (normally 1/8th), is set
4248 through @code{base-shortest-duration}.
4249
4250 @cindex @code{common-shortest-duration}
4251 @cindex @code{base-shortest-duration}
4252 @cindex @code{stem-spacing-correction}
4253 @cindex @code{spacing}
4254
4255 In the introduction it was explained that stem directions influence
4256 spacing. This is controlled with @code{stem-spacing-correction} in
4257 @internalsref{NoteSpacing}. The @code{StaffSpacing} grob contains the
4258 same property for controlling the stem/barline spacing. In the
4259 following example shows these corrections, once with default settings,
4260 and once with exaggerated corrections.  
4261
4262 @lilypond
4263     \score { \notes {
4264       c'4 e''4 e'4 b'4 |
4265       b'4 e''4 b'4 e''4|
4266       \property Staff.NoteSpacing \override #'stem-spacing-correction
4267       = #1.5
4268       \property Staff.StaffSpacing \override #'stem-spacing-correction
4269       = #1.5
4270       c'4 e''4 e'4 b'4 |
4271       b'4 e''4 b'4 e''4|      
4272     }
4273     \paper { linewidth = -1. } }
4274 @end lilypond
4275
4276
4277
4278 @refbugs
4279
4280 Spacing is determined on a score wide basis. If you have a score that
4281 changes its character (measured in durations) half way during the
4282 score, the part containing the longer durations will be spaced too
4283 widely.
4284
4285 Generating optically pleasing spacing is black magic. LilyPond tries
4286 to deal with a number of frequent cases. Here is an example that is
4287 not handled correctly, due to the combination of chord collisions and
4288 kneed stems.
4289
4290 @lilypond
4291 \score {
4292      \context PianoStaff \notes \transpose c''' <
4293      \context Staff = up { s1 }
4294      \context Staff = down { [c8 c \translator Staff=up <c d> c 
4295 \translator Staff=down c c c] }
4296      >
4297      \paper { linewidth = -1 }
4298 }
4299 @end lilypond
4300
4301
4302 @c .  {Font size}
4303 @node Font Size
4304 @subsection Font size
4305 @cindex font size, setting
4306 @cindex staff size, setting
4307 @cindex @code{paper} file
4308
4309 The Feta font provides musical symbols at seven different sizes.
4310 These fonts are 11 point, 13 point, 16 point, 19 pt, 20 point, 23
4311 point, and 26 point.  The point size of a font is the height of the
4312 five lines in a staff when displayed in the font.
4313
4314 Definitions for these sizes are the files @file{paperSZ.ly}, where
4315 @code{SZ} is one of 11, 13, 16, 19, 20, 23 and 26.  If you include any
4316 of these files, the identifiers @code{paperEleven},
4317 @code{paperThirteen}, @code{paperSixteen}, @code{paperNineteen},
4318 @code{paperTwenty}, @code{paperTwentythree}, and @code{paperTwentysix}
4319 are defined respectively.  The default @code{\paper} block is also
4320 set. These files should be imported at toplevel, i.e.
4321 @example
4322         \include "paper26.ly"
4323         \score @{  ... @}
4324 @end example
4325
4326 The font definitions are generated using a Scheme function. For more
4327 details, see the file @file{scm/font.scm}.
4328
4329
4330 @c .  {Line break}
4331 @node Line breaking
4332 @subsection Line breaking
4333
4334 @cindex line breaks
4335 @cindex breaking lines
4336
4337 Line breaks are normally computed automatically. They are chosen such
4338 that it looks neither cramped nor loose, and that consecutive lines have
4339 similar density.
4340
4341 Occasionally you might want to override the automatic breaks; you can
4342 do this by specifying @code{\break}. This will force a line break at
4343 this point.  Line breaks can only occur at places where there are bar
4344 lines.  If you want to have a line break where there is no bar line,
4345 you can force an invisible bar line by entering @code{\bar
4346 ""}. Similarly, @code{\noBreak} forbids a line break at a certain
4347 point.
4348
4349 If you want linebreaks at regular intervals, you can use the following:
4350 @example
4351 <  \repeat 7 unfold @{ s1 * 4 \break  @}
4352    @emph{real music}
4353
4354 @end  example
4355 This makes the following 28 measures (assuming 4/4 time) be broken every
4356 4 measures.
4357
4358 @node Page layout
4359 @subsection Page layout
4360
4361 @cindex page breaks
4362 @cindex breaking pages
4363
4364 @cindex @code{indent}
4365 @cindex @code{linewidth}
4366
4367 The most basic settings influencing the spacing are @code{linewidth}
4368 and @code{indent}, both set in the @code{\paper} block.  They control
4369 the indentation of the first line of music, and the lengths of the
4370 lines.  If @code{linewidth} set to a negative value, a single
4371 unjustified line is produced.  A similar effect for scores that are
4372 longer than one line, can be produced by setting @code{raggedright} to
4373 true in the @code{\paper} block.
4374
4375 @cindex page layout
4376
4377 The page layout process happens outside lilypond. Ly2dvi sets page
4378 layout instructions. Ly2dvi responds to the following variables in the
4379 @code{\paper} block.  The variable @code{textheight} sets the total
4380 height of the music on each page.  The spacing between systems is
4381 controlled with @code{interscoreline}, its default is 16pt.
4382 The distance between the score lines will stretch in order to fill the
4383 full page @code{interscorelinefill} is set to a positive number.  In
4384 that case @code{interscoreline} specifies the minimum spacing.
4385
4386 @cindex @code{textheight}
4387 @cindex @code{interscoreline}
4388 @cindex @code{interscorelinefill}
4389
4390 Page breaks are normally computed by @TeX{}, so they are not under
4391 direct control of LilyPond.  However, you can insert a commands into
4392 the @file{.tex} output to instruct @TeX{} where to break pages. You
4393 can insert a @code{\newpage} from within lilypond. This is done by
4394 setting the @code{between-systems-strings} on the
4395 @internalsref{NonMusicalPaperColumn} where the system is broken.
4396
4397 @cindex paper size
4398 @cindex page size
4399 @cindex @code{papersize}
4400
4401 To change the paper size, you must first set the
4402 @code{papersize} paper variable variable.  Set it to
4403 the strings @code{a4}, @code{letter}, or @code{legal}.  After this
4404 specification, you must set the font as described above.  If you want
4405 the default font, then use the 20 point font.
4406
4407 @example
4408         \paper@{ papersize = "a4" @}
4409         \include "paper16.ly"
4410 @end example
4411
4412 The file @code{paper16.ly}  will now include a file named @file{a4.ly}, which
4413 will set the paper variables @code{hsize} and @code{vsize} (used by
4414 Lilypond and @code{ly2dvi})
4415
4416
4417
4418
4419 @c . {Sound}
4420 @node Sound
4421 @section Sound
4422 @cindex Sound
4423
4424 LilyPond can produce MIDI output.  The performance lacks lots of
4425 interesting effects, such as swing, articulation, slurring, etc., but it
4426 is good enough for proof-hearing the music you have entered.  Ties,
4427 dynamics and tempo changes are interpreted.
4428
4429 Dynamic marks, crescendi and decrescendi translate into MIDI volume
4430 levels.  Dynamic marks translate to a fixed fraction of the available
4431 MIDI volume range, crescendi and decrescendi make the the volume vary
4432 linearly between their two extremities.  The fractions be adjusted by
4433 overriding the @code{absolute-volume-alist} defined in
4434 @file{scm/midi.scm}.
4435
4436 For each type of musical instrument (that MIDI supports), a volume range
4437 can be defined.  This gives you basic equalizer control, which can
4438 enhance the quality of the MIDI output remarkably.  You can add
4439 instruments and ranges or change the default settings by overriding the
4440 @code{instrument-equalizer-alist} defined in @file{scm/midi.scm}.
4441
4442 Both loudness controls are combined to produce the final  MIDI volume. 
4443
4444
4445
4446 @menu
4447 * MIDI block::                  
4448 * MIDI instrument names::       
4449 @end menu
4450
4451 @c .  {MIDI block}
4452 @node MIDI block
4453 @subsection MIDI block
4454 @cindex MIDI block
4455
4456
4457 The MIDI block is analogous to the paper block, but it is somewhat
4458 simpler.  The @code{\midi} block can contain:
4459 @cindex MIDI block
4460
4461 @itemize @bullet
4462   @item  a @code{\tempo} definition
4463   @item  context definitions
4464 @end itemize
4465
4466 Assignments in the @code{\midi} block are not allowed.
4467
4468
4469
4470 @cindex context definition
4471
4472 Context definitions follow precisely the same syntax as within the
4473 \paper block.  Translation modules for sound are called performers.
4474 The contexts for MIDI output are defined in @file{ly/performer-init.ly}.
4475
4476
4477 @node MIDI instrument names
4478 @subsection MIDI instrument names
4479
4480 @cindex instrument names
4481 @cindex @code{Staff.midiInstrument}
4482 @cindex @code{Staff.instrument}
4483
4484 The MIDI instrument name is set by the @code{Staff.midiInstrument}
4485 property or, if that property is not set, the @code{Staff.instrument}
4486 property.  The instrument name should be chosen from the list in
4487 @ref{MIDI instruments}.
4488
4489 @refbugs
4490
4491 If the selected string does not exactly match, then LilyPond uses the
4492 default (Grand Piano). It is not possible to select an instrument by
4493 number.
4494
4495