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