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