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