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