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