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