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