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