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