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