]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/refman.itely
patch::: 1.3.129.jcn3
[lilypond.git] / Documentation / user / refman.itely
1
2 @c Note:
3 @c
4 @c A menu is needed before every deeper *section nesting of @nodes
5 @c Run M-x texinfo-all-menus-update
6 @c to automagically fill in these menus
7 @c before saving changes
8
9
10 @ignore
11  TODO:
12
13    fix all FIXMEs
14
15    Rhythm staff (clef, x-notehead)
16
17    markup text
18
19    postscript, scheme output?
20
21    (links to?) using/existance of ly2dvi, lilypond-book
22
23 @end ignore
24
25
26 @c .{Reference Manual}
27
28 @node Reference Manual
29 @chapter Reference Manual
30
31 This document describes GNU LilyPond and its input format. This document
32 has been revised for LilyPond 1.3.125
33
34
35
36 @menu
37 * Overview::                    
38 * Modifying music::             
39 * Repeats::                     
40 * Note entry::                  
41 * Music notation::              
42 * Polyphony::                   
43 * Spanners::                    
44 * Piano music::                 
45 * Lyrics::                      
46 * Chords::                      
47 * Writing parts::               
48 * Custodes::                    
49 * Page layout::                 
50 * Sound::                       
51 * Music entry::                 
52 * Engravers::                   
53 * Syntactic details::           
54 * Unsorted::                    
55 @end menu
56
57 @c . {Overview}
58 @node Overview
59 @section Overview
60
61
62 The purpose of LilyPond is explained informally by the term `music
63 typesetter'.  This is not a fully correct name: not only does the
64 program print musical symbols, it also makes esthetic decisions.  All
65 symbols and their placement is @emph{generated} from a high-level
66 musical description.  In other words, LilyPond would be best described
67 by `music compiler' or `music to notation compiler'.
68
69 Internally, LilyPond is written in a mixture of Scheme and C++. Most of
70 the algorithms and low-level routines are written in C++, but these low
71 level components are glued together using Scheme data
72 structures. LilyPond is linked to GUILE, GNU's Scheme library for
73 extension.
74
75 When lilypond is run to typeset sheet music, the following happens:
76
77 @itemize @bullet
78 @item GUILE Initialization: various scheme files are read
79 @item parsing: first standard .ly initialization  files are read, and
80 then the user @file{.ly} file is read.
81 @item interpretation: the music in the file is processed "in playing
82 order", i.e. in the same order as your eyes scan sheet music, and in the
83 same order that you hear the notes play.
84
85 @item typesetting:
86 in this step, the results of the interpretation, a typesetting
87 specification, is solved.
88
89 @item the visible results ("virtual ink") is written to the output file.
90 @end itemize
91
92 These stages, involve data of a specific type: during parsing,
93 @strong{Music} objects are created.  During the interpretation,
94 @strong{context} is constructed, and with this context af network of
95 @strong{graphical objects} (``grobs'') is created. The grobs contain
96 unknown variables, and the network forms a set of equations. After
97 solving the equations and filling in these variables, the printed output
98 (in the form of @strong{molecules}) is written to an output file.
99
100 These threemanship of tasks (parsing, translating, typesetting) and
101 data-structures (music, context, graphical objects) permeates the entire
102 design of the program.  This manual is ordered in terms of user
103 tasks. With each concept will be explained to which of the three parts
104 it belongs.
105
106 LilyPond input can be classified into three types:
107 @itemize @bullet
108   @item musical expressions: a musical expression is some combination of
109 rest, notes, lyrics
110   @item output definitions: recipes for translating those musical
111 expressions into performances (MIDI) or graphics (eg. PostScript).
112
113   @item declarations: by declaring and naming musical expressions, you
114 can enter and edit them in manageable chunks.
115 @end itemize
116
117
118
119 @c . {Modifying music}
120 @node Modifying music
121 @section Modifying music
122 @cindex Modifying music
123
124 FIXME: more verbose titling:
125 music expressions?
126 Repeat?
127 Repeated music?
128 Repeating music expressions?
129
130 @menu
131 * Apply::                       
132 @end menu
133
134 @c .  {Apply}
135 @node Apply
136 @subsection Apply
137 @cindex Apply
138 Apply allows a Scheme-function to operate directly on the internal
139 representation of music.
140 @example
141         \apply #@var{func} @var{music}
142 @end example
143 The function takes two arguments, being a function and an musical
144 argument for that function. The function should return a music
145 expression.
146
147 This example replaces the text string of a script. It also shows a dump
148 of the music it processes.
149 @lilypond[verbatim]
150 #(define (testfunc x)
151         (if (equal? (ly-get-mus-property x 'text) "foo")
152                 (ly-set-mus-property x 'text "bar"))
153         ;; recurse
154         (ly-set-mus-property x 'elements
155           (map testfunc (ly-get-mus-property x 'elements)))
156         (display x)
157         x        
158 )
159 \score { \notes
160   \apply #testfunc { c4_"foo" }
161
162 @end lilypond
163
164 For more information on what is possible, see the @ref{Tricks} and the
165 automatically generated documentation.
166
167
168
169 @c .  {Repeats}
170 @node Repeats
171 @section Repeats
172
173
174 @cindex repeats
175 @cindex @code{\repeat}
176
177 In order to specify repeats, use the @code{\repeat}
178 keyword.  Since repeats look and sound differently when played or
179 printed, there are a few different variants of repeats.
180
181 @table @asis
182 @item unfolded  
183 Repeated music is fully written (played) out.  Useful for MIDI
184 output.
185
186 @item volta  
187 This is the normal notation: Repeats are not written out, but
188 alternative endings (voltas) are printed, left to right.
189
190 @item folded  
191 Alternative endings are written stacked.  Which is unfortunately not
192 practical for anything right now.
193
194 @item tremolo
195 Make tremolo beams.
196 @end table  
197
198 @menu
199 * Repeat syntax::               
200 * Manual repeat commands::      
201 * Tremolo repeats::             
202 * Tremolo subdivision::         
203 @end menu
204
205 @node Repeat syntax
206 @subsection Repeat syntax
207
208 The syntax for repeats is
209
210 @example
211   \repeat @var{variant} @var{repeatcount} @var{repeatbody}
212 @end example
213
214 If you have alternative endings, you may add
215
216 @cindex @code{\alternative}
217 @example
218  \alternative @code{@{} @var{alternative1}
219             @var{alternative2}
220             @var{alternative3} @dots{} @code{@}}
221 @end example
222
223 where each @var{alternative} is a Music expression.
224
225 Normal notation repeats are used like this:
226
227 @quotation
228
229 @lilypond[fragment,verbatim]
230   c'1
231   \repeat volta 2 { c'4 d' e' f' }
232   \repeat volta 2 { f' e' d' c' }
233 @end lilypond
234 @end quotation
235
236 With alternative endings:
237
238 @quotation
239
240 @lilypond[fragment,verbatim]
241   c'1
242   \repeat volta 2 {c'4 d' e' f'} 
243   \alternative { {d'2 d'} {f' f} }
244 @end lilypond
245 @end quotation
246
247 Folded repeats look like this:@footnote{Folded repeats offer little
248 more over simultaneous music.  However, it is to be expected that
249 more functionality -- especially for the MIDI backend -- will be
250 implemented at some point in the future.}
251
252 @quotation
253
254 @lilypond[fragment,verbatim]
255   c'1
256   \repeat fold 2 {c'4 d' e' f'} 
257   \alternative { {d'2 d'} {f' f} }
258
259 @end lilypond
260 @end quotation
261
262
263 If you don't give enough alternatives for all of the repeats, then
264 the first alternative is assumed to be repeated often enough to equal
265 the specified number of repeats.
266
267 @quotation
268 @lilypond[fragment,verbatim]
269 \context Staff {
270   \relative c' {
271     \partial 4;
272     \repeat volta 3 { e | c2 d2 | e2 f2 | }
273     \alternative { { g4 g g } { a | a a a a | b2. } }
274   }
275 }
276
277 @end lilypond
278 @end quotation
279
280
281 As you can see, LilyPond doesn't remember the timing information, nor
282 are slurs or ties repeated, so you have to reset timing information
283 after a repeat, eg using bar-checks, @code{Score.measurePosition} or
284 @code{\partial}. We hope to fix this after 1.4.
285
286 It is possible to nest @code{\repeat}, although it probably is only
287 meaningful for unfolded repeats.
288
289 @node Manual repeat commands
290 @subsection Manual repeat commands
291
292 @cindex @code{repeatCommands}
293
294 The property @code{repeatCommands} can be used to control the layout of
295 repeats. Its value is a Scheme list of repeat commands, where each repeat
296 command can be
297
298 @table @code
299 @item 'start-repeat
300  Print a |: bar line
301 @item 'stop-repeat
302  Print a :| bar line
303 @item (volta . @var{text})
304   Print a volta bracket saying @var{text}.
305 @item (volta . #f)
306   Stop a running volta bracket
307 @end table
308
309 @lilypond[verbatim, fragment]
310  c''4
311     \property Score.repeatCommands = #'((volta "93") end-repeat)
312  c4 c4
313     \property Score.repeatCommands = #'((volta #f))
314  c4 c4
315 @end lilypond
316
317
318 @node Tremolo repeats
319 @subsection Tremolo repeats
320 @cindex tremolo beams
321
322 To place tremolo marks between notes, use @code{\repeat} with tremolo
323 style.  
324 @lilypond[verbatim,center]
325 \score { 
326   \context Voice \notes\relative c' {
327     \repeat "tremolo" 8 { c16 d16 }
328     \repeat "tremolo" 4 { c16 d16 }    
329     \repeat "tremolo" 2 { c16 d16 }
330     \repeat "tremolo" 4 c16
331   }
332   \paper {
333     linewidth = 40*\staffspace;
334   }  
335 }
336 @end lilypond
337
338 @node Tremolo subdivision
339 @subsection Tremolo subdivision
340 @cindex tremolo marks
341 @cindex @code{tremoloFlags}
342
343 Tremolo marks can be printed on a single note by adding
344 `@code{:}[@var{length}]' after the note.  The length must be at least 8.
345 A @var{length} value of 8 gives one line across the note stem.  If the
346 length is omitted, then the last value is used, or the value of the
347 @code{tremoloFlags} property if there was no last value.
348
349 @lilypond[verbatim,fragment,center]
350   c'2:8 c':32
351 @end lilypond
352
353 Tremolos in this style do not carry over into the MIDI output.
354
355 Using this mechanism pays off when you entering many tremolos, since the
356 default argument saves a lot of typing.
357
358
359 @c . {Note entry}
360 @node Note entry
361 @section Note entry
362 @cindex Note entry
363
364 @menu
365 * Notes mode::                  
366 * Pitches::                     
367 * Defining pitch names::        
368 * Durations::                   
369 * Notes::                       
370 * Rests::                       
371 * Skip::                        
372 @end menu
373
374 @c .  {Notes mode}
375 @node Notes mode
376 @subsection Notes mode
377
378 @cindex note mode
379
380 @cindex @code{\notes}
381 Note mode is introduced by the keyword
382 @code{\notes}.  In Note mode, words can only
383 contain alphabetic characters.  If @code{word} is encountered,
384 LilyPond first checks for a notename of @code{word}.  If no
385 notename is found, then @code{word} is treated as a string.
386
387 Since combinations of numbers and dots are used for indicating
388 durations, it is not possible to enter real numbers in this mode.
389
390 @cindex Notes mode
391
392 @c .  {Pitches}
393 @node Pitches
394 @subsection Pitches
395
396 @cindex Pitch names
397 @cindex Note specification
398 @cindex pitches
399 @cindex entering notes
400
401 The verbose syntax for pitch specification is
402
403 @cindex @code{\pitch}
404 @example
405   \pitch @var{scmpitch}
406 @end example
407
408 @var{scmpitch} is a pitch scheme object, see @ref{Pitch data type}.
409
410 In Note and Chord mode, pitches may be designated by names.  The default
411 names are the Dutch note names.  The notes are specified by the letters
412 @code{c} through @code{b}, where @code{c} is an octave below middle C
413 and the letters span the octave above that C.  In Dutch,
414 @cindex note names, Dutch
415 a sharp is formed by adding @code{-is} to the end of a pitch name.  A
416 flat is formed by adding @code{-es}. Double sharps and double flats are
417 obtained by adding @code{-isis} or @code{-eses}.  @code{aes} and
418 @code{ees} are contracted to @code{as} and @code{es} in Dutch, but both
419 forms will be accepted.
420
421 LilyPond has predefined sets of notenames for various other languages.
422 To use them, simply include the language specific init file.  For
423 example: @code{\include "english.ly"}.  The available language files and
424 the names they define are:
425
426 @example 
427                         Note Names               sharp       flat
428 nederlands.ly  c   d   e   f   g   a   bes b   -is         -es
429 english.ly     c   d   e   f   g   a   bf  b   -s/-sharp   -f/-flat
430 deutsch.ly     c   d   e   f   g   a   b   h   -is         -es
431 norsk.ly       c   d   e   f   g   a   b   h   -iss/-is    -ess/-es
432 svenska.ly     c   d   e   f   g   a   b   h   -iss        -ess
433 italiano.ly    do  re  mi  fa  sol la  sib si  -d          -b
434 catalan.ly     do  re  mi  fa  sol la  sib si  -d/-s       -b 
435 @end example 
436
437 @cindex @code{'}
438 @cindex @code{,}
439
440
441
442
443 The optional octave specification takes the form of a series of
444 single quote (`@code{'}') characters or a series of comma
445 (`@code{,}') characters.  Each @code{'} raises the pitch by one
446 octave; each @code{,} lowers the pitch by an octave.
447
448 @lilypond[fragment,verbatim,center]
449   c' d' e' f' g' a' b' c''
450 @end lilypond
451
452 @lilypond[fragment,verbatim,center]
453   cis' dis' eis' fis' gis' ais' bis'
454 @end lilypond
455
456 @lilypond[fragment,verbatim,center]
457   ces' des' es' fes' ges' as' bes'
458 @end lilypond
459
460 @lilypond[fragment,verbatim,center]
461   cisis' eisis' gisis' aisis' beses'
462 @end lilypond
463
464 @lilypond[fragment,verbatim,center]
465   ceses' eses' geses' ases' beses'
466 @end lilypond
467
468
469 @c .  {Defining pitch names}
470 @node Defining pitch names
471 @subsection Defining pitch names
472
473 @cindex defining pitch names
474 @cindex pitch names, defining 
475
476 Note names and chord modifiers can be customised for nationalities.  The
477 syntax is as follows.
478
479 @cindex @code{\pitchnames}
480 @cindex @code{\chordmodifiers}
481 @example
482    \pitchnames @var{scheme-alist}
483    \chordmodifiers @var{scheme-alist}
484 @end example
485
486 See @file{ly/nederlands.ly} and @file{ly/chord-modifiers.ly} for
487 specific examples how to do this.  Some national note names have been
488 provided, among others: Norwegian, Swedish, German, Italian, Catalan,
489 French, Dutch and English.
490
491
492 @c .  {Durations}
493 @node Durations
494 @subsection Durations
495
496
497 @cindex duration
498 @cindex @code{\duration}
499
500 The syntax for an verbose duration specification is
501 @example
502  \duration @var{scmduration}
503 @end example
504
505 In Note, Chord, and Lyrics mode, durations may be designated by numbers
506 and dots: durations are entered as their reciprocal values.  For notes
507 longer than a whole note, use identifiers.
508
509 @quotation
510
511 @example 
512 c'\longa c'\breve  
513 c'1 c'2 c'4 c'8 c'16 c'32 c'64 c'64 
514 r\longa r\breve  
515 r1 r2 r4 r8 r16 r32 r64 r64 
516 @end example 
517
518
519 @lilypond[]
520 \score {
521   \notes \relative c'' {
522     a\longa a\breve  \autoBeamOff
523     a1 a2 a4 a8 a16 a32 a64 a64 
524     r\longa r\breve  
525     r1 r2 r4 r8 r16 r32 r64 r64 
526   }
527   \paper {
528     \translator {
529       \StaffContext
530         \remove "Clef_engraver";
531         \remove "Staff_symbol_engraver";
532         \remove "Time_signature_engraver";
533         \consists "Pitch_squash_engraver";
534     }
535   }
536 }
537 @end lilypond
538 @end quotation
539
540 As you  can see, the longa is not printed. To get a longa note head, you
541 have to use a different style of note heads. See [TODO].
542
543 If the duration is omitted then it is set equal to the previous duration
544 entered.  At the start of parsing there is no previous duration, so then
545 a quarter note is assumed.  The duration can be followed by a dot
546 (`@code{.}')  to obtain dotted note lengths.
547 @cindex @code{.}
548
549 @lilypond[fragment,verbatim,center]
550   a'4. b'4.
551 @end lilypond
552 @cindex @code{r}
553 @cindex @code{s}
554
555 You can alter the length of duration by writing `@code{*}@var{fraction}'
556 after it.  This will not affect the appearance of note heads or rests.
557
558 @c . {Notes}
559 @node Notes
560 @subsection Notes
561
562 A note specification has the form
563
564 @example
565   @var{pitch}[@var{octavespec}][!][?][@var{duration}]
566 @end example
567
568
569 LilyPond will determine what accidentals to typeset depending on the key
570 and context, so alteration refer to what note is heard, not to whether
571 accidentals are printed.  A reminder accidental
572 @cindex reminder accidental
573 @cindex @code{?}
574 can be forced by adding an exclamation mark @code{!} after the pitch.
575 A cautionary accidental,
576 @cindex cautionary accidental
577
578 i.e., an accidental within parentheses can be obtained by adding the
579 question mark `@code{?}' after the pitch.
580
581 @lilypond[fragment,verbatim,center]
582   cis' d' e' cis'  c'? d' e' c'!
583 @end lilypond
584
585
586 @c .  {Rests}
587 @node  Rests
588 @subsection Rests
589 @cindex Rests
590
591 Rests are entered like notes, with note name `@code{r}'.
592 There is also a note name
593 `@code{s}', which produces a space of the specified
594 duration.
595
596
597 @c .  {Skip}
598 @node Skip
599 @subsection Skip
600 @cindex Skip
601
602
603 @example
604   \skip @var{duration} @code{;}
605 @end example
606 @cindex @code{\skip}
607
608 Skips the amount of time specified by @var{duration}.  If no other
609 music is played, a gap will be left for the skipped time with no
610 notes printed.  It works in Note Mode or Lyrics Mode.  In Note mode,
611 this has the same effect as the spacer rest.
612
613
614
615 @c . {Music notation}
616 @node Music notation
617 @section Music notation
618 @cindex Music notation
619 @menu
620 * Key::                         
621 * Time signature::              
622 @end menu
623
624 @c .  {Key}
625 @node Key
626 @subsection Key
627 @cindex Key
628
629 @cindex @code{\key}
630
631 @example
632   @code{\key} @var{pitch} @var{type} @code{;}
633 @end example
634 @cindex @code{\minor}
635 @cindex @code{\major}
636 @cindex @code{\minor}
637 @cindex @code{\ionian}
638 @cindex @code{\locrian}
639 @cindex @code{\aeolian}
640 @cindex @code{\mixolydian}
641 @cindex @code{\lydian}
642 @cindex @code{\phrygian}
643 @cindex @code{\dorian}
644
645 Change the key signature.  @var{type} should be @code{\major} or
646 @code{\minor} to get @var{pitch}-major or @var{pitch}-minor,
647 respectively.  The second argument is optional; the default is major
648 keys.  The @var{\context} argument can also be given as an integer,
649 which tells the number of semitones that should be added to the pitch
650 given in the subsequent @code{\key} commands to get the corresponding
651 major key, e.g., @code{\minor} is defined as 3.  The standard mode names
652 @code{\ionian}, @code{\locrian}, @code{\aeolian}, @code{\mixolydian},
653 @code{\lydian}, @code{\phrygian}, and @code{\dorian} are also defined.
654
655 This command sets @code{Staff.keySignature}. 
656
657 @cindex @code{keySignature}
658
659 @c .   {Clef changes}
660 @subsubsection Clef changes
661 @cindex @code{\clef}
662 @example
663   \clef @var{clefname} @code{;}
664 @end example
665
666 Short-cut for
667
668 @example
669   \property Staff.clefGlyph = @var{symbol associated with clefname} 
670   \property Staff.clefPosition = @var{clef Y-position for clefname}
671   \property Staff.clefOctavation = @var{extra pitch of clefname}
672 @end example
673
674 Supported clef-names include 
675
676 @itemize @bullet
677 @item treble, violin, G, G2: G clef on 2nd line
678 @item french: G clef on 1st line
679 @item soprano: C clef on 1st line
680 @item mezzosoprano: C clef on 2nd line
681 @item alto: C clef on 3rd line
682 @item tenor: C clef on 4th line
683 @item baritone: C clef on 5th line
684 @item varbaritone: F clef on 3rd line
685 @item bass, F: F clef on 4th line
686 @item subbass: F clef on 5th line
687 @item percussion: percussion clef
688 @end itemize
689
690 [todo: ancient clefs]
691
692 Supported associated symbols (for Staff.clefGlyph) are:
693
694 @itemize @bullet
695 @item clefs-C: modern style C clef
696 @item clefs-F: modern style F clef
697 @item clefs-G: modern style G clef
698 @item clefs-vaticana_do: Editio Vaticana style do clef
699 @item clefs-vaticana_fa: Editio Vaticana style fa clef
700 @item clefs-medicaea_do: Editio Medicaea style do clef
701 @item clefs-medicaea_fa: Editio Medicaea style fa clef
702 @item clefs-mensural1_c: modern style mensural C clef
703 @item clefs-mensural2_c: historic style small mensural C clef
704 @item clefs-mensural3_c: historic style big mensural C clef
705 @item clefs-mensural1_f: historic style traditional mensural F clef
706 @item clefs-mensural2_f: historic style new mensural F clef
707 @item clefs-mensural_g: historic style mensural G clef
708 @item clefs-hufnagel_do: historic style hufnagel do clef
709 @item clefs-hufnagel_fa: historic style hufnagel fa clef
710 @item clefs-hufnagel_do_fa: historic style hufnagel combined do/fa clef
711 @item clefs-percussion: modern style percussion clef
712 @end itemize
713
714 @emph{Modern style} means "as is typeset in current editions".
715 @emph{Historic style} means "as was typeset or written in contemporary
716 historic editions".  @emph{Editio XXX style} means "as is/was printed in
717 Editio XXX".
718
719 @c .  {Time signature}
720 @node Time signature
721 @subsection Time signature
722 @cindex Time signature
723 @cindex meter
724 @cindex @code{\time}
725
726 @example
727   \time @var{numerator}@code{/}@var{denominator} @code{;}
728 @end example
729
730 A short-cut for doing
731 @example
732      \property Score.timeSignatureFraction = #'(@var{numerator} . @var{denominator})
733 @end example
734
735 See the documentation of @code{timeSignatureFraction}
736
737
738 @c .   {Partial}
739 @subsubsection Partial
740 @cindex Partial
741 @cindex anacrusis
742 @cindex upstep
743 @cindex partial measure
744 @cindex measure, partial
745 @cindex shorten measures
746 @cindex @code{\partial}
747 @example
748   \partial @var{duration} @code{;}
749 @end example
750
751 Short cut for 
752
753 @example
754   \property Score.measurePosition = @var{length of duration}
755 @end example
756 @cindex @code{|}
757
758 See the documentation of @code{measurePosition}.
759
760
761 @c .   {Polyphony}
762 @node Polyphony
763 @section Polyphony
764 @cindex Polyphony
765
766 [todo : collisiosn, rest-collisinos, voiceX identifiers, how to
767 which  contexts to instantiate.]
768
769
770 @table @code
771 @cindex @code{\shiftOff}  
772   @item @code{\shiftOff}
773     Disable horizontal shifting of note heads that collide. 
774
775 @cindex @code{\shiftOn}  
776   @item @code{\shiftOn}
777     Enable note heads that collide with other note heads to be
778     shifted horiztonally. Also @code{\shiftOnn} and @code{\shiftOnnn}
779 set different shift values.
780
781 @cindex @code{\stemBoth}  
782   @item @code{\stemBoth}
783     Allow stems, beams, and slurs to point either upwards or
784     downwards, decided automatically by LilyPond.
785
786 @cindex @code{\stemDown}  
787   @item @code{\stemDown}
788     Force stems, beams, and slurs to point down.
789
790 @cindex @code{\stemUp}  
791   @item @code{\stemUp}
792     Force stems, beams and slurs to point up.
793 @end table
794
795 @c .  {Spanners}
796 @node Spanners
797 @section Spanners
798 @cindex Spanners
799
800 @menu
801 * Beam::                        
802 * Slur ::                       
803 * Phrasing slur::               
804 * Ornaments::                   
805 * Grace notes::                 
806 * Bar check::                   
807 @end menu
808
809
810
811 @c .   {Beam}
812 @node Beam
813 @subsection Beams
814
815 @cindex beams
816
817 @c .    {Automatic beams}
818 @subsubsection Automatic beams
819
820
821 @cindex automatic beam generation
822 @cindex autobeam
823 @cindex @code{Voice.noAutoBeaming}
824
825 LilyPond will group flagged notes and generate beams autmatically, where
826 appropriate.
827
828 This feature can be disabled by setting the @code{Voice.noAutoBeaming}
829 property to true, which you may find necessary for the melody that goes
830 with lyrics, eg.  Automatic beaming can easily be overridden for
831 specific cases by specifying explicit beams. This is discussed in the
832 next subsubsection.
833
834
835
836 @cindex @code{Voice.autoBeamSettings}
837 @cindex @code{(end * * * *)}
838 @cindex @code{(begin * * * *)}
839
840 A large number of Voice properties are used to decide how to generate
841 beams.  Their default values appear in @file{scm/auto-beam.scm}.  In
842 general, beams can begin anywhere, but their ending location is
843 significant.  Beams can end on a beat, or at durations specified by the
844 properties in @code{Voice.autoBeamSettings}.  To end beams every quarter
845 note, for example, you could set the property @code{(end * * * *)} to
846 @code{(make-moment 1 4)}.  To end beams at every three eighth notes you
847 would set it to @code{(make-moment 1 8)}.  The same syntax can be used
848 to specify beam starting points using @code{(begin * * * *)}, eg:
849 @quotation
850 @example
851 \property Voice.autoBeamSettings \override
852     #'(end * * * *) = #(make-moment 1 4)
853 \property Voice.autoBeamSettings \override
854     #'(begin * * * *) = #(make-moment 1 8)
855 @end example
856 @end quotation
857
858 To allow different settings for different time signatures, instead of
859 the first two asterisks @code{* *} you can specify a time signature; use
860 @code{(end N M * *)} to restrict the definition to
861 `@var{N}@code{/}@var{M}' time.  For example, to specify beams ending
862 only for 6/8 time you would use the property @code{(end 6 8 * *)}.
863
864 To allow different endings for notes of different durations, instead of
865 th last two asterisks you can specify a duration; use @code{(end * * N
866 M)} to restrict the definition to beams that contain notes of
867 `@var{N}@code{/}@var{M}' duration.
868
869 For example, to specify beam endings for beams that contain 32nd notes,
870 you would use @code{(end * * 1 32)}.
871
872
873
874 @c .    {Manual beams}
875 @cindex Automatic beams
876 @subsubsection Manual beams
877 @cindex beams, manual
878 @cindex @code{]}
879 @cindex @code{[}
880
881 In some cases it may be necessary to override LilyPond's automatic
882 beaming algorithm.  For example, the auto beamer will not beam over
883 rests or bar lines, so if you want that, specify the begin and end point
884 manually using @code{[} and @code{]}:
885
886 @quotation
887 @lilypond[fragment,relative,verbatim]
888   \context Staff {
889     r4 [r8 g'' a r8] r8 [g | a] r8
890   }
891 @end lilypond
892
893
894 @cindex @code{stemLeftBeamCount}
895
896 If you have specific wishes for the number of beams, you can fully
897 control the number of beams through the properties
898 y@code{Voice.stemLeftBeamCount} and @code{Voice.stemRightBeamCount}.
899
900 @lilypond[fragment,relative,verbatim]
901   \context Staff {
902     [f'8 r16 f g a]
903     [f8 r16 \property Voice.stemLeftBeamCount = #1 f g a]
904   }
905 @end lilypond
906 @end quotation
907 @cindex @code{stemRightBeamCount}
908
909
910 @c .    {Adjusting beams}
911 @unnumberedsubsubsec Adjusting beams
912 @cindex Adjusting beams
913
914 FIXME
915
916
917         
918
919 @c .   {Slur}
920 @node Slur 
921 @subsection Slur
922 @cindex slur
923
924 @menu
925 * Slur attachments::            
926 @end menu
927
928 A slur connects chords and is used to indicate legato.  Slurs avoid
929 crossing stems.  A slur is started with @code{(} and stopped with
930 @code{)}.  The starting @code{(} appears to the right of the first note
931 in the slur.  The terminal @code{)} appears to the left of the last note
932 in the slur.  This makes it possible to put a note in slurs from both
933 sides:
934
935 @lilypond[fragment,verbatim,center]
936   f'()g'()a' [a'8 b'(] a'4 g'2 )f'4
937 @end lilypond
938
939 @c .    {Adjusting slurs}
940 @unnumberedsubsubsec Adjusting slurs
941
942
943 @node Slur attachments
944 @subsubsection Slur attachments
945
946 The ending of a slur should whenever possible be attached to a note
947 head.  Only in some instances where beams are involved, LilyPond may
948 attach a slur to a stem end.  In some cases, you may want to override
949 LilyPond's decision, e.g., to attach the slur to the stem end.  This can
950 be done through @code{Voice.Slur}'s grob-property @code{attachment}:
951
952
953 @quotation
954 @lilypond[fragment,relative,verbatim]
955   \property Voice.Slur \set #'direction = #1
956   \property Voice.Stem \set #'length = #5.5
957   g''8(g)g4
958   \property Voice.Slur \set #'attachment = #'(stem . stem)
959   g8(g)g4
960 @end lilypond
961 @end quotation
962
963 Similarly, slurs can be attached to note heads even when beams are
964 involved:
965
966 @quotation
967 @lilypond[fragment,relative,verbatim]
968   \property Voice.Slur \set #'direction = #1
969   \property Voice.Slur \set #'attachment = #'(head . head)
970   g''16()g()g()g()d'()d()d()d
971 @end lilypond
972 @end quotation
973
974 If a slur would strike through a stem or beam, LilyPond will move the
975 slur away vertically (upward or downward).  In some cases, this may
976 cause ugly slurs that you may want to correct:
977
978 @quotation
979 @lilypond[fragment,relative,verbatim]
980   \property Voice.Stem \set #'direction = #1
981   \property Voice.Slur \set #'direction = #1
982   d'32( d'4 )d8..
983   \property Voice.Slur \set #'attachment = #'(stem . stem)
984   d,32( d'4 )d8..
985 @end lilypond
986 @end quotation
987
988 LilyPond will increase the curvature of a slur trying to stay free of
989 note heads and stems.  However, if the curvature would increase too much,
990 the slur will be reverted to its default shape.  This decision is based
991 on @code{Voice.Slur}'s grob-property @code{beautiful} value.  In some
992 cases, you may find ugly slurs beautiful, and tell LilyPond so by
993 increasing the @code{beautiful} value:
994
995 [hoe  gedefd?? wat betekent beautiful = X?]
996
997 @quotation
998 @lilypond[verbatim]
999 \score {
1000   \notes \context PianoStaff <
1001     \time 6/4;
1002     \context Staff=up { s1 * 6/4 }
1003     \context Staff=down <
1004       \clef bass;
1005       \autochange Staff \context Voice
1006         \notes \relative c {
1007           d,8( a' d f a d f d a f d )a
1008         }
1009     >
1010   >
1011   \paper {
1012     linewidth = -1.;
1013     \translator {
1014       \VoiceContext
1015       Slur \override #'beautiful = #5.0
1016       Slur \override #'direction = #1
1017       Stem \override #'direction = #-1
1018       autoBeamSettings \override #'(end * * * *)
1019         = #(make-moment 1 2)
1020     }
1021     \translator {
1022       \PianoStaffContext
1023       VerticalAlignment \override #'threshold = #'(5 . 5)
1024     }
1025   }
1026 }
1027 @end lilypond
1028 @end quotation
1029
1030 @cindex Adusting slurs
1031
1032
1033
1034 @c .   {Phrasing slur}
1035 @node Phrasing slur
1036 @subsection Phrasing slur
1037 @cindex phrasing slur
1038 @cindex phrasing mark
1039
1040 A phrasing slur (or phrasing mark) connects chords and is used to
1041 indicate a musical sentence.  Phrasing slurs avoid crossing stems.  A
1042 phrasing slur is started with @code{\(} and stopped with @code{\)}.  The
1043 starting @code{\(} appears to the right of the first note in the
1044 phrasing slur.  The terminal @code{\)} appears to the left of the last
1045 note in the phrasing slur.
1046
1047 @lilypond[fragment,verbatim,center,relative]
1048   \time 6/4; c''\((d)e f(e)\)d
1049 @end lilypond
1050
1051
1052 @c .   {Tie}
1053 @menu
1054 * Tie::                         
1055 * Tuplets::                     
1056 * Text spanner::                
1057 * Ottava::                      
1058 * Span requests::               
1059 @end menu
1060
1061 @node Tie
1062 @subsubsection Tie
1063
1064 @cindex Tie
1065 @cindex ties
1066 @cindex @code{~}
1067
1068 A tie connects two adjacent note heads of the same pitch.  When used
1069 with chords, it connects all of the note heads whose pitches match.
1070 Ties are indicated using the tilde symbol `@code{~}'.
1071 If you try to tie together chords which have no common pitches, a
1072 warning message will appear and no ties will be created.
1073
1074 @lilypond[fragment,verbatim,center]
1075   e' ~ e' <c' e' g'> ~ <c' e' g'>
1076 @end lilypond
1077
1078 [sparseTies]
1079
1080
1081 @c .   {Tuplets}
1082 @node Tuplets
1083 @subsubsection Tuplets
1084 @cindex Tuplets
1085 @cindex Times 
1086
1087 Tuplets are made out of a music expression by multiplying their duration
1088 with a fraction.
1089
1090 @cindex @code{\times}
1091 @example
1092   \times @var{fraction} @var{musicexpr}
1093 @end example
1094
1095 The duration of @var{musicexpr} will be multiplied by the fraction. 
1096 In print, the fraction's denominator will be printed over the notes,
1097 optionally with a bracket.  The most common tuplet is the triplet in
1098 which 3 notes have the length of 2, so the notes are 2/3 of
1099 their written length:
1100
1101 @lilypond[fragment,verbatim,center]
1102   g'4 \times 2/3 {c'4 c' c'} d'4 d'4
1103 @end lilypond
1104
1105 [todo: document tupletSpannerDuration]
1106
1107
1108
1109 @c .   {Text spanner}
1110 @node Text spanner
1111 @subsubsection Text spanner
1112 @cindex Text spanner
1113
1114 @c .   {Ottava}
1115 @node Ottava
1116 @subsubsection Ottava
1117 @cindex Ottava
1118 @unnumberedsubsubsec Ottava
1119
1120 [move to trick. Not a supported feature.]
1121
1122 @lilypond[fragment,relative,verbatim]
1123   a'''' b c a
1124   \property Voice.TextSpanner \set #'type = #'dotted-line
1125   \property Voice.TextSpanner \set #'edge-height = #'(0 . 1.5)
1126   \property Voice.TextSpanner \set #'edge-text = #'("8va " . "")
1127   \property Staff.centralCPosition = #-13
1128   a\spanrequest \start "text" b c a \spanrequest \stop "text"
1129 @end lilypond
1130
1131
1132
1133 @c .   {Span requests}
1134 @node Span requests
1135 @subsubsection Span requests
1136 @cindex Span requests
1137
1138 @cindex @code{\spanrequest}
1139
1140 @example
1141   \spanrequest @var{startstop} @var{type}
1142 @end example
1143 @cindex @code{\start}
1144 @cindex @code{\stop}
1145
1146 Define a spanning request. The @var{startstop} parameter is either -1
1147 (@code{\start}) or 1 (@code{\stop}) and @var{type} is a string that
1148 describes what should be started.  Supported types are @code{crescendo},
1149 @code{decrescendo}, @code{beam}, @code{slur}.  [FIXME: many more] This
1150 is an internal command.  Users should use the shorthands which are
1151 defined in the initialization file @file{spanners.ly}.
1152
1153 You can attach a (general) span request to a note using
1154
1155 @lilypond[fragment,verbatim,center]
1156   c'4-\spanrequest \start "slur"
1157   c'4-\spanrequest \stop "slur"
1158 @end lilypond
1159
1160 The slur syntax with parentheses is a shorthand for this.
1161
1162
1163 @c .  {Ornaments}
1164 @node Ornaments
1165 @subsection Ornaments
1166 @cindex Ornaments
1167 @menu
1168 * Articulation::                
1169 * Text scripts::                
1170 @end menu
1171
1172 @c .   {Articulation}
1173 @node Articulation
1174 @subsubsection Articulation
1175 @cindex Articulation
1176
1177 @cindex articulations
1178 @cindex scripts
1179 @cindex ornaments
1180
1181 A variety of symbols can appear above and below notes to indicate
1182 different characteristics of the performance.  These symbols can be
1183 added to a note with `@var{note}@code{-\}@var{name}'.  Numerous symbols
1184 are defined in @file{script.ly} and @file{script.scm}.  Symbols can be
1185 forced to appear above or below the note by writing
1186 `@var{note}@code{^\}@var{name}' and `@var{note}@code{_\}@var{name}'
1187 respectively.  Here is a chart showing symbols above notes, with the
1188 name of the corresponding symbol appearing underneath.
1189
1190 @lilypond[]
1191
1192   \score {
1193     < \notes {
1194         \property Score.LyricSyllable \override #'font-family =
1195 #'typewriter
1196         \property Score.LyricSyllable \override #'font-shape = #'upright
1197         c''-\accent      c''-\marcato      c''-\staccatissimo c''-\fermata 
1198         c''-\stopped     c''-\staccato     c''-\tenuto        c''-\upbow
1199         c''-\downbow     c''^\lheel        c''-\rheel         c''^\ltoe
1200         c''-\rtoe        c''-\turn         c''-\open          c''-\flageolet
1201         c''-\reverseturn c''-\trill        c''-\prall         c''-\mordent
1202         c''-\prallprall  c''-\prallmordent c''-\upprall       c''-\downprall
1203         c''-\thumb       c''-\segno        c''-\coda
1204       }
1205       \context Lyrics \lyrics {
1206         accent__      marcato__      staccatissimo__ fermata
1207         stopped__     staccato__     tenuto__        upbow
1208         downbow__     lheel__        rheel__         ltoe
1209         rtoe__        turn__         open__          flageolet
1210         reverseturn__ trill__        prall__         mordent
1211         prallprall__  prallmordent__ uprall__        downprall
1212         thumb__       segno__        coda
1213       }
1214     >
1215     \paper {
1216       linewidth = 5.875\in;          
1217       indent    = 0.0;
1218     }
1219   }
1220
1221 @end lilypond
1222
1223 @c .   {Text scripts}
1224 @node Text scripts
1225 @subsubsection Text scripts
1226 @cindex Text scripts
1227
1228 FIXME: markup
1229
1230 In addition, it is possible to place arbitrary strings of text or
1231 @TeX{} above or below notes by using a string instead of an
1232 identifier: @code{c^"text"}.  Fingerings 
1233 can be placed by simply using digits.  All of these note ornaments
1234 appear in the printed output but have no effect on the MIDI rendering of
1235 the music.
1236
1237 @c .    {Fingerings}
1238 @unnumberedsubsubsec Fingerings
1239 @cindex Fingerings
1240
1241 To save typing, fingering instructions (digits 0 to 9 are
1242 supported) and single characters shorthands exist for a few
1243 common symbols
1244
1245 @lilypond[]
1246   \score {
1247     \notes \context Voice {
1248       \property Voice.TextScript \set #'font-family = #'typewriter
1249       \property Voice.TextScript \set #'font-shape = #'upright
1250       c''4-._"c-."      s4
1251       c''4--_"c-{}-"    s4
1252       c''4-+_"c-+"      s4
1253       c''4-|_"c-|"      s4
1254       c''4->_"c->"      s4
1255       c''4-^_"c-\\^{ }" s4
1256       c''4-1_"c-1"      s4
1257       c''4-2_"c-2"      s4
1258       c''4-3_"c-3"      s4
1259       c''4-4_"c-4"      s4
1260     }
1261     \paper {
1262       linewidth = 5.875 \in;
1263       indent    = 0.0;
1264     }
1265   }
1266
1267 @end lilypond
1268
1269
1270 @cindex @code{\textscript}
1271
1272 @example
1273
1274   \textscript @var{text} @var{style}
1275 @end example
1276
1277 Defines a text to be printed over or under a note.  @var{style} is a
1278 string that may be one of @code{roman}, @code{italic}, @code{typewriter}, 
1279 @code{bold}, @code{Large}, @code{large}, @code{dynamic} or @code{finger}.
1280
1281 You can attach a general textscript request using this syntax:
1282
1283 @quotation
1284
1285 @example 
1286 c4-\textscript "6" "finger"
1287 c4-\textscript "foo" "normal" 
1288 @end example 
1289
1290 @end quotation
1291
1292 This is equivalent to @code{c4-6 c4-"foo"}.  
1293
1294 @cindex @code{\script}
1295 @cindex scripts
1296 @cindex superscript
1297 @cindex subscript
1298
1299 @example
1300   \script @var{alias}
1301 @end example
1302
1303 Prints a symbol above or below a note.  The argument is a string which
1304 points into the script-alias table defined in @file{scm/script.scm}.
1305 Usually the @code{\script} keyword is not used directly.  Various
1306 helpful identifier definitions appear in @file{script.ly}.
1307
1308 For information on how to add scripts, consult @file{scm/script.scm}.
1309
1310
1311
1312
1313 @c .   {Grace notes}
1314 @node Grace notes
1315 @subsection Grace notes
1316
1317
1318
1319
1320
1321
1322
1323 @cindex Grace music
1324 @cindex @code{\grace}
1325 @cindex ornaments
1326 @cindex grace notes
1327 @cindex @code{graceAlignPosition}
1328
1329 @example
1330   \grace @var{musicexpr}
1331 @end example
1332
1333 A grace note expression has duration 0; the next real note is
1334 assumed to be the main note.
1335
1336 You cannot have the grace note after the main note, in terms of
1337 duration, and main notes, but you can typeset the grace notes to the
1338 right of the main note using the property
1339 @code{graceAlignPosition}.
1340 @cindex @code{flagStyle}
1341
1342 When grace music is interpreted, a score-within-a-score is set up:
1343 @var{musicexpr} has its own time bookkeeping, and you could (for
1344 example) have a separate time signature within grace notes.  While in
1345 this score-within-a-score, you can create notes, beams, slurs, etc.
1346 Unbeamed eighth notes and shorter by default have a slash through the
1347 stem.  This behavior can be controlled with the
1348 @code{flagStyle} property.
1349
1350 @quotation
1351 @lilypond[fragment,verbatim]
1352 \relative c'' {
1353   \grace c8 c4 \grace { [c16 c16] } c4
1354   \grace { \property Grace.flagStyle = "" c16 } c4
1355 }
1356
1357 @end lilypond
1358 @end quotation
1359
1360
1361 At present, nesting @code{\grace} notes is not supported. The following
1362 may cause run-time errors:
1363 @example
1364   @code{\grace @{ \grace c32 c16 @} c4}
1365 @end example
1366 Since the meaning of such a construct is unclear, we don't consider
1367 this a loss.  Similarly, juxtaposing two @code{\grace} sections is
1368 syntactically valid, but makes no sense and may cause runtime errors.
1369
1370 Ending a staff or score with grace notes may also generate a run-time
1371 error, since there will be no main note to attach the grace notes to.
1372
1373 The present implementation is not robust and generally kludgy. We expect
1374 it to change after LilyPond 1.4. Syntax changes might also be
1375 implemented.
1376
1377
1378
1379
1380
1381
1382
1383 @c .   {Stem tremolo}
1384 @menu
1385 * Glissando ::                  
1386 * Dynamics::                    
1387 * Crescendo and Decrescendo::   
1388 * Bar lines::                   
1389 * Breath marks::                
1390 @end menu
1391
1392
1393
1394 @c .   {Glissando}
1395 @node Glissando 
1396 @subsubsection Glissando
1397 @cindex Glissando 
1398
1399 @cindex @code{\glissando}
1400
1401 A glissando line can be requested by attaching a @code{\glissando} to a
1402 note:
1403
1404 @quotation
1405 @lilypond[fragment,relative,verbatim]
1406   c'' \glissando c'
1407 @end lilypond
1408 @end quotation
1409
1410 Printing of an additional text (such as @emph{gliss.}) must be done
1411 manually.
1412
1413
1414
1415 @c .   {Dynamics}
1416 @node Dynamics
1417 @subsubsection Dynamics
1418 @cindex Dynamics
1419
1420
1421
1422 @cindex @code{\ppp}
1423 @cindex @code{\pp}
1424 @cindex @code{\p}
1425 @cindex @code{\mp}
1426 @cindex @code{\mf}
1427 @cindex @code{\f}
1428 @cindex @code{\ff}
1429 @cindex @code{\fff}
1430 @cindex @code{\ffff}
1431 @cindex @code{\fp}
1432 @cindex @code{\sf}
1433 @cindex @code{\sff}
1434 @cindex @code{\sp}
1435 @cindex @code{\spp}
1436 @cindex @code{\sfz}
1437 @cindex @code{\rfz}
1438
1439
1440
1441
1442
1443
1444 Dynamic marks are specified by using an identifier after a note:
1445 @code{c4-\ff}.  The available dynamic marks are:
1446 @code{\ppp}, @code{\pp}, @code{\p}, @code{\mp}, @code{\mf}, @code{\f},
1447 @code{\ff}, @code{\fff}, @code{\fff}, @code{\fp}, @code{\sf},
1448 @code{\sff}, @code{\sp}, @code{\spp}, @code{\sfz}, and @code{\rfz}.
1449
1450 @c .   {Crescendo and Decrescendo}
1451 @node Crescendo and Decrescendo
1452 @subsubsection Crescendo and Decrescendo
1453
1454 @cindex Crescendo and Decrescendo
1455 @cindex crescendo
1456 @cindex @code{\cr}
1457 @cindex @code{\rc}
1458 @cindex @code{\decr}
1459 @cindex @code{\rced}
1460 @cindex @code{\<}
1461 @cindex @code{\>}
1462 @cindex @code{\"!}
1463
1464
1465
1466 A crescendo mark is started with @code{\cr} and terminated with
1467 @code{\rc}, the textual reverse of @code{cr}.  A decrescendo mark is
1468 started with @code{\decr} and terminated with @code{\rced}.  There are
1469 also shorthands for these marks.  A crescendo can be started with
1470 @code{\<} and a decrescendo can be started with @code{\>}.  Either one
1471 can be terminated with @code{\!}.  Note that @code{\!}  must go before
1472 the last note of the dynamic mark whereas @code{\rc} and @code{\rced} go
1473 after the last note.  Because these marks are bound to notes, if you
1474 want to get several marks during one note, you must use spacer notes.
1475
1476 @lilypond[fragment,verbatim,center]
1477   c'' \< \! c''   d'' \decr e'' \rced 
1478   < f''1 { s4 \< \! s2 \> \! s4 } >
1479 @end lilypond
1480
1481 You can also use a text saying @emph{cresc.} instead of hairpins. Here
1482 is an example how to do it:
1483
1484 @lilypond[fragment,relative,verbatim]
1485   \context Voice {
1486     \property Voice.crescendoText = "cresc."
1487     \property Voice.crescendoSpanner = #'dashed-line
1488     a''2\mf\< a a \!a 
1489   }
1490 @end lilypond
1491
1492
1493
1494 @c .   {Bar lines}
1495 @node Bar lines
1496 @subsubsection Bar lines
1497 @cindex Bar lines
1498
1499 @cindex @code{\bar}
1500 @cindex measure lines
1501 @cindex repeat bars
1502
1503 @example
1504   \bar @var{bartype};
1505 @end example
1506
1507 This is a short-cut for doing
1508 @example
1509   \property Score.whichBar = @var{bartype} 
1510 @end example
1511
1512 You are encouraged to use @code{\repeat} for repetitions.  See
1513 @ref{Repeats}, and the documentation of @code{whichBar} in
1514 @ref{(lilypond-internals)LilyPond context properties}.
1515
1516
1517 [FIXME]
1518
1519 @c .   {Breath marks}
1520 @node Breath marks
1521 @subsubsection Breath marks
1522 @cindex Breath marks
1523
1524
1525
1526 @c .  {Bar check}
1527 @node Bar check
1528 @subsection Bar check
1529 @cindex Bar check
1530
1531 @cindex bar check
1532 @cindex @code{barCheckNoSynchronize}
1533 @cindex @code{|}
1534
1535
1536 Whenever a bar check is encountered during interpretation, a warning
1537 message is issued if it doesn't fall at a measure boundary.  This can
1538 help you find errors in the input.  Depending on the value of
1539 @code{barCheckNoSynchronize}, the beginning of the measure will be
1540 relocated, so this can also be used to shorten measures.
1541
1542 A bar check is entered using the bar symbol, @code{|}
1543
1544
1545
1546
1547
1548
1549
1550
1551 @c . {Piano music}
1552 @node Piano music
1553 @section Piano music
1554 @menu
1555 * Automatic staff changes::     
1556 * Manual staff switches::       
1557 * Pedals::                      
1558 * Arpeggio::                    
1559 * Follow Thread::               
1560 @end menu 
1561
1562
1563 @c .   {Automatic staff changes}
1564 @node Automatic staff changes
1565 @subsection Automatic staff changes
1566 @cindex Automatic staff changes
1567
1568 [\autochange]
1569
1570 @node Manual staff switches
1571 @subsection Manual staff switches
1572
1573 @cindex manual staff switches
1574 @cindex staff switch, manual
1575
1576 @cindex @code{\translator}
1577 @example
1578   \translator @var{contexttype} = @var{name}
1579 @end example
1580
1581 A music expression indicating that the context which is a direct
1582 child of the a context of type @var{contexttype} should be shifted to
1583 a context of type @var{contexttype} and the specified name.
1584
1585 Usually this is used to switch staffs in Piano music, e.g.
1586
1587 @example
1588   \translator Staff = top @var{Music}
1589 @end example
1590
1591
1592 @c .   {Pedals}
1593 @node Pedals
1594 @subsection Pedals
1595 @cindex Pedals
1596
1597 [todo]
1598
1599
1600 @c .   {Arpeggio}
1601 @node Arpeggio
1602 @subsection Arpeggio
1603 @cindex Arpeggio
1604
1605 @cindex broken arpeggio
1606 @cindex @code{\arpeggio}
1607
1608 You can specify an arpeggio sign on a chord by attaching an
1609 @code{\arpeggio} to a note of the chord.
1610
1611
1612 @quotation
1613 @lilypond[fragment,relative,verbatim]
1614   \context Voice <c'\arpeggio e g c>
1615 @end lilypond
1616 @end quotation
1617
1618 When an arpeggio crosses staffs in piano music, you attach an arpeggio
1619 to the chords in both staffs, and set
1620 @code{PianoStaff.connectArpeggios}. LilyPond will connect the arpeggios
1621 in both staffs.
1622
1623 @quotation
1624 @lilypond[fragment,relative,verbatim]
1625   \context PianoStaff <
1626     \property PianoStaff.connectArpeggios = ##t
1627     \context Voice = one  { <c''\arpeggio e g c> }
1628     \context Voice = other { \clef bass;  <c,,\arpeggio e g>}
1629   >  
1630 @end lilypond
1631 @end quotation
1632
1633
1634
1635 @c .    {Follow Thread}
1636 @node Follow Thread
1637 @subsection Follow Thread
1638 @cindex follow thread
1639 @cindex staff switching
1640 @cindex cross staff
1641
1642 [todo: different name, eg. voice line ? ]
1643
1644 @cindex @code{followThread}
1645
1646 Whenever a voice switches to another staff a line connecting the notes
1647 can be printed automatically. This is enabled if the property
1648 @code{PianoStaff.followThread} is set to true:
1649
1650 @quotation
1651 @lilypond[fragment,relative,verbatim]
1652   \context PianoStaff <
1653     \property PianoStaff.followThread = ##t
1654     \context Staff \context Voice {
1655       c'1
1656       \translator Staff=two
1657       b2 a
1658     }
1659     \context Staff=two {\clef bass; \skip 1*2;}
1660   >  
1661 @end lilypond
1662 @end quotation
1663
1664
1665 @c . {Lyrics}
1666 @node Lyrics
1667 @section Lyrics
1668
1669
1670 @menu
1671 * Lyrics mode::                 
1672 * Printing lyrics::             
1673 * Automatic syllable durations::  
1674 @end menu
1675
1676 @c .  {Lyrics mode}
1677 @node Lyrics mode
1678 @subsection Lyrics mode
1679 @cindex Lyrics mode
1680
1681 @cindex lyric mode
1682 @cindex @code{\lyrics}
1683
1684 Lyrics mode is introduced by the keyword @code{\lyrics}.  This mode has
1685 rules that make it easy to include punctuation and diacritical marks in
1686 words: The purpose of Lyrics mode is that you can enter lyrics in @TeX{}
1687 format or a standard encoding without needing quotes.  The precise
1688 definition of this mode is ludicrous, and this will remain so until the
1689 authors of LilyPond acquire a deeper understanding of character
1690 encoding, or someone else steps up to fix this.
1691
1692 A word in Lyrics mode begins with: an alphabetic character, @code{_},
1693 @code{?}, @code{!}, @code{:}, @code{'}, the control characters @code{^A}
1694 through @code{^F}, @code{^Q} through @code{^W}, @code{^Y}, @code{^^},
1695 any 8-bit character with ASCII code over 127, or a two-character
1696 combination of a backslash followed by one of @code{`}, @code{'},
1697 @code{"}, or @code{^}.
1698
1699 Subsequent characters of a word can be any character that is not a digit
1700 and not white space.  One important consequence of this is that a word
1701 can end with `@code{@}}', which may be confusing. However, LilyPond will
1702 issue a warning.  Any @code{_} character which appears in an unquoted
1703 word is converted to a space.  This provides a mechanism for introducing
1704 spaces into words without using quotes.  Quoted words can also be used
1705 in Lyrics mode to specify words that cannot be written with the above
1706 rules.  Here are some examples.  Not all of these words are printable by
1707 @TeX{}.
1708
1709 @example 
1710 Ah!             % a word
1711 2B_||_!2B       % not a word because it starts with a digit
1712 ``Hello''       % not a word because it starts with `
1713 _ _ _ _         % 4 words, each one a space 
1714 @end example 
1715
1716 Since combinations of numbers and dots are used for indicating
1717 durations, you can not enter real numbers in this mode.
1718
1719 @cindex lyrics expressions
1720
1721 Syllables are entered like notes, with pitches replaced by text.  For
1722 example, @code{Twin-4 kle4 twin-4 kle4} enters four syllables, each
1723 with quarter note duration.  Note that the hyphen has no special
1724 meaning for lyrics, and does not introduce special symbols.  See
1725 section @ref{Lexical modes} for a description of what is interpreted as
1726 lyrics.
1727
1728 Spaces can be introduced into a lyric either by using quotes
1729 (@code{"}) or by using an underscore without quotes: @code{He_could4
1730 not4}.  All unquoted underscores are converted to spaces.  Printing
1731 lyrics is discussed in the next section.
1732
1733
1734 @c .  {Printing lyrics}
1735 @node Printing lyrics
1736 @subsection Printing lyrics
1737 @cindex lyrics
1738
1739
1740 Lyric syllables must be interpreted within a @code{Lyrics} context for
1741 printing them. Here is a full example:
1742
1743 @quotation
1744 @lilypond[verbatim]
1745 \score {
1746   <
1747     \notes \transpose c'' {
1748       c d e c | c d e c |
1749       e f g2 | e4 f g2 \bar "|.";
1750     }
1751     \context Lyrics \lyrics { 
1752       Va-4 der Ja- cob Va- der Ja- cob
1753       Slaapt gij nog?2 Slaapt4 gij nog?2
1754     }
1755   >
1756 }
1757
1758 @end lilypond
1759 @end quotation
1760
1761
1762
1763
1764 @cindex extender
1765 @cindex lyric extender
1766
1767 You may want a continuous line after the syllables to show melismata. 
1768 To achieve this effect, add a @code{__} lyric as a separate word
1769 after the lyric to be extended.  This will create an extender, a line
1770 that extends over the entire duration of the lyric.  This line will
1771 run all the way to the start of the next lyric, so you may want to
1772 shorten it by using a blank lyric (using @code{_}).
1773
1774 @quotation
1775
1776 @lilypond[verbatim]
1777 \score {
1778   <
1779     \notes \relative c'' {
1780       a4 () b () c () d | c () d () b () a | c () d () b () a
1781     }
1782     \context Lyrics \lyrics {
1783       foo1 __ | bar2. __ _4 | baz1 __
1784     }
1785   >
1786 }
1787
1788 @end lilypond
1789 @end quotation
1790
1791 @cindex Lyric hyphen
1792
1793 If you want to have hyphens centered between syllables (rather than
1794 attached to the end of the first syllable) you can use the special
1795 `@code{-}@code{-}' lyric as a separate word between syllables.  This
1796 will result in a hyphen which length varies depending on the space
1797 between syllables, and which will be centered between the syllables. 
1798 For example:
1799
1800 @quotation
1801
1802 @lilypond[verbatim]
1803 \score {
1804   <
1805     \notes \transpose c'' {
1806       c d e c | c d e c |
1807       e f g2 | e4 f g2 \bar "|.";
1808     }
1809     \context Lyrics \lyrics {
1810       Va4 -- der Ja -- cob | Va -- der Ja -- cob |
1811       Slaapt gij nog?2 | Slaapt4 gij nog?2
1812     }
1813   >
1814 }
1815
1816 @end lilypond
1817 @end quotation
1818
1819
1820 @c .  {Automatic syllable durations}
1821 @node Automatic syllable durations
1822 @subsection Automatic syllable durations
1823 @cindex Automatic syllable durations
1824
1825
1826 [explain automatic phrasing]
1827 @cindex automatic lyric durations
1828 @cindex @code{\addlyrics}
1829
1830 If you have lyrics that are set to a melody, you can import the rhythm
1831 of that melody into the lyrics using @code{\addlyrics}.  The syntax for
1832 this is
1833 @example
1834   \addlyrics @var{musicexpr1 musicexpr2}
1835 @end example
1836
1837 This means that both @var{musicexpr1} and @var{musicexpr2} are
1838 interpreted, but that every non-command atomic music expression
1839 (``every syllable'') in @var{musicexpr2} is interpreted using timing
1840 of @var{musicexpr1}.
1841 @cindex @code{automaticMelismata}
1842
1843 If the property @code{automaticMelismata} is set in the
1844 context of @var{musicexpr1}, no lyrics will be put on slurred or tied
1845 notes.
1846
1847 @quotation
1848 @lilypond[verbatim,fragment]
1849 \addlyrics
1850 \transpose c'' {
1851   \property Voice.automaticMelismata = ##t
1852   c8 () cis d8. e16 f2
1853 }
1854 \context Lyrics \lyrics {
1855  do4 re mi fa }
1856 @end lilypond
1857 @end quotation
1858
1859 You should use a single rhythm melody, and single rhythm lyrics (a
1860 constant duration is the obvious choice).  If you do not, you will get
1861 undesired effects when using multiple stanzas:
1862
1863 @quotation
1864 @lilypond[verbatim,fragment]
1865 \addlyrics
1866 \transpose c'' {
1867   c8 () cis d8. e16 f2
1868 }
1869 \context Lyrics \lyrics
1870 < { do4 re mi fa }
1871   { do8 re mi fa } >
1872
1873 @end lilypond
1874 @end quotation
1875
1876 It is valid (but probably not very useful) to use notes instead of
1877 lyrics for @var{musicexpr2}.
1878
1879
1880
1881 @c . {Chords}
1882 @node Chords
1883 @section Chords
1884 @cindex Chords
1885
1886 [chords vs. simultaneous music]
1887
1888 @menu
1889 * Chords mode::                 
1890 * Entering named chords::       
1891 * Printing named chords::       
1892 @end menu
1893
1894 @c .  {Chords mode}
1895 @node Chords mode
1896 @subsection Chords mode
1897 @cindex Chords mode
1898
1899 Chord mode is introduced by the keyword
1900 @code{\chords}.  It is similar to Note mode, but
1901 words are also looked up in a chord modifier table (containing
1902 @code{maj}, @code{dim}, etc).
1903
1904 Since combinations of numbers and dots are used for indicating
1905 durations, you can not enter real numbers in this mode.  Dashes
1906 and carets are used to indicate chord additions and subtractions,
1907 so scripts can not be entered in Chord mode.
1908
1909 @c .  {Entering named chords}
1910 @node Entering named chords
1911 @subsection Entering named chords
1912 @cindex Chords names
1913
1914 Chord names are a way to generate simultaneous music expressions that
1915 correspond with traditional chord names.  It can only be used in
1916 Chord mode (see section @ref{Lexical modes}).
1917
1918 @example
1919
1920   @var{tonic}[@var{duration}][@code{-}@var{modifiers}][@code{^}@var{subtractions}][@code{/}@var{inversion}][@code{/+}@var{bass}].
1921 @end example
1922
1923 @var{tonic} should be the tonic note of the chord, and @var{duration}
1924 is the chord duration in the usual notation.  There are two kinds of
1925 modifiers.  One type is @emph{chord additions}, which are obtained by
1926 listing intervals separated by dots.  An interval is written by its
1927 number with an optional @code{+} or @code{-} to indicate raising or
1928 lowering by half a step.  Chord additions has two effects: It adds
1929 the specified interval and all lower odd numbered intervals to the
1930 chord, and it may lower or raise the specified interval.  Intervals
1931 must be separated by a dot (@code{.}).
1932
1933
1934 Throughout these examples, chords have been shifted around the staff
1935 using @code{\transpose}.
1936
1937
1938 @quotation
1939
1940 @lilypond[fragment,verbatim]
1941 \transpose c'' {
1942   \chords {
1943     c1  c:3-       c:7     c:8
1944     c:9 c:9-.5+.7+ c:3-.5- c:4.6.8
1945   }
1946 }
1947
1948 @end lilypond
1949 @end quotation
1950
1951 @cindex @code{aug}
1952 @cindex @code{dim}
1953 @cindex @code{maj}
1954 @cindex @code{sus}
1955
1956 The second type of modifier that may appear after the @code{:} is a
1957 named modifier.  Named modifiers are listed in the file
1958 @file{chord-modifiers.ly}.  The available modifiers are @code{m} and
1959 @code{min} which lower the 3rd half a step, `@code{aug}' which
1960 raises the 5th, `@code{dim}' which lowers the 5th,
1961 `@code{maj}' which adds a raised 7th, and `@code{sus}'
1962 which replaces the 5th with a 4th.
1963
1964 @quotation
1965
1966 @lilypond[fragment,verbatim]
1967 \transpose c'' {
1968   \chords {
1969     c1:m c:min7 c:maj c:aug c:dim c:sus
1970   }
1971 }
1972
1973 @end lilypond
1974 @end quotation
1975  
1976
1977 Chord subtractions are used to eliminate notes from a chord.  The
1978 notes to be subtracted are listed after a @code{^} character,
1979 separated by dots.
1980
1981 @lilypond[fragment,verbatim,center]
1982   \transpose c'' {
1983     \chords {
1984       c1^3 c:7^5.3 c:8^7
1985     }
1986   }
1987 @end lilypond 
1988 @cindex @code{/}
1989
1990 Chord inversions can be specified by appending `@code{/}' and
1991 the name of a single note to a chord.  This has the effect of
1992 lowering the specified note by an octave so it becomes the lowest
1993 note in the chord.  If the specified note is not in the chord, a
1994 warning will be printed.
1995
1996 @lilypond[fragment,verbatim,center]
1997   \transpose c''' {
1998     \chords {
1999       c1 c/e c/g c:7/e
2000     }
2001   }
2002
2003 @end lilypond 
2004 @cindex @code{/+}
2005
2006 Bass notes can be added by `@code{/+}' and
2007 the name of a single note to a chord.  This has the effect of
2008 adding the specified note to the chord, lowered by an octave,
2009 so it becomes the lowest note in the chord.
2010
2011 @lilypond[fragment,verbatim,center]
2012   \transpose c''' {
2013     \chords {
2014       c1 c/+c c/+g c:7/+b
2015     }
2016   }
2017
2018 @end lilypond 
2019
2020 The most interesting application is printing  chord names, which is
2021 explained in the next subsection.
2022
2023 You should not combine @code{\relative} with named chords. [FIXME]
2024
2025 @c .  {Printing named chords}
2026 @node Printing named chords
2027 @subsection Printing named chords
2028
2029
2030
2031
2032
2033 @cindex printing chord names
2034 @cindex chord names
2035 @cindex chords
2036 @cindex @code{ChordNames}
2037 @cindex @code{ChordNameVoice}
2038
2039 For displaying printed chord names, use the @code{ChordNames} and
2040 @code{ChordNameVoice} contexts.  The chords may be entered either using
2041 the notation described above, or directly using simultaneous music.
2042
2043 @quotation
2044 @lilypond[verbatim]
2045 scheme = \notes {
2046   \chords {a1 b c} <d f g>  <e g b>
2047 }
2048 \score {
2049   \notes<
2050     \context ChordNamesVoice \scheme
2051     \context Staff \transpose c'' \scheme
2052   >
2053   \paper { linewidth = -1.; }
2054 }
2055 @end lilypond
2056 @end quotation
2057
2058 You can make the chord changes stand out more by setting property
2059 @code{ChordNames.chordChanges} to true.  This will only display chord
2060 names when there's a change in the chords scheme, but always display the
2061 chord name after a line break:
2062
2063 @c bug
2064 @quotation
2065 @lilypond[verbatim]
2066 scheme = \chords {
2067   c1:m \break c:m c:m c:m d
2068 }
2069
2070 \score {
2071   \notes <
2072     \context ChordNames \scheme
2073     \context Staff \transpose c'' \scheme
2074   >
2075   \paper{
2076     linewidth = 40 * \staffspace;
2077     \translator {
2078       \ChordNamesContext
2079       chordChanges = ##t
2080     }
2081   }
2082 }
2083 @end lilypond
2084 @end quotation
2085
2086
2087
2088 LilyPond examines chords specified as lists of notes to determine a
2089 name to give the chord. LilyPond will not try to
2090 identify chord inversions or added base, which may result in strange
2091 chord names when chords are entered as a list of pitches:
2092
2093 @quotation
2094 @lilypond[verbatim,center]
2095 scheme = \notes {
2096   <c'1 e' g'>
2097   <e' g' c''>
2098   <e e' g' c''>
2099 }
2100
2101 \score {
2102   <
2103     \context ChordNamesVoice \scheme
2104     \context Staff \scheme
2105   >
2106   \paper { linewidth = -1.; }
2107 }
2108 @end lilypond
2109 @end quotation
2110
2111 To specify chord inversions, append @code{/<notename>}.  To specify an
2112 added bass note, append @code{/+<notename}:
2113
2114 @quotation
2115 @lilypond[verbatim,center]
2116 scheme = \chords {
2117   d1 d/a d/+gis
2118 }
2119
2120 \score {
2121   \notes <
2122     \context ChordNames \scheme
2123     \context Staff \transpose c'' \scheme
2124   >
2125   \paper { linewidth = -1.; }
2126 }
2127 @end lilypond
2128 @end quotation
2129
2130 The chord names that LilyPond should print are fully customizable.  The
2131 code to print chord names is written in Scheme. It can be found in
2132 @file{scm/chord-name.scm}.  Chord names are based on Banter style
2133 naming, which is unambiguous and has a logical structure.  Typical
2134 American style chord names are implemented as a variation on Banter
2135 names, they can be selected by setting property @code{ChordName.style}
2136 to @code{american}:
2137
2138 @quotation
2139 @lilypond[verbatim]
2140 \include "english.ly"
2141
2142 scheme = \chords {
2143   c         % Major triad
2144   cs:m      % Minor triad
2145   df:m5-    % Diminished triad
2146   c:5^3     % Root-fifth chord
2147   c:4^3     % Suspended fourth triad
2148   c:5+      % Augmented triad
2149   c:2^3     % "2" chord
2150   c:m5-.7-  % Diminished seventh
2151   c:7+      % Major seventh
2152   c:7.4^3   % Dominant seventh suspended fourth
2153   c:5+.7    % Augmented dominant seventh
2154   c:m5-.7   % "Half" diminished seventh
2155   c:5-.7    % Dominant seventh flat fifth
2156   c:5-.7+   % Major seventh flat fifth
2157   c:m7+     % Minor-major seventh
2158   c:m7      % Minor seventh
2159   c:7       % Dominant seventh
2160   c:6       % Major sixth
2161   c:m6      % Minor sixth
2162   c:9^7     % Major triad w/added ninth
2163   c:6.9^7   % Six/Nine chord
2164   c:9       % Dominant ninth 
2165   c:7+.9    % Major ninth
2166   c:m7.9    % Minor ninth
2167 }
2168
2169 \score {
2170   \notes <
2171     \context ChordNames \scheme
2172     \context Staff \transpose c'' \scheme
2173   >
2174   \paper {
2175     \translator { 
2176       \ChordNamesContext
2177       ChordName \override #'word-space = #1 
2178       ChordName \override #'style = #'american
2179     }
2180   }
2181 }
2182 @end lilypond
2183 @end quotation
2184
2185 Similarly, Jazz style chord names are implemented as a variation on
2186 American style names:
2187 @quotation
2188 @lilypond[verbatim]
2189 scheme = \chords {
2190   % major chords
2191   c
2192   c:6           % 6 = major triad with added sixth
2193   c:maj         % triangle = maj
2194   c:6.9^7       % 6/9 
2195   c:9^7         % add9
2196
2197   % minor chords
2198   c:m           % m = minor triad
2199   c:m.6         % m6 = minor triad with added sixth
2200   c:m.7+        % m triangle = minor major seventh chord
2201   c:3-.6.9^7    % m6/9 
2202   c:m.7         % m7
2203   c:3-.9        % m9
2204   c:3-.9^7      % madd9
2205
2206   % dominant chords
2207   c:7           % 7 = dominant
2208   c:7.5+        % +7 = augmented dominant
2209   c:7.5-        % 7b5 = hard diminished dominant
2210   c:9           % 7(9)
2211   c:9-          % 7(b9)
2212   c:9+          % 7(#9)
2213   c:13^9.11     % 7(13)
2214   c:13-^9.11    % 7(b13)
2215   c:13^11       % 7(9,13)
2216   c:13.9-^11    % 7(b9,13)
2217   c:13.9+^11    % 7(#9,13)
2218   c:13-^11      % 7(9,b13)
2219   c:13-.9-^11   % 7(b9,b13)
2220   c:13-.9+^11   % 7(#9,b13)
2221
2222   % half diminished chords
2223   c:m5-.7               % slashed o = m7b5
2224   c:9.3-.5-     % o/7(pure 9)
2225
2226   % diminished chords
2227   c:m5-.7-      % o = diminished seventh chord
2228 }
2229
2230 \score {
2231   \notes <
2232     \context ChordNames \scheme
2233     \context Staff \transpose c'' \scheme
2234   >
2235   \paper {
2236     \translator { 
2237       \ChordNamesContext
2238       ChordName \override #'word-space = #1 
2239       ChordName \override #'style = #'jazz
2240     }
2241   }
2242 }
2243 @end lilypond
2244 @end quotation
2245
2246 @node Writing parts
2247 @section Writing parts
2248
2249 @c .  {Transpose}
2250 @menu
2251 * Rehearsal marks::             
2252 * Transpose::                   
2253 * Multi measure rests::         
2254 @end menu
2255
2256 [TODO:
2257
2258 partcombine
2259
2260 rehearsal marks
2261
2262 bar numbering 
2263
2264 tranposing midi property.
2265
2266 instrument names
2267
2268
2269
2270 @c .   {Rehearsal marks}
2271 @node Rehearsal marks
2272 @subsection Rehearsal marks
2273 @cindex Rehearsal marks
2274 @cindex mark
2275 @cindex @code{\mark}
2276 @cindex @code{Mark_engraver}
2277
2278 @example
2279   \mark @var{unsigned};
2280   \mark @var{string};
2281   \mark ; 
2282 @end example
2283
2284 With this command, you can print a rehearsal mark above the system. You
2285 can provide a number, a string or a markup text as argument. If there is
2286 no argument, the property @code{rehearsalMark} is used and automatically
2287 incremented.
2288
2289 @lilypond[fragment,verbatim]
2290 \relative c'' {
2291   c1 \mark "A2";
2292   c1 \mark ; 
2293   c1 \mark ; 
2294   c1 \mark "12";
2295   c1 \mark #'(music "scripts-segno") ;
2296   c1
2297 }
2298 @end lilypond
2299
2300 @node Transpose
2301 @subsection Transpose
2302 @cindex Transpose
2303 @cindex transposition of pitches
2304 @cindex @code{\transpose}
2305
2306 A music expression can be transposed with @code{\transpose}.  The syntax
2307 is
2308 @example
2309   \transpose @var{pitch} @var{musicexpr}
2310 @end example
2311
2312 This means that middle C in @var{musicexpr} is transposed to
2313 @var{pitch}.
2314
2315 @code{\transpose} distinguishes between enharmonic pitches: both
2316 @code{\transpose cis'} or @code{\transpose des'} will transpose up half
2317 a tone.  The first version will print sharps and the second version
2318 will print flats.
2319
2320 @quotation
2321 @lilypond[fragment,verbatim]
2322 \context Staff {
2323   \clef "F";
2324   { \key e \major; c d e f }
2325   \clef "G";
2326   \transpose des'' { \key e \major; c d e f }
2327   \transpose cis'' { \key e \major; c d e f }
2328 }
2329
2330 @end lilypond
2331 @end quotation
2332
2333 If you want to use both @code{\transpose} and @code{\relative}, then
2334 you must use @code{\transpose} first.  @code{\relative} will have no
2335 effect music that appears inside a @code{\transpose}.
2336
2337
2338 @c .  {Multi measure rests}
2339 @node  Multi measure rests
2340 @subsection Multi measure rests
2341 @cindex Multi measure rests
2342
2343 @cindex @code{R}
2344
2345 Multi measure rests are entered using `@code{R}'. It is specifically
2346 meant for entering parts: the rest can expand to fill a score with
2347 rests, or it can be printed as a single multimeasure rest This expansion
2348 is controlled by the property @code{Score.skipBars}. If this is set to true,
2349 Lily will not expand empty measures, and the appropriate number is added
2350 automatically.
2351
2352 @lilypond[fragment,verbatim]
2353  \time 3/4; R2.*2 \property Score.skipBars = ##t R2.*17  R2.*4
2354 @end lilypond
2355
2356 Currently, there is  no way to condense multiple rests into a single
2357 multimeasure rest.
2358
2359 @cindex condensing rests
2360
2361 @c . {Custodes}
2362 @node Custodes
2363 @section Custodes
2364 @cindex Custos
2365 @cindex Custodes
2366
2367 A @emph{custos} (plural: @emph{custodes}; latin word for "guard") is a
2368 staff context symbol that appears at the end of a staff line.  It
2369 anticipates the pitch of the first note(s) of the following line and
2370 thus helps the player or singer to manage line breaks during
2371 performance, thus enhancing readability of a score.
2372
2373 @quotation
2374 @lilypond[verbatim]
2375 \score {
2376   \notes { c'1 d' e' d' \break c' d' e' d' }
2377   \paper {
2378     \translator {
2379       \StaffContext
2380       \consists Custos_engraver;
2381       Custos \override #'style = #'mensural;
2382     }
2383   }
2384 }
2385 @end lilypond
2386 @end quotation
2387
2388 Custodes were frequently used in music notation until the 16th century.
2389 There were different appearences for different notation styles.
2390 Nowadays, they have survived only in special forms of musical notation
2391 such as via the editio vaticana dating back to the beginning of the 20th
2392 century.
2393
2394 For typesetting custodes, just put a @code{Custos_engraver} into the
2395 @code{StaffContext} when declaring the @code{\paper} block.  In this
2396 block, you can also globally control the appearance of the custos symbol
2397 by setting the custos @code{style} property.  Currently supported styles
2398 are @code{vaticana}, @code{medicaea}, @code{hufnagel} and
2399 @code{mensural}.
2400
2401 @quotation
2402 \paper @{
2403   \translator @{
2404       \StaffContext
2405       \consists Custos_engraver;
2406       Custos \override #'style = #'mensural;
2407   @}
2408 @}
2409 @end quotation
2410
2411 The property can also be set locally, for example in a @code{\notes}
2412 block:
2413
2414 @quotation
2415 \notes @{
2416   \property Staff.Custos \override #'style = #'vaticana
2417   c'1 d' e' d' \break c' d' e' d'
2418 @}
2419 @end quotation
2420
2421 @c . {Page layout}
2422 @node Page layout
2423 @section Page layout
2424 @cindex Page layout
2425
2426 @menu
2427 * Paper block::                 
2428 * Paper variables::             
2429 * Font Size::                   
2430 * Paper size::                  
2431 * Line break::                  
2432 * Page break::                  
2433 @end menu
2434
2435 @c .  {Paper block}
2436 @node Paper block
2437 @subsection Paper block
2438 @cindex Paper block
2439
2440 The most important output definition is the @code{\paper} block, for
2441 music notation.  The syntax is
2442
2443 @example
2444   @code{\paper @{} [@var{paperidentifier}] @var{items} @code{@}}
2445 @end example
2446
2447 where each of the items is one of
2448
2449 @itemize @bullet
2450   @item  An assignment.  The assignment must be terminated by a
2451        semicolon.  
2452
2453   @item  A context definition.  See section @ref{Context definitions} for
2454        more information on context definitions.
2455
2456   @item  \stylesheet  declaration.  Its syntax is
2457        @example
2458                 \stylesheet @var{alist}
2459        @end example
2460
2461         See @file{font.scm} for details of @var{alist}.
2462 @end itemize
2463
2464 @c .  {Paper variables}
2465 @node Paper variables
2466 @subsection Paper variables 
2467 @cindex Paper variables
2468
2469 The paper block has some variables you may want to use or change:
2470
2471 @table @code
2472 @cindex @code{indent}
2473   @item @code{indent}  
2474     The indentation of the first line of music.
2475 @cindex @code{staffspace}
2476
2477   @item @code{staffspace}
2478     The distance between two staff lines, calculated from the center
2479     of the lines.  You should use either this or @code{stafflinethickness}
2480     as a unit for distances you modify.
2481   
2482 @cindex @code{linewidth}
2483   @item @code{linewidth}  
2484     Sets the width of the lines.
2485
2486 If set to a negative value, a single
2487     unjustified line is produced.
2488
2489 @cindex @code{textheight}
2490
2491   @item @code{textheight}  
2492     Sets the total height of the music on each page. Only used by
2493     ly2dvi.
2494 @cindex @code{interscoreline}
2495
2496   @item @code{interscoreline}  
2497     Sets the spacing between the score lines. Defaults to 16 pt.
2498 @cindex @code{interscorelinefill}
2499
2500   @item @code{interscorelinefill}  
2501     If set to a positive number, the distance between the score 
2502     lines will stretch in order to fill the full page. In that
2503     case @code{interscoreline} specifies the minimum spacing.
2504     Defaults to 0.
2505 @cindex @code{stafflinethickness}
2506
2507   @item @code{stafflinethickness}  
2508     Determines the thickness of staff lines, and also acts as a scaling
2509     parameter for other line thicknesses.
2510 @end table
2511
2512
2513
2514 @c .  {Font size}
2515 @node Font Size
2516 @subsection Font size
2517 @cindex font size
2518
2519 The Feta font provides musical symbols at six different sizes.  These
2520 fonts are 11 point, 13 point, 16 point, 20 point,
2521 23 point, and 26 point.  The point size of a font is the
2522 height of the five lines in a staff when displayed in the font.
2523
2524 Definitions for these sizes are the files @file{paperSZ.ly}, where
2525 @code{SZ} is one of 11, 13, 16, 20, 23 and 26.  If you include any of
2526 these files, the identifiers @code{paperEleven}, @code{paperThirteen},
2527 @code{paperSixteen}, @code{paperTwenty}, @code{paperTwentythree}, and
2528 @code{paperTwentysix} are defined respectively.  The default
2529 @code{\paper} block is also set.
2530
2531 The font definitions are generated using a Scheme function. For more
2532 details, see the file @file{font.scm}.
2533
2534
2535
2536 @c .  {Paper size}
2537 @node Paper size
2538 @subsection Paper size
2539 @cindex Paper size
2540
2541 @cindex paper size
2542 @cindex page size
2543 @cindex @code{papersize}
2544
2545 To change the paper size, you must first set the
2546 @code{papersize} variable at top level.  Set it to
2547 the strings @code{a4}, @code{letter}, or @code{legal}.  After this
2548 specification, you must set the font as described above.  If you want
2549 the default font, then use the 20 point font.  The new paper size will
2550 not take effect if the font is not loaded and selected afterwards.
2551
2552 @example
2553         papersize = "a4"
2554         \include "paper16.ly"
2555
2556         \score @{
2557                 ...
2558                 \paper @{ \paperSixteen @}
2559         @}
2560 @end example
2561
2562 The file "paper16.ly" will now include a file named @file{a4.ly}, which
2563 will set the paper variables @code{hsize} and @code{vsize} (used by
2564 @code{ly2dvi})
2565
2566
2567
2568
2569
2570
2571
2572 @c .  {Line break}
2573 @node Line break
2574 @subsection Line break
2575
2576 @cindex line breaks
2577 @cindex breaking lines
2578
2579 Line breaks are normally computed automatically. They are chosen such
2580 that the resulting spacing has low variation, and looks neither cramped
2581 nor loose.
2582
2583 Occasionally you might want to override the automatic breaks; you can do
2584 this by specifying @code{\break}. This will force a line break at this
2585 point. Do remember that line breaks can only occur at places where there
2586 are barlines.  If you want to have a line break where there is no
2587 barline, you can force a barline by entering @code{\bar "";}.
2588
2589 Similarly, @code{\noBreak} forbids a  line break at a certain point.
2590
2591 @cindex @code{\penalty}
2592
2593 The @code{\break} and @code{\noBreak} commands are defined in terms of
2594 the penalty command:
2595 @example
2596   \penalty @var{int} @code{;}
2597 @end example
2598
2599 This imposes   encourages or discourages LilyPond to make a line break
2600 at this point.
2601
2602 @strong{Warning} do not use @code{\penalty} directly. It is rather
2603 kludgy, and slated for rewriting.
2604
2605 @c .  {Page break}
2606 @node Page break
2607 @subsection Page break
2608
2609 @cindex page breaks
2610 @cindex breaking pages
2611
2612
2613 Page breaks are normally computed by @TeX{}, so they are not under direct
2614 control.  However, you can insert a commands into the @file{.tex} output to
2615 instruct @TeX{} where to break pages. For more details, see  the
2616 example file @file{input/test/between-systems.ly}
2617
2618 [or -> Tricks? ]
2619
2620
2621
2622
2623
2624
2625 @c . {Sound}
2626 @node Sound
2627 @section Sound
2628 @cindex Sound
2629 @menu
2630 * MIDI block::                  
2631 * MIDI instrument names::       
2632 * Tempo::                       
2633 @end menu
2634
2635 @c .  {MIDI block}
2636 @node MIDI block
2637 @subsection MIDI block
2638 @cindex MIDI block
2639
2640
2641 The MIDI block is analogous to the paper block, but it is somewhat
2642 simpler.  The @code{\midi} block can contain:
2643 @cindex MIDI block
2644
2645 @itemize @bullet
2646   @item  a @code{\tempo} definition
2647   @item  context definitions
2648 @end itemize
2649
2650 Assignments in the @code{\midi} block are not allowed.
2651
2652
2653
2654 @cindex context definition
2655
2656 Context definitions follow precisely the same syntax as within the
2657 \paper block.  Translation modules for sound are called performers.
2658 The contexts for MIDI output are defined in @file{ly/performer.ly}.
2659
2660
2661 @c .  {MIDI instrument names}
2662 @node MIDI instrument names
2663 @subsection MIDI instrument names
2664 @cindex instrument names
2665 @cindex @code{Staff.midiInstrument}
2666 @cindex @code{Staff.instrument}
2667
2668 The MIDI instrument name is set by the @code{Staff.midiInstrument}
2669 property or, if that property is not set, the @code{Staff.instrument}
2670 property.  The instrument name should be chosen from the following list.
2671 If the selected string does not exactly match, then LilyPond uses the
2672 default piano.
2673
2674 [FIXME: to appendix ]
2675
2676
2677 @example 
2678 "acoustic grand"            "contrabass"           "lead 7 (fifths)"
2679 "bright acoustic"           "tremolo strings"      "lead 8 (bass+lead)"
2680 "electric grand"            "pizzicato strings"    "pad 1 (new age)"
2681 "honky-tonk"                "orchestral strings"   "pad 2 (warm)"
2682 "electric piano 1"          "timpani"              "pad 3 (polysynth)"
2683 "electric piano 2"          "string ensemble 1"    "pad 4 (choir)"
2684 "harpsichord"               "string ensemble 2"    "pad 5 (bowed)"
2685 "clav"                      "synthstrings 1"       "pad 6 (metallic)"
2686 "celesta"                   "synthstrings 2"       "pad 7 (halo)"
2687 "glockenspiel"              "choir aahs"           "pad 8 (sweep)"
2688 "music box"                 "voice oohs"           "fx 1 (rain)"
2689 "vibraphone"                "synth voice"          "fx 2 (soundtrack)"
2690 "marimba"                   "orchestra hit"        "fx 3 (crystal)"
2691 "xylophone"                 "trumpet"              "fx 4 (atmosphere)"
2692 "tubular bells"             "trombone"             "fx 5 (brightness)"
2693 "dulcimer"                  "tuba"                 "fx 6 (goblins)"
2694 "drawbar organ"             "muted trumpet"        "fx 7 (echoes)"
2695 "percussive organ"          "french horn"          "fx 8 (sci-fi)"
2696 "rock organ"                "brass section"        "sitar"
2697 "church organ"              "synthbrass 1"         "banjo"
2698 "reed organ"                "synthbrass 2"         "shamisen"
2699 "accordion"                 "soprano sax"          "koto"
2700 "harmonica"                 "alto sax"             "kalimba"
2701 "concertina"                "tenor sax"            "bagpipe"
2702 "acoustic guitar (nylon)"   "baritone sax"         "fiddle"
2703 "acoustic guitar (steel)"   "oboe"                 "shanai"
2704 "electric guitar (jazz)"    "english horn"         "tinkle bell"
2705 "electric guitar (clean)"   "bassoon"              "agogo"
2706 "electric guitar (muted)"   "clarinet"             "steel drums"
2707 "overdriven guitar"         "piccolo"              "woodblock"
2708 "distorted guitar"          "flute"                "taiko drum"
2709 "guitar harmonics"          "recorder"             "melodic tom"
2710 "acoustic bass"             "pan flute"            "synth drum"
2711 "electric bass (finger)"    "blown bottle"         "reverse cymbal"
2712 "electric bass (pick)"      "skakuhachi"           "guitar fret noise"
2713 "fretless bass"             "whistle"              "breath noise"
2714 "slap bass 1"               "ocarina"              "seashore"
2715 "slap bass 2"               "lead 1 (square)"      "bird tweet"
2716 "synth bass 1"              "lead 2 (sawtooth)"    "telephone ring"
2717 "synth bass 2"              "lead 3 (calliope)"    "helicopter"
2718 "violin"                    "lead 4 (chiff)"       "applause"
2719 "viola"                     "lead 5 (charang)"     "gunshot"
2720 "cello"                     "lead 6 (voice)" 
2721 @end example 
2722
2723
2724
2725
2726
2727 @c .  {Tempo}
2728 @node Tempo
2729 @subsection Tempo
2730 @cindex Tempo
2731 @cindex beats per minute
2732 @cindex metronome marking
2733
2734 @cindex @code{\tempo}
2735 @example
2736   \tempo @var{duration} = @var{perminute} @code{;}
2737 @end example
2738
2739 Used to specify the tempo.  For example, @code{\tempo 4 = 76;} requests
2740 output with 76 quarter notes per minute.
2741
2742
2743
2744
2745
2746 @c . {Music entry}
2747 @node Music entry
2748 @section Music entry
2749 @cindex Music entry
2750 @menu
2751 * Relative::                    
2752 * Point and click::             
2753 @end menu
2754
2755
2756
2757 @c .  {Relative}
2758 @node Relative
2759 @subsection Relative
2760 @cindex Relative
2761 @cindex relative octave specification
2762
2763 Octaves are specified by adding @code{'} and @code{,} to pitch names.
2764 When you copy existing music, it is easy to accidentally put a pitch in
2765 the wrong octave and hard to find such an error.  To prevent these
2766 errors, LilyPond features octave entry.
2767
2768 @cindex @code{\relative}
2769 @example
2770   \relative @var{startpitch} @var{musicexpr}
2771 @end example
2772
2773 The octave of notes that appear in @var{musicexpr} are calculated as
2774 follows: If no octave changing marks are used, the basic interval
2775 between this and the last note is always taken to be a fourth or less.
2776   The octave changing marks @code{'} and @code{,} can then
2777 be added to raise or lower the pitch by an extra octave.  Upon entering
2778 relative mode, an absolute starting pitch must be specified that will
2779 act as the predecessor of the first note of @var{musicexpr}.
2780
2781 This distance is determined without regarding accidentals: a
2782 @code{fisis} following a @code{ceses} will be put above the
2783 @code{ceses}.
2784
2785 Entering scales is straightforward in relative mode.
2786
2787 @lilypond[fragment,verbatim,center]
2788   \relative c'' {
2789     g a b c d e f g g, g
2790   }
2791 @end lilypond
2792
2793 And octave changing marks are used for intervals greater than a fourth.
2794
2795 @lilypond[fragment,verbatim,center]
2796   \relative c'' {
2797     c g c f, c' a, e'' }
2798 @end lilypond
2799
2800 If the preceding item is a chord, the first note of the chord is used
2801 to determine the first note of the next chord.  But other notes
2802 within the second chord are determined by looking at the immediately
2803 preceding note.
2804
2805 @lilypond[fragment,verbatim,center]
2806   \relative c' {
2807     c <c e g> 
2808     <c' e g>
2809     <c, e' g>
2810   }
2811 @end lilypond 
2812 @cindex @code{\notes}
2813
2814 The pitch after the @code{\relative} contains a notename.  To parse
2815 the pitch as a notename, you have to be in note mode, so there must
2816 be a surrounding @code{\notes} keyword (which is not
2817 shown here).
2818
2819 The relative conversion will not affect @code{\transpose} or
2820 @code{\relative} sections in its argument.  If you want to use
2821 relative within transposed music, you must place an additional
2822 @code{\relative} inside the @code{\transpose}.
2823
2824
2825 @c .  {Point and click}
2826 @node Point and click
2827 @subsection Point and click
2828
2829 [todo]
2830
2831 @c . {Engravers}
2832 @node Engravers
2833 @section Engravers
2834 @cindex engravers
2835 @menu
2836 * Selecting contexts::          
2837 * Context definitions::         
2838 * Notation Contexts::           
2839 @end menu
2840
2841 @c .  {Music expressions}
2842 @node Selecting contexts
2843 @subsection Selecting contexts
2844
2845 @cindex @code{\context}
2846 @cindex context selection
2847
2848 @example
2849   \context @var{contexttype} [= @var{contextname}] @var{musicexpr}
2850 @end example
2851
2852 Interpret @var{musicexpr} within a context of type @var{contexttype}. 
2853 If the context does not exist, it will be created.  The new context
2854 can optionally be given a name.  
2855
2856
2857
2858 @c .  {Context definitions}
2859 @node Context definitions
2860 @subsection Context definitions
2861
2862 @cindex context definition
2863 @cindex translator definition
2864 @cindex engraver hacking
2865
2866
2867 A notation contexts is defined by the following information
2868
2869 @enumerate 1
2870   @item  A name.
2871
2872   @item  The LilyPond modules that do the actual conversion of music to
2873        notation.  Each module is a so-called
2874        @emph{engraver}
2875 @cindex engraver
2876 .
2877
2878   @item  How these modules should cooperate, i.e. which ``cooperation
2879        module'' should be used.  This cooperation module is a special
2880        type of engraver.
2881
2882   @item  What other contexts the context can contain,
2883
2884   @item  What properties are defined.
2885 @end enumerate
2886
2887 A context definition has this syntax:
2888
2889 @example
2890
2891   \translator @code{@{}
2892                       @var{translatorinit} @var{translatormodifierlist}
2893                     @code{@}}
2894 @end example
2895
2896 @var{translatorinit} can be an identifier or 
2897 @example
2898   \type @var{typename} @code{;}
2899 @end example
2900 where @var{typename} is one of
2901
2902 @table @code
2903 @cindex @code{Engraver_group_engraver}
2904   @item @code{Engraver_group_engraver}  
2905     The standard cooperation engraver.
2906 @cindex @code{Score_engraver}
2907
2908   @item @code{Score_engraver}  
2909     This is cooperation module that should be in the top level context.
2910 @cindex @code{Grace_engraver_group}
2911
2912   @item @code{Grace_engraver_group}  
2913     This is a special cooperation module (resembling
2914     @code{Score_engraver}) that is used to created an embedded
2915     `miniscore'.
2916 @end table 
2917
2918 @var{translatormodifierlist} is a list of items where each item is
2919 one of
2920
2921 @itemize @bullet
2922   @item  @code{\consists} @var{engravername} @code{;}  
2923     Add @var{engravername} to the list of modules in this context. 
2924   The order of engravers added with @code{\consists} is
2925     significant.
2926   
2927   @item  @code{\consistsend} @var{engravername} @code{;}  
2928     Analogous to @code{\consists}, but makes sure that
2929     @var{engravername} is always added to the end of the list of
2930     engravers.
2931
2932     Some engraver types need to be at the end of the list; this
2933     insures they are put there, and stay there, if a user adds or
2934     removes engravers.  This command is usually not needed for
2935     end-users.
2936     
2937   @item  @code{\accepts} @var{contextname} @code{;}  
2938     Add @var{contextname} to the list of  context this context can
2939     contain.  The first listed context is the context to create by
2940     default.
2941
2942   @item @code{\denies}. The opposite of @code{\accepts}. Added for
2943 completeness, but is never used in practice.
2944  
2945   
2946   @item  @code{\remove} @var{engravername} @code{;}  
2947     Remove a previously added (with @code{\consists}) engraver.
2948   
2949   @item  @code{\name} @var{contextname} @code{;}  
2950     This sets name of the context, e.g. @code{Staff}, @code{Voice}.  If
2951     the name is not specified, the translator won't do anything.
2952
2953   @item  @var{propname} @code{=} @var{value} @code{;}  
2954     A property assignment.
2955 @end itemize
2956
2957 In the @code{\paper} block, it is also possible to define translator
2958 identifiers.  Like other block identifiers, the identifier can only
2959 be used as the very first item of a translator.  In order to define
2960 such an identifier outside of @code{\score}, you must do
2961
2962 @quotation
2963
2964 @example 
2965 \paper @{
2966   foo = \translator @{ @dots{} @}
2967 @}
2968 \score @{
2969   \notes @{
2970     @dots{}
2971   @}
2972   \paper @{
2973     \translator @{ \foo @dots{} @}
2974   @}
2975 @} 
2976 @end example 
2977
2978 @end quotation
2979
2980
2981 @cindex paper types, engravers, and pre-defined translators
2982
2983 Some pre-defined identifiers can simplify modification of
2984 translators.  The pre-defined identifiers are:
2985
2986 @table @code
2987 @cindex @code{StaffContext}
2988   @item @code{StaffContext}  
2989     Default Staff context. 
2990 @cindex @code{RhythmicStaffContext}
2991
2992   @item @code{RhythmicStaffContext}  
2993     Default RhythmicStaff context. 
2994 @cindex @code{VoiceContext}
2995
2996   @item @code{VoiceContext}  
2997     Default Voice context.  
2998 @cindex @code{ScoreContext}
2999
3000   @item @code{ScoreContext}  
3001     Default Score context. 
3002
3003 @cindex @code{HaraKiriStaffContext}
3004
3005   @item @code{HaraKiriStaffContext}  
3006     Staff context that does not print if it only contains rests. 
3007     Useful for orchestral scores.@footnote{Harakiri, also called
3008     Seppuku, is the ritual suicide of the Japanese Samourai warriors.}
3009
3010 @end table
3011
3012 Using these pre-defined values, you can remove or add items to the
3013 translator:
3014
3015 @quotation
3016
3017 @example 
3018 \paper @{
3019   \translator @{
3020     \StaffContext
3021     \remove Some_engraver;
3022     \consists Different_engraver;
3023   @}
3024 @} 
3025 @end example 
3026
3027 @end quotation
3028
3029       
3030
3031
3032 @c .  {Notation Contexts}
3033 @node Notation Contexts
3034 @subsection Notation Contexts
3035
3036 @cindex notation contexts
3037
3038 Notation contexts are objects that only exist during a run of
3039 LilyPond.  During the interpretation phase of LilyPond, the Music
3040 expression contained in a @code{\score} block is interpreted in time
3041 order.  This is the order in which humans read, play, and write
3042 music.
3043
3044 A context is an object that holds the reading state of the
3045 expression; it contains information like
3046
3047 @itemize @bullet
3048   @item What notes are playing at this point?
3049   @item What symbols will be printed at this point?
3050   @item In what style will they printed?
3051   @item What is the current key signature, time signature, point within
3052        the measure, etc.?
3053 @end itemize
3054
3055 Contexts are grouped hierarchically: A @code{Voice} context is
3056 contained in a @code{Staff} context (because a staff can contain
3057 multiple voices at any point), a @code{Staff} context is contained in
3058 a @code{Score}, @code{StaffGroup}, or @code{ChoirStaff} context (because
3059 these can all contain multiple staffs).
3060
3061 Contexts associated with sheet music output are called @emph{notation
3062 contexts}, those for sound output are called performance contexts.
3063
3064 Contexts are created either manually or automatically.  Initially, the
3065 top level music expression is interpreted by the top level context (the
3066 @code{Score} context).  When a atomic music expression (i.e. a note, a
3067 rest, etc.), a nested set of contexts is created that can process these
3068 atomic expressions, as in this example:
3069
3070 @example
3071 \score @{ \notes @{ c4 @} @} 
3072 @end example 
3073
3074 The sequential music, `@code{@{ c4 @}}' is interpreted by @code{Score}
3075 context. When the note @code{c4} itself is interpreted, a set of
3076 contexts is needed that will accept notes.  The default for this is a
3077 @code{Voice} context, contained in a @code{Staff} context.  Creation of
3078 these contexts results in the staff being printed.
3079
3080 @cindex context
3081
3082 You can also create contexts manually, and you probably have to do so
3083 if you want to typeset complicated multiple part material.  If a
3084 `@code{\context} @var{name} @var{musicexpr}' expression is encountered
3085 during the interpretation phase, the @var{musicexpr} argument will be
3086 interpreted with a context of type @var{name}.  If you specify a name,
3087 the specific context with that name is searched.
3088
3089 [type vs id]
3090
3091 If a context of the specified type and name can not be found, a new
3092 one is created.  For example,
3093
3094 @quotation
3095
3096 @lilypond[verbatim]
3097 \score {
3098   \notes \relative c'' {
3099     c4 <d4 \context Staff = "another" e4> f
3100   }
3101 }
3102
3103 @end lilypond
3104 @end quotation
3105
3106 In this example, the @code{c} and @code{d} are printed on the
3107 default staff.  For the @code{e}, a context Staff called
3108 @code{another} is specified; since that does not exist, a new
3109 context is created.  Within @code{another}, a (default) Voice context
3110 is created for the @code{e4}.  When all music referring to a
3111 context is finished, the context is ended as well.  So after the
3112 third quarter, @code{another} is removed.
3113
3114 Almost all music expressions inherit their interpretation context
3115 from their parent.  In other words, suppose that the syntax for a
3116 music expression is
3117
3118 @example
3119
3120   \keyword @var{musicexpr1} @var{musicexpr2} @dots{}
3121 @end example
3122
3123 When the interpretation of this music expression starts, the context
3124 for @var{musicexpr1}, @var{musicexpr2}, etc. is that of the total
3125 expression.
3126
3127 Lastly, you may wonder, why this:
3128
3129 @quotation
3130
3131 @example 
3132 \score @{
3133   \notes \relative c'' @{
3134     c4 d4 e4
3135   @}
3136 @} 
3137 @end example 
3138
3139 @end quotation
3140
3141 doesn't result in this:
3142
3143 @lilypond[]
3144
3145   \score {
3146     \notes \relative c'' {
3147       <c4> <d4> <e4>
3148     }
3149   }
3150
3151 @end lilypond
3152
3153 For the @code{c4}, a default @code{Staff} (with a contained
3154 @code{Voice}) context is created.  After the @code{c4} ends, no
3155 music refers to this default staff, so it would be ended, with the
3156 result shown.  To prevent this inconvenient behavior, the context to
3157 which the sequential music refers is adjusted during the
3158 interpretation.  So after the @code{c4} ends, the context of the
3159 sequential music is also the default @code{Voice} context. 
3160 The @code{d4} gets interpreted in the same context
3161 as @code{c4}.
3162
3163 Properties that are set in one context are inherited by all of the
3164 contained contexts.  This means that a property valid for the
3165 @code{Voice} context can be set in the @code{Score} context (for
3166 example) and thus take effect in all @code{Voice} contexts.
3167
3168 Properties can be preset within the @code{\translator} block
3169 corresponding to the appropriate context.  In this case, the syntax
3170 is
3171
3172 @example
3173   @var{propname} @code{=} @var{value}
3174 @end example
3175
3176 This assignment happens before interpretation starts, so a
3177 @code{\property} expression will override any predefined settings.
3178
3179 The property settings are used during the interpretation phase.  They
3180 are read by the LilyPond modules where interpretation contexts are
3181 built of.  These modules are called @emph{translators}.  Translators for
3182 notation are called @emph{engravers}, and translators for sound are
3183 called @emph{performers}.
3184
3185
3186
3187 @c . {Syntactic details}
3188 @node Syntactic details
3189 @section Syntactic details
3190 @cindex Syntactic details
3191 @menu
3192 * Top level::                   
3193 * Identifiers::                 
3194 * Music expressions::           
3195 * Assignments::                 
3196 * Lexical details::             
3197 * Lexical modes::               
3198 * Ambiguities::                 
3199 @end menu
3200
3201 @c .  {Top level}
3202 @node Top level
3203 @subsection Top level
3204 @cindex Top level
3205
3206 This section describes what you may enter at top level.
3207
3208
3209 @unnumberedsubsec Score definition
3210 @cindex score definition
3211
3212 The output is generated combining a music expression with an output
3213 definition.  A score block has the following syntax:
3214
3215 @example
3216   \score @{ @var{musicexpr} @var{outputdefs} @}
3217 @end example
3218
3219 @var{outputdefs} are zero or more output definitions.  If no output
3220 definition is supplied, the default @code{\paper} block will be added.
3221
3222
3223 @c .   {Score}
3224 @subsubsection Score
3225 @cindex Score
3226
3227 @c .   {Paper}
3228 @subsubsection Paper
3229 @cindex Paper
3230
3231 @c .   {Midi}
3232 @subsubsection Midi
3233 @cindex Midi
3234
3235 @c .   {Header}
3236 @subsubsection Header
3237 @cindex Header
3238 @cindex @code{\header}
3239
3240 The syntax is
3241
3242 @example
3243   \header @{ @var{key1} = @var{val1};
3244 @cindex @code{ly2dvi}
3245              @var{key2} = @var{val2}; @dots{} @}
3246 @end example
3247
3248
3249 A header describes the file's contents.  It can also appear in a
3250 @code{\score} block.  Tools like @code{ly2dvi} can use this
3251 information for generating titles.  Key values that are used by
3252 @code{ly2dvi} are: title, subtitle, composer, opus, poet, instrument,
3253 metre, arranger, piece and tagline.
3254
3255 It is customary to put the @code{\header} at the top of the file.
3256
3257 @subsubsection Default output
3258
3259 A @code{\midi} or @code{\paper} block at top-level sets the default
3260
3261 paper block for all scores that lack an explicit paper block.
3262
3263 @c .  {Identifiers}
3264 @node Identifiers
3265 @subsection Identifiers
3266 @cindex  Identifiers
3267
3268 All of the information in a LilyPond input file, is represented as a
3269 Scheme value. In addition to normal Scheme data types (such as pair,
3270 number, boolean, etc.), LilyPond has a number of specialized data types,
3271
3272 @itemize @bullet
3273 @item Input
3274 @item c++-function
3275 @item Music
3276 @item Identifier
3277 @item Translator_def
3278 @item Duration
3279 @item Pitch
3280 @item Score
3281 @item Music_output_def
3282 @item Moment (rational number)
3283 @end itemize
3284
3285 LilyPond also includes some transient object types. Objects of these
3286 types are built during a LilyPond run, and do not `exist' per se within
3287 your input file. These objects are created as a result of your input
3288 file, so you can include commands in the input to manipulate them,
3289 during a lilypond run.
3290
3291 @itemize @bullet
3292 @item Grob: short for Graphical object. See @ref{Grobs}. 
3293 @item Molecule: device-independent page output object,
3294 including dimensions.  Produced by some Grob functions
3295 See @ref{Molecules}
3296 @item Translator: object that produces audio objects or Grobs. This is
3297 not yet user accessible.
3298 @item Font_metric: object representing a font. (See @ref{Font metrics})
3299
3300 @end itemize
3301
3302
3303 @node Music expressions
3304 @subsection Music expressions
3305
3306 @cindex music expressions
3307
3308 Music in LilyPond is entered as a music expression.  Notes, rests, lyric
3309 syllables are music expressions, and you can combine music expressions
3310 to form new ones, for example by enclosing a list of expressions in
3311 @code{\sequential @{ @}} or @code{< >}.  In this example, a compound
3312 expression is formed out of the quarter note @code{c} and a quarter note
3313 @code{d}:
3314
3315 @example 
3316 \sequential @{ c4 d4 @} 
3317 @end example 
3318
3319 @cindex Sequential music
3320 @cindex @code{\sequential}
3321 @cindex sequential music
3322 @cindex @code{<}
3323 @cindex @code{>}
3324 @cindex Simultaneous music
3325 @cindex @code{\simultaneous}
3326
3327 The two basic compound  music expressions are simultaneous  and
3328 sequential music.
3329
3330 @example
3331   \sequential @code{@{} @var{musicexprlist} @code{@}}
3332   \simultaneous @code{@{} @var{musicexprlist} @code{@}}
3333 @end example
3334 For both, there is a shorthand:
3335 @example
3336   @code{@{} @var{musicexprlist} @code{@}}
3337 @end example
3338 for sequential and
3339 @example
3340   @code{<} @var{musicexprlist} @code{>}
3341 @end example
3342 for simultaneous music.
3343 Other compound music expressions include
3344 @example
3345  \repeat @var{expr}
3346  \transpose @var{pitch} @var{expr}
3347  \apply @var{func} @var{expr}
3348  \context @var{type} = @var{id} @var{expr}
3349  \times @var{fraction} @var{expr}
3350 @end example
3351
3352 In principle, the way in which you nest sequential and simultaneous to
3353 produce music is not relevant.  In the following example, three chords
3354 are expressed in two different ways:
3355
3356 @lilypond[fragment,verbatim,center]
3357   \notes \context Voice {
3358     <a c'> <b  d' > <c' e'>
3359     < { a b  c' } { c' d' e' } >
3360   }
3361 @end lilypond
3362
3363 However, in some cases, LilyPond will also try to choose contexts, and
3364 use the structure of the music expression  to do so. This can have
3365 undesired effects: for example, LilyPond will create a separate staff
3366 for each note if you start a @code{\score} with a  chord:
3367 @lilypond[verbatim,center]
3368   \score {
3369     \notes <c''4 e''>
3370     \paper {
3371       linewidth = -1.;
3372     }
3373   }
3374 @end lilypond
3375   The solution is to explicitly instantiate the context you desire.
3376 In this case this is typically a Voice context
3377 @lilypond[verbatim,center]
3378   \score {
3379     \notes\context Voice <c''4 e''>
3380     \paper {
3381       linewidth = -1.;
3382     }
3383   }
3384 @end lilypond
3385 If you use @code{\context Staff} you will get separate stems for each
3386 note head, leading to collisions, so don't use that.
3387
3388
3389
3390 @c .   {Assignments}
3391 @node Assignments
3392 @subsection Assignments
3393 @cindex Assignments
3394
3395 Identifiers allow objects to be assigned to names during the parse
3396 stage.  To assign an identifier, you use @var{name}@code{=}@var{value}
3397 and to refer to an identifier, you preceed its name with a backslash:
3398 `@code{\}@var{name}'.  @var{value} is any valid Scheme value or any of
3399 the input-types listed above.  Identifier assignments can appear at top
3400 level in the LilyPond file, but also in @code{\paper} blocks.
3401
3402 Semicolons are forbidden after top level assignments, but mandatory in
3403 other places. The rules about semicolons and assignments are very
3404 confusing, but when LilyPond input evolves more towards Scheme, we hope
3405 that this problem will grow smaller.
3406
3407 An identifier can be created with any string for its name, but you will
3408 only be able to refer to identifiers whose names begin with a letter,
3409 being entirely alphabetical.  It is impossible to refer to an identifier
3410 whose name is the same as the name of a keyword.
3411
3412 The right hand side of an identifier assignment is parsed completely
3413 before the assignment is done, so it is allowed to redefine an
3414 identifier in terms of its old value, e.g.
3415
3416 @example
3417 foo = \foo * 2.0
3418 @end example
3419
3420 When an identifier is referenced, the information it points to is
3421 copied.  For this reason, an identifier reference must always be the
3422 first item in a block.
3423 @example
3424 \paper  @{
3425         foo = 1.0
3426         \paperIdent % wrong and invalid
3427 @}
3428
3429 \paper @{
3430         \paperIdent % correct
3431         foo = 1.0 @}
3432 @end example
3433
3434 @c .  {Lexical details}
3435 @node Lexical details
3436 @subsection Lexical details
3437 @cindex Lexical details
3438 @menu
3439 @end menu
3440
3441 @c .   {Comments}
3442 @subsubsection Comments
3443 @cindex Comments
3444
3445 @cindex @code{%}
3446
3447
3448 A one line comment is introduced by a @code{%} character. 
3449 Block comments are started by @code{%@{} and ended by @code{%@}}. 
3450 They cannot be nested.
3451
3452 @c .  {Direct Scheme}
3453 @subsubsection Direct Scheme
3454 @cindex Scheme
3455 @cindex GUILE
3456 @cindex Scheme, in-line code
3457
3458
3459 LilyPond contains a Scheme interpreter (the GUILE library) for
3460 internal use. In some places Scheme expressions also form valid syntax:
3461 whereever it is allowed,
3462 @example
3463   #@var{scheme}
3464 @end example
3465 evaluates the specified Scheme code. If this is used at toplevel, then
3466 the result is discarded. Example:
3467 @example
3468   \property Staff.TestObject \override #'foobar =  #(+ 1 2)
3469 @end example
3470
3471 @code{\override} expects two Scheme expressions, so there are two Scheme
3472 expressions. The first one is a symbol (@code{foobar}), the second one
3473 an integer (namely, 3).
3474
3475 Scheme is a full-blown programming language, and a full discussion is
3476 outside the scope of this document. Interested readers are referred to
3477 the website @uref{http://www.schemers.org/} for more information on
3478 Scheme.
3479
3480
3481 @c .   {Keywords}
3482 @subsubsection Keywords
3483 @cindex Keywords
3484
3485
3486 Keywords start with a backslash, followed by a number of lower case
3487 alphabetic characters.  These are all the keywords.
3488
3489 @example
3490 apply arpeggio autochange spanrequest commandspanrequest
3491 simultaneous sequential accepts alternative bar breathe
3492 char chordmodifiers chords clef cm consists consistsend
3493 context denies duration dynamicscript elementdescriptions
3494 font grace header in lyrics key mark pitch
3495 time times midi mm name pitchnames notes outputproperty
3496 override set revert partial paper penalty property pt
3497 relative remove repeat addlyrics partcombine score
3498 script stylesheet skip textscript tempo translator
3499 transpose type
3500 @end example
3501
3502 @c .   {Integers}
3503 @subsubsection Integers
3504
3505 @cindex integers
3506 @cindex @code{+}
3507 @cindex @code{-}
3508 @cindex @code{*}
3509 @cindex @code{/}
3510
3511 Formed from an optional minus sign followed by digits.  Arithmetic
3512 operations cannot be done with integers, and integers cannot be mixed
3513 with reals.
3514
3515 @c .   {Reals}
3516 @subsubsection Reals
3517 @cindex real numbers
3518
3519
3520
3521
3522
3523 Formed from an optional minus sign and a sequence of digits followed
3524 by a @emph{required} decimal point and an optional exponent such as
3525 @code{-1.2e3}.  Reals can be built up using the usual operations:
3526 `@code{+}', `@code{-}', `@code{*}', and
3527 `@code{/}', with parentheses for grouping.
3528
3529 @cindex @code{\mm},
3530 @cindex @code{\in}
3531 @cindex @code{\cm}
3532 @cindex @code{\pt}
3533 @cindex dimensions
3534
3535 A real constant can be followed by one of the dimension keywords:
3536 @code{\mm} @code{\pt}, @code{\in}, or @code{\cm}, for millimeters,
3537 points, inches and centimeters, respectively.  This converts the number
3538 to a real that is the internal representation of dimensions.
3539
3540
3541 @c .   {Strings}
3542 @subsubsection Strings
3543 @cindex string
3544 @cindex concatenate
3545
3546 Begins and ends with the @code{"} character.  To include a @code{"}
3547 character in a string write @code{\"}.  Various other backslash
3548 sequences have special interpretations as in the C language.  A string
3549 that contains no spaces can be written without the quotes.  See
3550 @ref{Lexical modes} for details on unquoted strings; their
3551 interpretation varies depending on the situation.  Strings can be
3552 concatenated with the @code{+} operator.
3553
3554 The tokenizer accepts the following commands. They have no grammatical
3555 function, hence they can appear anywhere in the input.
3556
3557
3558 @c .   {Main input}
3559 @subsubsection Main input
3560 @cindex Main input
3561
3562 @cindex @code{\maininput}
3563
3564 The @code{\maininput} command is used in init files to signal that the
3565 user file must be read. This command cannot be used in a user file.
3566
3567 @c .   {File inclusion}
3568 @subsubsection Main input
3569 @cindex Main input
3570
3571 @subsubsection File inclusion
3572 @cindex @code{\include}
3573 @example
3574   \include @var{filename}
3575 @end example
3576
3577 Include @var{filename}.  The argument @var{filename} may be a quoted string (an
3578 unquoted string will not work here!) or a string identifier.  The full
3579 filename including the @file{.ly} extension must be given,
3580
3581 @subsubsection Version information 
3582 @cindex @code{\version}
3583 @example
3584   \version @var{string} ;
3585 @end example
3586
3587 Specify the version of LilyPond that a file was written for.  The
3588 argument is a version string in quotes, for example @code{"1.2.0"}. 
3589 This is used to detect invalid input, and to aid
3590 @code{convert-ly}  a tool that automatically upgrades input files. See
3591 See @ref{convert-ly} for more information on @code{convert-ly}.
3592
3593 @cindex convert-ly
3594
3595
3596 @c .   {Pitch names}
3597 @subsubsection Defining pitch names
3598 @cindex Lexical modes
3599 @cindex definining pitch names
3600 @cindex pitch names, definining
3601 @cindex note names
3602 @cindex chord modifier names
3603
3604 A @code{\paper} block at top level sets the default paper block.  A
3605 @code{\midi} block at top level works similarly.
3606
3607 @c .   {Assignments}
3608 @subsubsection Assignments
3609 @cindex assignments
3610 @cindex @code{#}
3611
3612 Identifier assignments may appear at top level.  @ref{Assignments}
3613
3614
3615
3616 @c .    {Direct scheme}
3617 @subsubsection Direct scheme
3618 @cindex Direct scheme
3619
3620 Scheme statements maybe issued to produce interesting side-effects. 
3621
3622
3623 @c .  {Lexical modes}
3624 @node Lexical modes
3625 @subsection Lexical modes
3626 @cindex Lexical modes
3627 @cindex input mode
3628 @cindex mode, input 
3629 @cindex @code{\notes}
3630 @cindex @code{\chords}
3631 @cindex @code{\lyrics}
3632
3633 To simplify entering notes, lyrics, and chords, LilyPond has three
3634 special input modes on top of the default mode: note, lyrics and chords
3635 mode.  These input modes change the way that normal, unquoted words are
3636 interpreted: for example, the word @code{cis} may be interpreted as a
3637 C-sharp, as a lyric syllable `cis' or as a C-sharp major triad
3638 respectively.
3639
3640 A mode switch is entered as a compound music expressions
3641 @example
3642 @code{\notes} @var{musicexpr}
3643 @code{\chords} @var{musicexpr}
3644 @code{\lyrics}  @var{musicexpr}.
3645 @end example
3646
3647 In each of these cases, these expressions do not add anything to the
3648 meaning of their arguments.  They are just a way to indicate that the
3649 arguments should be parsed in indicated mode.  The modes are treated in
3650 more detail in the sections @ref{Note entry}, @ref{Lyrics} and
3651 @ref{Chords}.
3652
3653 You may nest different input modes.
3654
3655 @c .  {Ambiguities}
3656 @node Ambiguities
3657 @subsection Ambiguities
3658 @cindex ambiguities
3659 @cindex grammar
3660
3661
3662 The grammar contains a number of ambiguities. We hope to resolve them at
3663 some time.
3664
3665 @itemize @bullet
3666   @item  The assignment
3667
3668          @example 
3669 foo = bar 
3670 @end example 
3671
3672        can be interpreted as making a string identifier @code{\foo}
3673        containing @code{"bar"}, or a music identifier @code{\foo}
3674        containing the syllable `bar'.
3675
3676   @item  The assignment
3677
3678          @example 
3679 foo = -6 
3680 @end example 
3681
3682        can be interpreted as making an integer identifier
3683        containing -6, or a Request identifier containing the
3684        fingering `6' (with neutral direction).
3685
3686   @item  If you do a nested repeat like
3687
3688        @quotation
3689
3690 @example 
3691 \repeat @dots{}
3692 \repeat @dots{}
3693 \alternative 
3694 @end example 
3695
3696        @end quotation
3697
3698        then it is ambiguous to which @code{\repeat} the
3699        @code{\alternative} belongs.  This is the classic if-then-else
3700        dilemma.  It may be solved by using braces.
3701
3702   @item  (an as yet unidentified ambiguity :-)
3703 @end itemize
3704
3705
3706
3707
3708 @c . {Unsorted}
3709 @node Unsorted
3710 @section Unsorted
3711
3712 [mucho todo]
3713
3714 Translation?
3715
3716 @cindex properties
3717 @unnumberedsubsec Translation property
3718
3719 [todo: add \set/\override/\revert]
3720
3721
3722 @cindex @code{\property}
3723 @example
3724   \property @var{contextname}.@var{propname} =  @var{value}
3725 @end example
3726
3727 Sets the @var{propname} property of the context @var{contextname} to
3728 the specified @var{value}.  All three arguments are strings. 
3729 Depending on the context, it may be necessary to quote the strings or
3730 to leave space on both sides of the dot.
3731
3732
3733 @cindex output properties
3734 @unnumberedsubsec Output properties
3735
3736 These allow you to tweak what is happening in the back-end
3737 directly. If you want to control every detail of the output
3738 formatting, this is the feature to use. The downside to this is that
3739 you need to know exactly how the backend works. Example:
3740
3741
3742 @lilypond[fragment,verbatim]
3743 \relative c'' { c4
3744   \context Staff \outputproperty
3745   #(make-type-checker 'note-head-interface)
3746   #'extra-offset = #'(0.5 . 0.75)
3747   <c8 e g> }
3748 @end lilypond
3749
3750 This selects all note heads occurring at current staff level, and sets
3751 the @code{extra-offset} of those heads to @code{(0.5,0.75)}, shifting
3752 them up and right.
3753
3754 Use of this feature is entirely on your own risk: if you use this, the
3755 result will depend very heavily on the implementation of the backend,
3756 which we change regularly and unscrupulously.
3757
3758
3759 Don't move the finger 2, only text "m.d." ...
3760 @lilypond[verbatim]
3761 #(define (make-text-checker text)
3762    (lambda (grob) (equal? text (ly-get-elt-property grob 'text))))
3763
3764 \score {    
3765   \notes\relative c''' {
3766     \property Voice.Stem \set #'direction = #1
3767     \outputproperty #(make-text-checker "m.d.")
3768       #'extra-offset = #'(-3.5 . -4.5)
3769     a^2^"m.d."    
3770   }
3771   \paper { linewidth = -1.; }
3772 }
3773 @end lilypond
3774
3775
3776
3777
3778
3779 @c .{Local emacs vars}
3780 @c Local variables:
3781 @c mode: texinfo
3782 @c minor-mode: font-lock
3783 @c minor-mode: outline
3784 @c outline-layout: (-1 : 0)
3785 @c outline-use-mode-specific-leader: "@c \."
3786 @c outline-primary-bullet: "{"
3787 @c outline-stylish-prefixes: nil
3788 @c outline-override-protect: t
3789 @c End:
3790