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