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