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