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