]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/advanced-notation.itely
Minor fixes.
[lilypond.git] / Documentation / user / advanced-notation.itely
1 @c -*- coding: latin-1; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3
4 @c A menu is needed before every deeper *section nesting of @node's; run 
5 @c     M-x texinfo-all-menus-update
6 @c to automatically fill in these menus before saving changes
7
8
9 @node Advanced notation
10 @chapter Advanced notation
11
12 This chapter deals with rarely-used and advanced notation.
13
14 @menu
15 * Text::                        
16 * Even more than notes::        
17 * Preparing parts::             
18 * Orchestral music::            
19 * Contemporary notation::       
20 * Educational use::             
21 * Automatic notation::          
22 @end menu
23
24
25 @node Text
26 @section Text
27
28 This section explains how to include text (with various formatting) in
29 your scores.
30
31 @menu
32 * Text scripts::                
33 * Text spanners::               
34 * Text markup::                 
35 * Text encoding::               
36 * Nested scores::               
37 * Overview of text markup commands::  
38 * New dynamic marks::           
39 * Other text markup issues::    
40 @end menu
41
42
43 @node Text scripts
44 @subsection Text scripts
45 @cindex Text scripts
46
47 @cindex text items, non-empty
48 @cindex non-empty texts
49
50 It is possible to place arbitrary strings of text or markup text (see
51 @ref{Text markup}) above or below notes by using a string
52 @code{c^"text"}.  By default, these indications do not influence the
53 note spacing, but by using the command @code{\fatText}, the widths
54 will be taken into account
55
56 @lilypond[quote,fragment,raggedright,verbatim,relative=1]
57 c4^"longtext" \fatText c4_"longlongtext" c4
58 @end lilypond
59
60 More complex formatting may also be added to a note by using the
61 markup command,
62 @lilypond[fragment,raggedright,verbatim,quote]
63 c'4^\markup { bla \bold bla }
64 @end lilypond
65
66 The @code{\markup} is described in more detail in
67 @ref{Text markup}.
68
69
70 @refcommands
71
72 @cindex @code{\fatText}
73 @code{\fatText},
74 @cindex @code{\emptyText}
75 @code{\emptyText}.
76
77 @seealso
78
79 In this manual: @ref{Text markup}.
80
81 Program reference: @internalsref{TextScriptEvent}, @internalsref{TextScript}.
82
83
84 @node Text spanners
85 @subsection Text spanners
86 @cindex Text spanners
87
88 Some performance indications, e.g., @i{rallentando} or @i{accelerando},
89 are written as text and are extended over many measures with dotted
90 lines.  Such texts are created using text spanners; attach
91 @code{\startTextSpan} and @code{\stopTextSpan} to the first and last
92 notes of the spanner.
93
94 The string to be printed, as well as the style, is set through object
95 properties
96
97 @lilypond[quote,raggedright,fragment,relative=1,verbatim]
98 c1
99 \textSpannerDown
100 \override TextSpanner #'edge-text = #'("rall " . "")
101 c2\startTextSpan b c\stopTextSpan a
102 @end lilypond
103
104 @refcommands
105
106 @cindex textSpannerUp
107 @code{textSpannerUp},
108 @cindex textSpannerDown 
109 @code{textSpannerDown},
110 @cindex textSpannerNeutral
111 @code{textSpannerNeutral}.
112
113 @seealso
114
115 Internals @internalsref{TextSpanEvent},
116 @internalsref{TextSpanner}.
117
118 Examples: @inputfileref{input/@/regression,text@/-spanner@/.ly}.
119
120
121 @node Text markup
122 @subsection Text markup
123 @cindex text markup
124 @cindex markup text
125
126 @cindex typeset text
127
128 The internal mechanism to typeset texts is accessed with the keyword
129 @code{\markup}.  Within markup mode, you can enter texts similar to
130 lyrics.  They are simply entered, while commands use the backslash @code{\}.
131 @cindex markup
132
133 @lilypond[quote,verbatim,fragment,relative=1]
134 c1^\markup { hello }
135 c1_\markup { hi there }
136 c1^\markup { hi \bold there, is \italic anyone home? }
137 @end lilypond
138
139 @cindex font switching
140
141 The markup in the example demonstrates font switching commands.  The
142 command @code{\bold} and @code{\italic} apply to the first following 
143 word only; enclose a set of texts with braces to apply a command
144 to more words:
145 @example
146 \markup @{ \bold @{ hi there @} @}
147 @end example
148
149 @noindent
150 For clarity, you can also do this for single arguments, e.g.,
151
152 @example
153 \markup @{ is \italic @{ anyone @} home @}
154 @end example
155
156 @cindex font size, texts
157
158
159 In markup mode you can compose expressions, similar to mathematical
160 expressions, XML documents, and music expressions.  You can stack
161 expressions grouped vertically with the command @code{\column}.
162 Similarly, @code{\center-align} aligns texts by their center lines:
163
164 @lilypond[quote,verbatim,fragment,relative=1]
165 c1^\markup { \column { a bbbb \line { c d } } }
166 c1^\markup { \center-align { a bbbb c } }
167 c1^\markup { \line { a b c } }
168 @end lilypond
169
170
171 Markups can be stored in variables and these variables
172 may be attached to notes, like
173 @example
174 allegro = \markup @{ \bold \large @{ Allegro @} @}
175  @{ a^\allegro b c d @}
176 @end example
177
178
179 Some objects have alignment procedures of their own, which cancel out
180 any effects of alignments applied to their markup arguments as a
181 whole.  For example, the @internalsref{RehearsalMark} is horizontally
182 centered, so using @code{\mark \markup @{ \left-align .. @}} has no
183 effect.
184
185
186 @seealso
187
188 Program reference: @internalsref{TextScriptEvent}, @internalsref{TextScript}.
189
190 Init files: @file{scm/@/new@/-markup@/.scm}.
191
192 @refbugs
193
194 Kerning or generation of ligatures is only done when the @TeX{}
195 backend is used.  In this case, LilyPond does not account for them so
196 texts will be spaced slightly too wide.
197
198 Syntax errors for markup mode are confusing.
199
200
201 @node Text encoding
202 @subsection Text encoding
203
204 LilyPond uses the Pango library to format multi-lingual texts, and
205 does not perform any input-encoding conversions.  This means that any
206 text, be it title, lyric text, or musical instruction containing
207 non-ASCII characters, must be utf-8.  Easiest to enter such texts is
208 by using a Unicode-aware editor, and save using utf-8 encoding.  Most
209 popular modern editors have utf-8 support, for example, vim, Emacs,
210 jEdit, and GEdit do.
211
212 Depending on the fonts installed, the following fragment shows Hebrew
213 and Cyrillic lyrics,
214
215 @cindex Cyrillic
216 @cindex Hebrew
217 @cindex ASCII, non
218
219 @lilypondfile[fontload]{utf-8.ly}
220
221
222 The @TeX{} backend does not handle encoding specially at all.  Strings
223 in the input are put in the output as-is.  Extents of text items in the
224 @TeX{} backend, are determined by reading a file created via the
225 @file{texstr} backend,
226
227 @example
228 lilypond -b texstr input/les-nereides.ly
229 latex les-nereides.texstr
230 @end example
231
232 The last command produces @file{les-nereides.textmetrics}, which is
233 read when you execute
234
235 @example
236 lilypond -b tex input/les-nereides.ly
237 @end example
238
239 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
240 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
241 interpreting non-ASCII strings.
242
243 @seealso
244
245 @inputfileref{input/regression,utf-8.ly}
246
247
248 @node Nested scores
249 @subsection Nested scores
250
251 It is possible to nest music inside markups, by adding a @code{\score}
252 block to a markup expression.  Such a score must contain a @code{\layout}
253 block.
254
255 @lilypond[quote,verbatim,raggedright]
256 \relative {
257   c4 d^\markup {
258     \score {
259       \relative { c4 d e f }
260       \layout { }
261     }
262   }
263   e f
264 }
265 @end lilypond
266  
267
268
269 @node Overview of text markup commands
270 @subsection Overview of text markup commands
271
272 The following commands can all be used inside @code{\markup @{ @}}.
273
274 @include markup-commands.tely
275
276
277 @node New dynamic marks
278 @subsection New dynamic marks
279
280 It is possible to print new dynamic marks or text that should be aligned
281 with dynamics.  Use @code{make-dynamic-script} to create these marks.
282
283 @cindex make-dynamic-script
284
285 @lilypond[quote,verbatim,raggedright]
286 sfzp = #(make-dynamic-script "sfzp")
287 \relative c' {
288   c4 c c\sfzp c
289 }
290 @end lilypond
291
292 @cindex Dynamics, editorial
293 @cindex Dynamics, parenthesis
294
295 It is also possible to print dynamics in round parenthesis or square
296 brackets.  These are often used for adding editorial dynamics.
297
298 @lilypond[quote,verbatim,raggedright]
299 rndf = \markup{ \center-align {\line { \bold{\italic (}
300   \dynamic f \bold{\italic )} }} }
301 boxf = \markup{ \bracket { \dynamic f } }
302 { c'1_\rndf c'1_\boxf }
303 @end lilypond
304
305
306 @node Other text markup issues
307 @subsection Other text markup issues
308
309 To use a normal font within a title, you must define it manually
310
311 @example
312 #(def-markup-command (normal-font layout props arg) (markup?)
313   "Switch to normal text font"
314   (interpret-markup layout (cons '((font-series . 'medium) (font-shape . 'upright)) props) arg))
315
316 \header@{
317   title = \markup@{ ABCD \normal-font ABCD @}
318 @}
319 @end example
320
321
322 @c  really bad section name.  :(
323 @node Even more than notes
324 @section Even more than notes
325
326 @menu
327 * Transpose::                   
328 * Ottava brackets::             
329 * Multi measure rests::         
330 * Time administration::         
331 @end menu
332
333
334
335 @node Transpose
336 @subsection Transpose
337 @cindex Transpose
338 @cindex transposition of pitches
339 @cindex @code{\transpose}
340
341 A music expression can be transposed with @code{\transpose}.  The
342 syntax is
343 @example
344 \transpose @var{from} @var{to} @var{musicexpr}
345 @end example
346
347 This means that @var{musicexpr} is transposed by the interval between
348 the pitches @var{from} and @var{to}: any note with pitch @code{from}
349 is changed to @code{to}.
350
351
352 For example, consider a piece written in the key of D-major.  If
353 this piece is a little too low for its performer, it can be
354 transposed up to E-major with
355 @example
356 \transpose d e @dots{}
357 @end example
358
359 Consider a part written for violin (a C instrument).  If
360 this part is to be played on the A clarinet, the following
361 transposition will produce the appropriate part
362
363 @example
364 \transpose a c @dots{}
365 @end example
366
367 @code{\transpose} distinguishes between enharmonic pitches: both
368 @code{\transpose c cis} or @code{\transpose c des} will transpose up
369 half a tone.  The first version will print sharps and the second
370 version will print flats
371
372 @lilypond[quote,raggedright,verbatim]
373 mus = { \key d \major cis d fis g }
374 \context Staff {
375   \clef "F" \mus
376   \clef "G"
377   \transpose c g' \mus
378   \transpose c f' \mus
379 }
380 @end lilypond
381
382 @code{\transpose} may also be used to input written notes for a
383 transposing instrument.  Pitches are normally entered into LilyPond
384 in C (or ``concert pitch''), but they may be entered in another
385 key.  For example, when entering music for a B-flat trumpet which
386 begins on concert D, one would write
387
388 @example
389 \transpose c bes @{ e4 @dots{} @}
390 @end example
391
392 To print this music in B-flat again (ie producing a trumpet part,
393 instead of a concert pitch conductor's score) you would wrap the
394 existing music with another @code{transpose}
395
396 @example
397 \transpose bes c @{ \transpose c bes @{ e4 @dots{} @} @}
398 @end example
399
400
401
402 @seealso
403
404 Program reference: @internalsref{TransposedMusic}, and
405 @internalsref{UntransposableMusic}.
406
407 @refbugs
408
409 If you want to use both @code{\transpose} and @code{\relative},
410 you must put @code{\transpose} outside of @code{\relative}, since
411 @code{\relative} will have no effect music that appears inside a
412 @code{\transpose}.
413
414
415 @node Ottava brackets
416 @subsection Ottava brackets
417
418 `Ottava' brackets introduce an extra transposition of an octave for
419 the staff.  They are created by invoking the function
420 @code{set-octavation}
421
422 @cindex ottava
423 @cindex 15ma
424 @cindex octavation
425
426 @lilypond[quote,raggedright,verbatim,fragment]
427 \relative c''' {
428   a2 b
429   #(set-octavation 1)
430   a b
431   #(set-octavation 0)
432   a b
433 }
434 @end lilypond
435
436 The @code{set-octavation} function also takes -1 (for 8va bassa) and 2
437 (for 15ma) as arguments.  Internally the function sets the properties
438 @code{ottavation} (e.g., to @code{"8va"}) and
439 @code{centralCPosition}.  For overriding the text of the bracket, set
440 @code{ottavation} after invoking @code{set-octavation}, i.e.,
441
442 @lilypond[quote,raggedright,verbatim]
443 {
444   #(set-octavation 1)
445   \set Staff.ottavation = #"8"
446   c'''
447 }
448 @end lilypond
449
450 @seealso
451
452 Program reference: @internalsref{OttavaBracket}.
453
454 Examples: @inputfileref{input/@/regression,ottava@/.ly},
455 @inputfileref{input/@/regression,ottava@/-broken@/.ly}.
456
457 @refbugs
458
459 @code{set-octavation} will get confused when clef changes happen
460 during an octavation bracket.
461
462
463 @node Multi measure rests
464 @subsection Multi measure rests
465 @cindex multi measure rests
466 @cindex Rests, multi measure
467
468 @cindex @code{R}
469
470 Multi-measure rests are entered using `@code{R}'.  It is specifically
471 meant for full bar rests and for entering parts: the rest can expand
472 to fill a score with rests, or it can be printed as a single
473 multi-measure rest.  This expansion is controlled by the property
474 @code{Score.skipBars}.  If this is set to true, empty measures will not
475 be expanded, and the appropriate number is added automatically
476
477 @lilypond[quote,raggedright,fragment,verbatim]
478 \time 4/4 r1 | R1 | R1*2
479 \set Score.skipBars = ##t R1*17 R1*4
480 @end lilypond
481
482 The @code{1} in @code{R1} is similar to the duration notation used for
483 notes.  Hence, for time signatures other than 4/4, you must enter other
484 durations.  This can be done with augmentation dots or fractions
485
486 @lilypond[quote,raggedright,fragment,verbatim]
487 \set Score.skipBars = ##t
488 \time 3/4
489 R2. | R2.*2
490 \time 13/8
491 R1*13/8
492 R1*13/8*12 |
493 \time 10/8 R4*5*4 |
494 @end lilypond
495
496 An @code{R} spanning a single measure is printed as either a whole rest
497 or a breve, centered in the measure regardless of the time signature.
498
499 If there are only a few measures of rest, LilyPond prints ``church rests''
500 (a series of rectangles) in the staff.  To replace that with a simple
501 rest, use @code{MultiMeasureRest.expand-limit}.
502
503 @lilypond[quote,raggedright,fragment,verbatim]
504 \set Score.skipBars = ##t
505 R1*2 | R1*5 | R1*9
506 \override MultiMeasureRest #'expand-limit = 1
507 R1*2 | R1*5 | R1*9
508 @end lilypond
509
510
511 @cindex text on multi-measure rest
512 @cindex script on multi-measure rest
513 @cindex fermata on multi-measure rest
514
515 Texts can be added to multi-measure rests by using the
516 @var{note}-@code{markup} syntax (see @ref{Text markup}).
517 A variable (@code{\fermataMarkup}) is provided for
518 adding fermatas
519
520 @lilypond[quote,raggedright,verbatim,fragment]
521 \set Score.skipBars = ##t
522 \time 3/4
523 R2.*10^\markup { \italic "ad lib." }
524 R2.^\fermataMarkup
525 @end lilypond
526
527 If you want to have text on the left end of a multi-measure rest,
528 attach the text to a zero-length skip note, i.e.,
529
530 @example
531 s1*0^"Allegro"
532 R1*4
533 @end example
534
535
536 @cindex whole rests for a full measure
537
538 @seealso
539
540 Program reference: @internalsref{MultiMeasureRestEvent},
541 @internalsref{MultiMeasureTextEvent},
542 @internalsref{MultiMeasureRestMusicGroup}, and
543 @internalsref{MultiMeasureRest}.
544
545 The layout object @internalsref{MultiMeasureRestNumber} is for the
546 default number, and @internalsref{MultiMeasureRestText} for user
547 specified texts.
548
549 @refbugs
550
551 It is not possible to use fingerings (e.g., @code{R1-4}) to put numbers
552 over multi-measure rests.  And the pitch of multi-measure rests (or
553 staff-centered rests) can not be influenced.
554
555 @cindex condensing rests
556
557 There is no way to automatically condense multiple rests into a single
558 multi-measure rest.  Multi-measure rests do not take part in rest
559 collisions.
560
561 Be careful when entering multi-measure rests followed by whole
562 notes.  The following will enter two notes lasting four measures each
563 @example
564 R1*4 cis cis
565 @end example
566 When @code{skipBars} is set, the result will look OK, but the bar
567 numbering will be off.
568
569
570 @node Time administration
571 @subsection Time administration
572
573 Time is administered by the @internalsref{Time_signature_engraver},
574 which usually lives in the @internalsref{Score} context.
575 The bookkeeping deals with the following variables
576
577 @table @code
578 @item currentBarNumber
579 The measure number.
580
581 @item measureLength
582 The length of the measures in the current time signature.  For a 4/4
583 time this is@tie{}1, and for 6/8 it is 3/4.
584
585 @item measurePosition
586 The point within the measure where we currently are.  This quantity
587 is reset to@tie{}0 whenever it exceeds @code{measureLength}.  When that
588 happens, @code{currentBarNumber} is incremented.
589
590 @item timing
591 If set to true, the above variables are updated for every time
592 step.  When set to false, the engraver stays in the current measure
593 indefinitely.
594 @end table
595
596 Timing can be changed by setting any of these variables explicitly.
597 In the next example, the 4/4 time signature is printed, but
598 @code{measureLength} is set to 5/4.  After a while, the measure is
599 shortened by 1/8, by setting @code{measurePosition} to 7/8 at 2/4
600 in the measure, so the next bar line will fall at 2/4 + 3/8.  The
601 3/8 arises because 5/4 normally has 10/8, but we have manually
602 set the measure position to be 7/8 and 10/8 - 7/8 = 3/8.
603
604 @lilypond[quote,raggedright,verbatim,relative,fragment]
605 \set Score.measureLength = #(ly:make-moment 5 4)
606 c1 c4
607 c1 c4
608 c4 c4
609 \set Score.measurePosition = #(ly:make-moment 7 8)
610 b8 b b
611 c4 c1
612 @end lilypond
613
614
615
616 @node Preparing parts
617 @section Preparing parts
618
619 This section describes various notation that are useful for preparing
620 individual parts.
621
622 @menu
623 * Metronome marks::             
624 * Rehearsal marks::             
625 * Bar numbers::                 
626 * Instrument names::            
627 * Instrument transpositions::   
628 * Different editions from one source::  
629 @end menu
630
631
632 @node Metronome marks
633 @subsection Metronome marks
634
635 @cindex Tempo
636 @cindex beats per minute
637 @cindex metronome marking
638
639 Metronome settings can be entered as follows
640 @example
641 \tempo @var{duration} = @var{per-minute}
642 @end example
643
644 In the MIDI output, they are interpreted as a tempo change.  In the
645 layout output, a metronome marking is printed
646 @cindex @code{\tempo}
647 @lilypond[quote,raggedright,verbatim,fragment]
648 \tempo 8.=120 c''1
649 @end lilypond
650
651 To change the tempo in the MIDI output without printing anything, make
652 the metronome marking invisible
653 @example
654 \once \override Score.MetronomeMark #'transparent = ##t
655 @end example
656
657 To print other metronome markings, use these markup commands
658 @lilypond[quote,raggedright,verbatim,relative,fragment]
659 c4^\markup {
660   "("
661   \smaller \general-align #Y #DOWN \note #"16." #1
662   "="
663   \smaller \general-align #Y #DOWN \note #"8" #1"
664   ")" }
665 @end lilypond
666
667 @noindent
668 See @ref{Text markup} for more details.
669
670
671 @seealso
672
673 Program reference: @internalsref{MetronomeChangeEvent}
674 @internalsref{MetronomeMark}.
675
676 @refbugs
677
678 Collisions are not checked.  If you have notes above the top line of
679 the staff (or notes with articulations, slurs, text, etc), then the
680 metronome marking may be printed on top of musical symbols.  If this
681 occurs, increase the padding of the metronome mark to place it 
682 further away from the staff.
683
684 @example
685 \override Score.MetronomeMark #'padding = #2.5
686 @end example
687
688
689 @node Rehearsal marks
690 @subsection Rehearsal marks
691 @cindex Rehearsal marks
692 @cindex mark
693 @cindex @code{\mark}
694
695 To print a rehearsal mark, use the @code{\mark} command
696
697 @lilypond[quote,raggedright,fragment,verbatim,relative=2]
698 c1 \mark \default
699 c1 \mark \default
700 c1 \mark #8
701 c1 \mark \default
702 c1 \mark \default
703 @end lilypond
704
705 @noindent
706 (The letter@tie{}`I' is skipped in accordance with engraving traditions.)
707 @c umm, is the manual the right place for feature requests?  :)  -gp
708 @c FIXME - should make that tunable.
709
710 The mark is incremented automatically if you use @code{\mark
711 \default}, but you can also use an integer argument to set the mark
712 manually.  The value to use is stored in the property
713 @code{rehearsalMark}.
714
715 The style is defined by the property @code{markFormatter}.  It is a
716 function taking the current mark (an integer) and the current context
717 as argument.  It should return a markup object.  In the following
718 example, @code{markFormatter} is set to a canned procedure.  After a
719 few measures, it is set to function that produces a boxed number.
720
721 @lilypond[fragment,quote,raggedright,verbatim,relative=2]
722 \set Score.markFormatter = #format-mark-numbers
723 c1 \mark \default
724 c1 \mark \default
725 \set Score.markFormatter = #format-mark-box-numbers
726 c1 \mark \default
727 c1 \mark \default
728 c1
729 @end lilypond
730
731 The file @file{scm/@/translation@/-functions@/.scm} contains the definitions
732 of @code{format-mark-numbers} (the default format), @code{format-mark-box-numbers},
733 @code{format-mark-letters} and @code{format-mark-box-letters}.
734 These can be used as inspiration for other formatting functions.
735
736
737 @cindex coda on bar line
738 @cindex segno on bar line
739 @cindex fermata on bar line
740 @cindex bar lines, symbols on
741
742 The @code{\mark} command can also be used to put signs like coda,
743 segno, and fermata on a bar line.  Use @code{\markup} to
744 access the appropriate symbol
745
746 @lilypond[fragment,quote,raggedright,verbatim,relative=2]
747 c1 \mark \markup { \musicglyph #"scripts.ufermata" }
748 c1
749 @end lilypond
750
751 If the mark occurs at a line break, the mark will be printed at the
752 beginning of the next line.
753 @c  IMO this is a bug; hopefully it'll be fixed soon, so I can
754 @c  delete this sentence.   -gp
755 If there is no next line, then the mark will not be printed at all.
756 To print the mark at the end of the current line, use
757
758 @example
759 \override Score.RehearsalMark
760   #'break-visibility = #begin-of-line-invisible
761 @end example
762
763 @cindex fermatas
764 @cindex coda
765 @cindex segno
766 @cindex bar lines, putting symbols on
767
768 @seealso
769
770 Program reference: @internalsref{MarkEvent}, @internalsref{RehearsalMark}.
771
772 Init files: @file{scm/@/translation@/-functions@/.scm} contains the
773 definition of @code{format-mark-numbers} and
774 @code{format-mark-letters}.  They can be used as inspiration for other
775 formatting functions.
776
777 Examples: @inputfileref{input/@/regression,rehearsal@/-mark@/-letter@/.ly},
778
779 @inputfileref{input/@/regression,rehearsal@/-mark@/-number@/.ly}.
780
781
782 @node Bar numbers
783 @subsection Bar numbers
784
785
786 @cindex Bar numbers
787 @cindex measure numbers
788 @cindex @code{currentBarNumber}
789
790 Bar numbers are printed by default at the start of the line.  The
791 number itself is stored in the @code{currentBarNumber} property, which
792 is normally updated automatically for every measure.
793
794 Bar numbers can be typeset at regular intervals instead of at the
795 beginning of each line.  This is illustrated in the following example,
796 whose source is available as
797 @inputfileref{input/@/test,bar@/-number@/-regular@/-interval@/.ly}
798
799 @lilypondfile[raggedright,quote]{bar-number-regular-interval.ly}
800
801 Bar numbers can be typeset manually by tweaking the
802 @code{markFormatter} property
803
804 @lilypond[verbatim,raggedright,quote]
805 \relative c' {
806   \set Score.markFormatter
807     = #(lambda (mark context)
808       (make-bold-markup
809         (make-box-markup
810           (number->string (ly:context-property context
811                                                'currentBarNumber)))))
812
813   c1 \bar "||" \mark \default c1 c1 \mark \default c1 \bar "|."
814 }
815 @end lilypond
816
817 Bar numbers can be manually changed by setting the
818 @code{Staff.currentBarNumber} property
819
820 @lilypond[verbatim,raggedright,quote]
821 \relative c' {
822   \repeat unfold 4 {c4 c c c} \break
823   \set Score.currentBarNumber = #50
824   \repeat unfold 4 {c4 c c c}
825 }
826 @end lilypond
827
828 @seealso
829
830 Program reference: @internalsref{BarNumber}.
831
832 Examples:
833 @inputfileref{input/@/test,bar@/-number@/-every@/-five@/-reset@/.ly},
834 and @inputfileref{input/@/test,bar@/-number@/-regular@/-interval@/.ly}.
835
836 @refbugs
837
838 Bar numbers can collide with the @internalsref{StaffGroup} bracket, if
839 there is one at the top.  To solve this, the
840 @code{padding} property of @internalsref{BarNumber} can be
841 used to position the number correctly.
842
843
844 @node Instrument names
845 @subsection Instrument names
846
847 In an orchestral score, instrument names are printed at the left side
848 of the staves.
849
850 This can be achieved by setting @internalsref{Staff}.@code{instrument}
851 and @internalsref{Staff}.@code{instr}.  This will print a string before
852 the start of the staff.  For the first staff, @code{instrument} is
853 used, for the following ones, @code{instr} is used.
854
855 @lilypond[quote,verbatim,raggedright,relative=1,fragment]
856 \set Staff.instrument = "Ploink "
857 \set Staff.instr = "Plk "
858 c1
859 \break
860 c''
861 @end lilypond
862
863 You can also use markup texts to construct more complicated instrument
864 names, for example
865
866 @lilypond[quote,fragment,verbatim,raggedright]
867 \set Staff.instrument = \markup {
868   \column { "Clarinetti"
869             \line { "in B" \smaller \flat } } }
870 c''1
871 @end lilypond
872
873 For longer instrument names, it may be useful to increase the
874 @code{indent} setting in the @code{\layout} block.
875
876 @seealso
877
878 Program reference: @internalsref{InstrumentName}.
879
880 @refbugs
881
882 When you put a name on a grand staff or piano staff, the width of the
883 brace is not taken into account.  You must add extra spaces to the end of
884 the name to avoid a collision.
885
886
887 @node Instrument transpositions
888 @subsection Instrument transpositions
889 @cindex transposition, MIDI
890 @cindex transposition, instrument
891
892 The key of a transposing instrument can also be specified.  This
893 applies to many wind instruments, for example, clarinets (B-flat, A, and
894 E-flat), horn (F) and trumpet (B-flat, C, D, and E-flat).
895
896 The transposition is entered after the keyword @code{\transposition}
897
898 @example
899 \transposition bes   %% B-flat clarinet
900 @end example
901
902 @noindent
903 This command sets the property @code{instrumentTransposition}.  The value of
904 this property is used for MIDI output and quotations.  It does not
905 affect how notes are printed in the current staff.  To change the printed
906 output, see @ref{Transpose}.
907
908 The pitch to use for @code{\transposition} should correspond to the
909 transposition of the notes.  For example, when entering a score in
910 concert pitch, typically all voices are entered in C, so
911 they should be entered as
912
913 @example
914 clarinet = @{
915   \transposition c'
916   ...
917 @}
918 saxophone = @{
919   \transposition c'
920   ...
921 @}
922 @end example
923
924 The command @code{\transposition} should be used when the music is
925 entered from a (transposed) orchestral part.  For example, in
926 classical horn parts, the tuning of the instrument is often changed
927 during a piece.  When copying the notes from the part, use
928 @code{\transposition}, e.g.,
929
930 @example
931 \transposition d'
932 c'4^"in D"
933 ...
934 \transposition g'
935 c'4^"in G"
936 ...
937 @end example
938
939
940 @node Different editions from one source
941 @subsection Different editions from one source
942
943 @cindex tag
944 The @code{\tag} command marks music expressions with a name.  These
945 tagged expressions can be filtered out later.  With this mechanism it
946 is possible to make different versions of the same music source.
947
948 In the following example, we see two versions of a piece of music, one
949 for the full score, and one with cue notes for the instrumental part
950
951 @example
952 c1
953 <<
954   \tag #'part <<
955     R1 \\
956     @{
957       \set fontSize = #-1
958       c4_"cue" f2 g4 @}
959   >>
960   \tag #'score R1
961 >>
962 c1
963 @end example
964
965 The same can be applied to articulations, texts, etc.: they are
966 made by prepending
967 @example
968 -\tag #@var{your-tag}
969 @end example
970 to an articulation, for example,
971 @example
972 c1-\tag #'part ^4
973 @end example
974
975 This defines a note with a conditional fingering indication.
976
977 @cindex keepWithTag
978 @cindex removeWithTag
979 By applying the @code{\keepWithTag} and @code{\removeWithTag}
980 commands, tagged expressions can be filtered.  For example,
981 @example
982 <<
983   @var{the music}
984   \keepWithTag #'score @var{the music}
985   \keepWithTag #'part @var{the music}
986 >>
987 @end example
988 would yield
989
990 @lilypondfile[raggedright,quote]{tag-filter.ly}
991
992
993 The argument of the @code{\tag} command should be a symbol, or a list
994 of symbols, for example,
995 @example
996 \tag #'(original-part transposed-part) @dots{}
997 @end example
998
999
1000
1001 @seealso
1002
1003 Examples: @inputfileref{input/@/regression,tag@/-filter@/.ly}.
1004
1005 @refbugs
1006
1007 Multiple rests are not merged if you create the score with both tagged
1008 sections.
1009  
1010
1011 @node Orchestral music
1012 @section Orchestral music
1013
1014 Orchestral music involves some special notation, both in the full
1015 score and the individual parts.  This section explains how to tackle
1016 some common problems in orchestral music.
1017
1018 @menu
1019 * Automatic part combining::    
1020 * Hiding staves::               
1021 * Quoting other voices::        
1022 * Formatting cue notes::        
1023 * Aligning to cadenzas::        
1024 @end menu
1025
1026
1027 @node Automatic part combining
1028 @subsection Automatic part combining
1029 @cindex automatic part combining
1030 @cindex part combiner
1031
1032 Automatic part combining is used to merge two parts of music onto a
1033 staff.  It is aimed at typesetting orchestral scores.  When the two
1034 parts are identical for a period of time, only one is shown.  In
1035 places where the two parts differ, they are typeset as separate
1036 voices, and stem directions are set automatically.  Also, solo and
1037 @emph{a due} parts are identified and can be marked.
1038
1039 The syntax for part combining is
1040
1041 @example
1042 \partcombine @var{musicexpr1} @var{musicexpr2}
1043 @end example
1044
1045
1046 The following example demonstrates the basic functionality of the part
1047 combiner: putting parts on one staff, and setting stem directions and
1048 polyphony
1049
1050 @lilypond[quote,verbatim,raggedright,fragment]
1051 \new Staff \partcombine
1052   \relative g' { g g a( b) c c r r }
1053   \relative g' { g g r4 r e e g g }
1054 @end lilypond
1055
1056 The first @code{g} appears only once, although it was
1057 specified twice (once in each part).  Stem, slur, and tie directions are
1058 set automatically, depending whether there is a solo or unisono.  The
1059 first part (with context called @code{one}) always gets up stems, and
1060 `Solo', while the second (called @code{two}) always gets down stems and
1061 `Solo II'.
1062
1063 If you just want the merging parts, and not the textual markings, you
1064 may set the property @code{printPartCombineTexts} to false
1065
1066 @lilypond[quote,verbatim,raggedright,fragment,relative=2]
1067 \new Staff <<
1068   \set Staff.printPartCombineTexts = ##f
1069   \partcombine
1070     \relative g' { g a( b) r }
1071     \relative g' { g r4 r f }
1072 >>
1073 @end lilypond
1074
1075 To change the text that is printed for solos or merging, you may
1076 set the @code{soloText}, @code{soloIIText}, and @code{aDueText}
1077 properties.
1078
1079 @lilypond[quote,verbatim,raggedright,fragment,relative=2]
1080 \new Staff <<
1081   \set Score.soloText = #"ichi"
1082   \set Score.soloIIText = #"ni"
1083   \set Score.aDueText = #"tachi"
1084   \partcombine
1085     \relative g' { g4 g a( b) r }
1086     \relative g' { g4 g r r f }
1087 >>
1088 @end lilypond
1089
1090 Both arguments to @code{\partcombine} will be interpreted as
1091 @internalsref{Voice} contexts.  If using relative octaves,
1092 @code{\relative} should be specified for both music expressions, i.e.,
1093
1094 @example
1095 \partcombine
1096   \relative @dots{} @var{musicexpr1}
1097   \relative @dots{} @var{musicexpr2}
1098 @end example
1099
1100 @noindent
1101 A @code{\relative} section that is outside of @code{\partcombine} has
1102 no effect on the pitches of @var{musicexpr1} and @var{musicexpr2}.
1103
1104 @seealso
1105
1106 Program reference: @internalsref{PartCombineMusic},
1107 @internalsref{SoloOneEvent}, and
1108 @internalsref{SoloTwoEvent}, and
1109 @internalsref{UnisonoEvent}.
1110
1111 @refbugs
1112
1113 When @code{printPartCombineTexts} is set, when the two voices play the
1114 same notes on and off, the part combiner may typeset @code{a2} more
1115 than once in a measure.
1116
1117 @code{\partcombine} cannot be inside @code{\times}.
1118
1119 @code{\partcombine} cannot be inside @code{\relative}.
1120
1121 Internally, the @code{\partcombine} interprets both arguments as
1122 @code{Voice}s named @code{one} and @code{two}, and then decides when
1123 the parts can be combined.  Consequently, if the arguments switch to
1124 differently named @internalsref{Voice} contexts, the events in those
1125 will be ignored.
1126
1127
1128 @node Hiding staves
1129 @subsection Hiding staves
1130
1131 @cindex Frenched scores
1132 @cindex Hiding staves
1133
1134 In orchestral scores, staff lines that only have rests are usually
1135 removed; this saves some space.  This style is called `French Score'.
1136 For @internalsref{Lyrics},
1137 @internalsref{ChordNames} and @internalsref{FiguredBass}, this is
1138 switched on by default.  When the lines of these contexts turn out
1139 empty after the line-breaking process, they are removed.
1140
1141 For normal staves, a specialized @internalsref{Staff} context is
1142 available, which does the same: staves containing nothing (or only
1143 multi-measure rests) are removed.  The context definition is stored in
1144 @code{\RemoveEmptyStaffContext} variable.  Observe how the second staff
1145 in this example disappears in the second line
1146
1147 @lilypond[quote,raggedright,verbatim]
1148 \layout {
1149   \context { \RemoveEmptyStaffContext }
1150 }
1151
1152 {
1153   \relative c' <<
1154     \new Staff { e4 f g a \break c1 }
1155     \new Staff { c4 d e f \break R1 }
1156   >>
1157 }
1158 @end lilypond
1159
1160 The first system shows all staves in full.  If empty staves should be
1161 removed from the first system too, set @code{remove-first} to true in
1162 @internalsref{RemoveEmptyVerticalGroup}.
1163
1164 @example
1165 \override Score.RemoveEmptyVerticalGroup #'remove-first = ##t
1166 @end example
1167
1168 To remove other types of contexts, use @code{\AncientRemoveEmptyStaffContext}
1169 or @code{\RemoveEmptyRhythmicStaffContext}.
1170
1171 Another application is making ossia sections, i.e., alternative
1172 melodies on a separate piece of staff, with help of a Frenched
1173 staff.  See @inputfileref{input/@/test,ossia@/.ly} for an example.
1174
1175
1176 @node Quoting other voices
1177 @subsection Quoting other voices
1178
1179 With quotations, fragments of other parts can be inserted into a part
1180 directly.  Before a part can be quoted, it must be marked especially as
1181 quotable.  This is done with the @code{\addquote} command.
1182
1183 @example
1184 \addquote @var{name} @var{music}
1185 @end example
1186
1187
1188 @noindent
1189 Here, @var{name} is an identifying string.  The @var{music} is any kind
1190 of music.  Here is an example of @code{\addquote}
1191
1192 @example
1193 \addquote clarinet \relative c' @{
1194   f4 fis g gis
1195 @}
1196 @end example
1197
1198 This command must be entered at toplevel, i.e., outside any music
1199 blocks.
1200
1201 After calling @code{\addquote}, the quotation may then be done with
1202 @code{\quoteDuring} or @code{\cueDuring},
1203
1204 @example
1205 \quoteDuring #@var{name} @var{music}
1206 @end example
1207
1208 During a part, a piece of music can be quoted with the @code{\quoteDuring}
1209 command.
1210
1211 @example
1212 \quoteDuring #"clarinet" @{ s2. @}
1213 @end example
1214
1215 This would cite three quarter notes (the duration of @code{s2.})  of
1216 the previously added @code{clarinet} voice.
1217
1218
1219 More precisely, it takes the current time-step of the part being
1220 printed, and extracts the notes at the corresponding point of the
1221 @code{\addquote}d voice.  Therefore, the argument to @code{\addquote}
1222 should be the entire part of the voice to be quoted, including any
1223 rests at the beginning.
1224
1225 Quotations take into account the transposition of both source and target
1226 instruments, if they are specified using the @code{\transposition} command.
1227
1228 @lilypond[quote,raggedright,verbatim]
1229 \addquote clarinet \relative c' {
1230   \transposition bes
1231   f4 fis g gis
1232 }
1233
1234 {
1235   e'8 f'8 \quoteDuring #"clarinet" { s2 }
1236 }
1237 @end lilypond
1238
1239 The type of events that are present in cue notes can be trimmed with
1240 the @code{quotedEventTypes} property.  The default value is
1241 @code{(note-event rest-event)}, which means that only notes and
1242 rests of the cued voice end up in the @code{\quoteDuring}.
1243 Setting
1244
1245 @example
1246 \set Staff.quotedEventTypes =
1247        #'(note-event articulation-event dynamic-event)
1248 @end example
1249
1250 @noindent
1251 will quote notes (but no rests), together with scripts and dynamics.
1252
1253 @refbugs
1254
1255 Only the contents of the first @internalsref{Voice} occurring in an
1256 @code{\addquote} command will be considered for quotation, so
1257 @var{music} can not contain @code{\new} and @code{\context Voice}
1258 statements that would switch to a different Voice.
1259
1260 Quoting grace notes is broken and can even cause LilyPond to crash.
1261
1262 @seealso
1263
1264 In this manual: @ref{Instrument transpositions}.
1265
1266 Examples: @inputfileref{input/@/regression,quote@/.ly}
1267 @inputfileref{input/@/regression,quote@/-transposition@/.ly}
1268
1269 Program reference: @internalsref{QuoteMusic}.
1270
1271
1272 @node Formatting cue notes
1273 @subsection Formatting cue notes
1274
1275 The previous section deals with inserting notes from another voice.
1276 There is a more advanced music function called @code{\cueDuring},
1277 which makes formatting cue notes easier.
1278
1279 The syntax is
1280
1281 @example
1282   \cueDuring #@var{name} #@var{updown} @var{music}
1283 @end example
1284
1285 This will insert notes from the part @var{name} into a
1286 @internalsref{Voice} called @code{cue}.  This happens simultaneously
1287 with @var{music}, which usually is a rest.  When the cue notes start,
1288 the staff in effect becomes polyphonic for a moment.  The argument
1289 @var{updown} determines whether the cue notes should be notated as a
1290 first or second voice.
1291
1292
1293 @lilypond[verbatim,raggedright]
1294 smaller = {
1295   \set fontSize = #-2
1296   \override Stem #'length = #5.5
1297   \override Beam #'thickness = #0.384
1298   \override Beam #'space-function =
1299     #(lambda (beam mult) (* 0.8 (Beam::space_function beam mult)))
1300 }
1301
1302 \addquote clarinet \relative {
1303   R1*20
1304   r2 r8 c f f
1305
1306
1307 \new Staff \relative  <<
1308
1309   % setup a context for  cue  notes.
1310   \context Voice = cue { \smaller \skip 1*21 }
1311   
1312   \set Score.skipBars = ##t
1313   
1314   \new Voice {
1315     R1*20
1316     \cueDuring #"clarinet" #1 {
1317       R1
1318     }
1319     g4 g2. 
1320   }
1321 >>
1322 @end lilypond 
1323
1324
1325 Here are a couple of hints for successful cue notes
1326
1327 @itemize @bullet
1328 @item
1329 Cue notes have smaller font sizes.
1330 @item
1331  the cued part is marked with the instrument playing the cue.
1332 @item
1333  when the original part takes over again, this should be marked with
1334  the name of the original instrument.
1335
1336  @c really?  Are you sure about that last point?  I'll check after 3.0 -gp
1337
1338 @c Yes, this is good practice.  Otherwise, the start of the original
1339 @c part can only be seen from the font size.  This is not good enough
1340 @c for sight-reading.  It is possilbe to use other
1341 @c markers (eg. a big close-bracket over the staff) to indicate the cue notes are
1342 @c finished.
1343 @c -hwn
1344
1345
1346  any other changes introduced by the cued part should also be
1347 undone.  For example, if the cued instrument plays in a different clef,
1348 the original clef should be stated once again.
1349
1350 @end itemize
1351
1352
1353 @node Aligning to cadenzas
1354 @subsection Aligning to cadenzas
1355
1356 In an orchestral context, cadenzas present a special problem:
1357 when constructing a score that includes a cadenza, all other
1358 instruments should skip just as many notes as the length of the
1359 cadenza, otherwise they will start too soon or too late.
1360
1361 A solution to this problem are the functions @code{mmrest-of-length}
1362 and @code{skip-of-length}.  These Scheme functions take a piece of music
1363 as argument, and generate a @code{\skip} or multi-rest, exactly as
1364 long as the piece.  The use of @code{mmrest-of-length} is demonstrated
1365 in the following example.
1366
1367 @lilypond[verbatim,raggedright,quote]
1368 cadenza = \relative c' {
1369   c4 d8 << { e f g } \\ { d4. } >>
1370   g4 f2 g4 g
1371 }
1372
1373 \new GrandStaff <<
1374   \new Staff { \cadenza c'4 }
1375   \new Staff {
1376     #(ly:export (mmrest-of-length cadenza))
1377     c'4
1378   }
1379 >>
1380 @end lilypond
1381
1382
1383
1384
1385 @node Contemporary notation
1386 @section Contemporary notation
1387
1388 In the 20th century, composers have greatly expanded the musical
1389 vocabulary.  With this expansion, many innovations in musical notation
1390 have been tried.  The book ``Music Notation in the 20th century'' by
1391 Kurt Stone gives a comprehensive overview (see @ref{Literature
1392 list}).  In general, the use of new, innovative notation makes a piece
1393 harder to understand and perform and its use should therefore be
1394 avoided.  For this reason, support for contemporary notation in
1395 LilyPond is limited.
1396
1397
1398 @menu
1399 * Polymetric notation::         
1400 * Clusters::                    
1401 * Special fermatas::            
1402 * Feathered beams::             
1403 * Improvisation::               
1404 @end menu
1405
1406 @node Polymetric notation
1407 @subsection Polymetric notation
1408
1409 Double time signatures are not supported explicitly, but they can be
1410 faked.  In the next example, the markup for the time signature is
1411 created with a markup text.  This markup text is inserted in the
1412 @internalsref{TimeSignature} grob.
1413
1414 @lilypond[verbatim,raggedright]
1415 % create 2/4 + 5/8
1416 tsMarkup =\markup {
1417   \number {
1418     \column { "2" "4" }
1419     \musicglyph #"scripts.stopped"
1420     \bracket \column { "5" "8" }
1421   }
1422 }
1423
1424 {
1425   \override Staff.TimeSignature #'print-function = #Text_interface::print
1426   \override Staff.TimeSignature #'text = #tsMarkup
1427   \time 3/2
1428   c'2 \bar ":" c'4 c'4.
1429 }
1430 @end lilypond
1431
1432 Each staff can also have its own time signature.  This is done by
1433 moving the @internalsref{Timing_engraver} to the @internalsref{Staff}
1434 context.
1435
1436 @example
1437 \layout @{
1438   \context @{ \Score \remove "Timing_engraver" @}
1439   \context @{ \Staff \consists "Timing_engraver" @}
1440 @}
1441 @end example
1442
1443
1444 Now, each staff has its own time signature.
1445 @example
1446 <<
1447   \new Staff @{
1448     \time 3/4
1449     c4 c c | c c c |
1450   @}
1451   \new Staff @{
1452     \time 2/4
1453     c4 c | c c | c c
1454   @}
1455   \new Staff @{
1456     \time 3/8
1457     c4. c8 c c c4. c8 c c
1458   @}
1459 >>
1460 @end example
1461
1462 @lilypond[quote,raggedright]
1463 \layout{
1464   \context{ \Score \remove "Timing_engraver" }
1465   \context{ \Staff \consists "Timing_engraver" }
1466 }
1467
1468 \relative c' <<
1469   \new Staff {
1470     \time 3/4
1471     c4 c c | c c c |
1472   }
1473   \new Staff {
1474     \time 2/4
1475     c4 c | c c | c c
1476   }
1477   \new Staff {
1478     \time 3/8
1479     c4. c8 c c c4. c8 c c
1480   }
1481 >>
1482 @end lilypond
1483
1484
1485 A different form of polymetric notation is where note lengths have
1486 different values across staves.
1487
1488 This notation can be created by setting a common time signature for
1489 each staff but replacing it manually using
1490 @code{timeSignatureFraction} to the desired fraction.  Then the printed
1491 durations in each staff are scaled to the common time signature.
1492 The latter is done with @code{\compressmusic}, which is similar to
1493 @code{\times}, but does not create a tuplet bracket.
1494
1495
1496 In this example, music with the time signatures of 3/4, 9/8, and 10/8 are
1497 used in parallel.  In the second staff, shown durations are multiplied by
1498 2/3, so that 2/3 * 9/8 = 3/4, and in the third staff, shown durations are
1499 multiplied by 3/5, so that 3/5 * 10/8 = 3/4.
1500
1501 @lilypond[quote,raggedright,verbatim,fragment]
1502 \relative c' { <<
1503   \new Staff {
1504     \time 3/4
1505     c4 c c | c c c |
1506   }
1507   \new Staff {
1508     \time 3/4
1509     \set Staff.timeSignatureFraction = #'(9 . 8)
1510     \compressmusic #'(2 . 3)
1511       \repeat unfold 6 { c8[ c c] }
1512   }
1513   \new Staff {
1514     \time 3/4
1515     \set Staff.timeSignatureFraction = #'(10 . 8)
1516     \compressmusic #'(3 . 5) {
1517       \repeat unfold 2 { c8[ c c] }
1518       \repeat unfold 2 { c8[ c] }
1519       | c4. c4. \times 2/3 { c8 c c } c4
1520     }
1521   }
1522 >> }
1523 @end lilypond
1524
1525
1526
1527
1528 @refbugs
1529
1530 When using different time signatures in parallel, the spacing is
1531 aligned vertically, but bar lines distort the regular spacing.
1532
1533
1534
1535 @node Clusters
1536 @subsection Clusters
1537
1538 @cindex cluster
1539
1540 A cluster indicates a continuous range of pitches to be played.  They
1541 can be denoted as the envelope of a set of notes.  They are entered by
1542 applying the function @code{makeClusters} to a sequence of
1543 chords, e.g.,
1544 @lilypond[quote,raggedright,relative=2,fragment,verbatim]
1545 \makeClusters { <c e > <b f'> }
1546 @end lilypond
1547
1548 The following example (from
1549 @inputfileref{input/@/regression,cluster@/.ly}) shows what the result
1550 looks like
1551
1552 @lilypondfile[raggedright,quote]{cluster.ly}
1553
1554 Ordinary notes and clusters can be put together in the same staff,
1555 even simultaneously.  In such a case no attempt is made to
1556 automatically avoid collisions between ordinary notes and clusters.
1557
1558 @seealso
1559
1560 Program reference: @internalsref{ClusterSpanner},
1561 @internalsref{ClusterSpannerBeacon},
1562 @internalsref{Cluster_spanner_engraver}, and
1563 @internalsref{ClusterNoteEvent}.
1564
1565 Examples: @inputfileref{input/@/regression,cluster@/.ly}.
1566
1567 @refbugs
1568
1569 Music expressions like @code{<< @{ g8 e8 @} a4 >>} are not printed
1570 accurately.  Use @code{<g a>8 <e a>8} instead.
1571
1572
1573
1574 @node Special fermatas
1575 @subsection Special fermatas
1576
1577 @cindex fermatas, special
1578
1579 In contemporary music notation, special fermata symbols denote breaks
1580 of differing lengths.  The following fermatas are supported
1581
1582 @lilypond[quote,raggedright]
1583 <<
1584   \oldaddlyrics {
1585     b'2
1586     ^\shortfermata
1587     _\shortfermata
1588     r
1589
1590     b'
1591     ^\fermata
1592     _\fermata
1593     r
1594
1595     b'
1596     ^\longfermata
1597     _\longfermata
1598     r
1599
1600     b'
1601     ^\verylongfermata
1602     _\verylongfermata
1603     r
1604   }
1605   \context Lyrics \lyricmode {
1606     \override LyricText #'font-family = #'typewriter
1607     "shortfermata" "fermata" "longfermata" "verylongfermata"
1608   }
1609 >>
1610 @end lilypond
1611
1612 See @ref{Articulations} for general instructions how to apply scripts
1613 such as fermatas to notes.
1614
1615 @node Feathered beams
1616 @subsection Feathered beams
1617
1618 Feathered beams are not supported natively, but they can be faked by
1619 forcing two beams to overlap.  Here is an example,
1620
1621 @c don't change relative setting witout changing positions!
1622 @lilypond[raggedright,relative=1,fragment,verbatim]
1623 \new Staff <<
1624   \new Voice
1625   {
1626     \stemUp
1627     \once \override Voice.Beam #'positions = #'(0 . 0.5)
1628     c8[ c c c c ]
1629   }
1630   \new Voice {
1631     \stemUp
1632     \once \override Voice.Beam #'positions = #'(0 . -0.5)
1633     c[ c c c c]
1634   }
1635 >>
1636 @end lilypond
1637
1638
1639 @node Improvisation
1640 @subsection Improvisation
1641
1642 Improvisation is sometimes denoted with slashed note heads.  Such note
1643 heads can be created by adding a @internalsref{Pitch_squash_engraver}
1644 to the @internalsref{Staff} or @internalsref{Voice} context.  Then, the
1645 following command
1646
1647 @example
1648 \set squashedPosition = #0
1649 \override NoteHead #'style = #'slash
1650 @end example
1651
1652 @noindent
1653 switches on the slashes.
1654
1655 There are shortcuts @code{\improvisationOn} (and an accompanying
1656 @code{\improvisationOff}) for this command sequence.  They are used in
1657 the following example
1658
1659 @lilypond[verbatim,raggedright,quote]
1660 \new Staff \with {
1661   \consists Pitch_squash_engraver
1662 } \transpose c c' {
1663   e8 e g a a16(bes)(a8) g \improvisationOn
1664   e8
1665   ~e2~e8 f4 fis8
1666   ~fis2 \improvisationOff a16(bes) a8 g e
1667 }
1668 @end lilypond
1669
1670
1671 @node Educational use
1672 @section Educational use
1673
1674 With the amount of control that LilyPond offers, one can make great
1675 teaching tools in addition to great musical scores.
1676
1677 @menu
1678 * Balloon help::                
1679 * Blank music sheet::           
1680 * Hidden notes::                
1681 * Shaped note heads ::          
1682 * Easy Notation note heads::    
1683 * Analysis brackets::           
1684 * Coloring objects::            
1685 @end menu
1686
1687 @node Balloon help
1688 @subsection Balloon help
1689
1690 Elements of notation can be marked and named with the help of a square
1691 balloon.  The primary purpose of this feature is to explain notation.
1692
1693 The following example demonstrates its use.
1694
1695 @lilypond[quote,verbatim,fragment,raggedright,relative=2]
1696 \context Voice {
1697   \applyoutput
1698     #(add-balloon-text 'NoteHead "heads, or tails?"
1699     '(1 . -3))
1700   c8
1701 }
1702 @end lilypond
1703
1704 @noindent
1705 The function @code{add-balloon-text} takes the name of a grob, the
1706 label to print, and the position where to put the label relative to
1707 the object.  In the above example, the text ``heads or tails?'' ends
1708 3 spaces below and 1 space to the right of the marked head.
1709
1710 @cindex balloon
1711 @cindex notation, explaining
1712
1713 @seealso
1714
1715 Program reference: @internalsref{text-balloon-interface}.
1716
1717 Examples: @inputfileref{input/@/regression,balloon@/.ly}.
1718
1719
1720
1721
1722 @node Blank music sheet
1723 @subsection Blank music sheet
1724
1725 A blank music sheet can be produced also by using invisible notes, and
1726 removing @code{Bar_number_engraver}.
1727
1728
1729 @lilypond[quote,verbatim]
1730 emptymusic = {
1731   \repeat unfold 2 % Change this for more lines.
1732   { s1\break }
1733   \bar "|."
1734 }
1735 \new Score \with {
1736   \override TimeSignature #'transparent = ##t
1737   defaultBarType = #""
1738   \remove Bar_number_engraver
1739 } <<
1740   \context Staff \emptymusic
1741   \context TabStaff \emptymusic
1742 >>
1743 @end lilypond
1744
1745
1746 @node Hidden notes
1747 @subsection Hidden notes
1748
1749 @cindex Hidden notes
1750 @cindex Invisible notes
1751 @cindex Transparent notes
1752
1753 @cindex @code{\hideNotes}
1754 @cindex @code{\unHideNotes}
1755 Hidden (or invisible or transparent) notes can be useful in preparing theory
1756 or composition exercises.
1757
1758 @lilypond[quote,raggedright,verbatim,relative=2,fragment]
1759 c4 d4
1760 \hideNotes
1761 e4 f4
1762 \unHideNotes
1763 g4 a
1764 @end lilypond
1765
1766 Hidden notes are also great for performing weird tricks.  For example,
1767 slurs cannot be attached to rests or spacer rests, but you may wish
1768 to include that in your score -- string instruments use this notation
1769 when doing pizzicato to indicate that the note should ring for as long
1770 as possible.
1771
1772 @lilypond[quote,raggedright,verbatim,relative=0,fragment]
1773 \clef bass
1774 << {
1775   c4^"pizz"( \hideNotes c)
1776   \unHideNotes c( \hideNotes c)
1777 } {
1778   s4 r s r
1779 } >>
1780 @end lilypond
1781
1782
1783 @node Shaped note heads 
1784 @subsection Shaped note heads 
1785
1786 In shaped note head notation, the shape of the note head corresponds
1787 to the harmonic function of a note in the scale.  This notation was
1788 popular in the 19th century American song books.
1789
1790 Shaped note heads can be produced by setting @code{\aikenHeads} or
1791 @code{\sacredHarpHeads}, depending on the style desired.
1792
1793 @lilypond[verbatim,relative=1,fragment]
1794   \aikenHeads
1795   c8 d4 e8 a2 g1
1796   \sacredHarpHeads
1797   c8 d4. e8 a2 g1
1798 @end lilypond
1799
1800 Shapes are determined on the step in the scale, where the base of the
1801 scale is determined by  the @code{\key} command
1802
1803 @findex \key
1804 @findex shapeNoteStyles
1805 @findex \aikenHeads
1806 @findex \sacredHarpHeads
1807
1808 Shaped note heads are implemented through the @code{shapeNoteStyles}
1809 property.  Its value is a vector of symbols.  The k-th element indicates
1810 the style to use for the k-th step of the scale.  Arbitrary
1811 combinations are possible, eg.,
1812
1813
1814 @lilypond[verbatim,relative=1,fragment]
1815   \set shapeNoteStyles  = ##(cross triangle fa #f mensural xcircle diamond)
1816   c8 d4. e8 a2 g1
1817 @end lilypond
1818
1819
1820 @node Easy Notation note heads
1821 @subsection Easy Notation note heads
1822
1823 @cindex easy notation
1824 @cindex Hal Leonard
1825
1826 The `easy play' note head includes a note name inside the head.  It is
1827 used in music for beginners
1828
1829 @lilypond[quote,raggedright,verbatim,fragment,staffsize=26]
1830   \setEasyHeads
1831   c'2 e'4 f' | g'1
1832 @end lilypond
1833
1834 The command @code{\setEasyHeads} overrides settings for the
1835 @internalsref{NoteHead} object.  To make the letters readable, it has
1836 to be printed in a large font size.  To print with a larger font, see
1837 @ref{Setting global staff size}.
1838
1839 @refcommands
1840
1841 @cindex @code{\setEasyHeads}
1842 @code{\setEasyHeads}
1843
1844
1845 @node Analysis brackets
1846 @subsection Analysis brackets
1847 @cindex brackets
1848 @cindex phrasing brackets
1849 @cindex musicological analysis
1850 @cindex note grouping bracket
1851
1852 Brackets are used in musical analysis to indicate structure in musical
1853 pieces.  LilyPond supports a simple form of nested horizontal
1854 brackets.  To use this, add the @internalsref{Horizontal_bracket_engraver}
1855 to @internalsref{Staff} context.  A bracket is started with
1856 @code{\startGroup} and closed with @code{\stopGroup}
1857
1858 @lilypond[quote,raggedright,verbatim]
1859 \score {
1860   \relative c'' {
1861     c4\startGroup\startGroup
1862     c4\stopGroup
1863     c4\startGroup
1864     c4\stopGroup\stopGroup
1865   }
1866   \layout {
1867     \context {
1868       \Staff \consists "Horizontal_bracket_engraver"
1869 }}}
1870 @end lilypond
1871
1872 @seealso
1873
1874 Program reference: @internalsref{HorizontalBracket},
1875 @internalsref{NoteGroupingEvent}.
1876
1877 Examples: @inputfileref{input/@/regression,note@/-group@/-bracket@/.ly}.
1878
1879
1880
1881 @ignore
1882
1883 I don't think we need this info.
1884
1885 @n ode Stems
1886 @s ubsection Stems
1887
1888 Whenever a note is found, a @internalsref{Stem} object is created
1889 automatically.  For whole notes and rests, they are also created but
1890 made invisible.
1891
1892 @refcommands
1893
1894 @cindex @code{\stemUp}
1895 @code{\stemUp},
1896 @cindex @code{\stemDown}
1897 @code{\stemDown},
1898 @cindex @code{\stemNeutral}
1899 @code{\stemNeutral}.
1900
1901 @end ignore
1902
1903
1904 @node Coloring objects
1905 @subsection Coloring objects
1906
1907 @c FIXME: need link to missing list of colors
1908 Individual objects may be assigned colors.  You may use color names
1909 listed HERE
1910
1911 @lilypond[quote,raggedright,verbatim,fragment]
1912 \override NoteHead #'color = #red
1913 c4 c
1914 \override NoteHead #'color = #(x11-color 'LimeGreen)
1915 d
1916 \override Stem #'color = #blue
1917 e
1918 @end lilypond
1919
1920 The full range of colors defined for X11 can be accessed by using the
1921 scheme function x11-color.  The function takes one argument that can be a
1922 symbol
1923
1924 @example
1925 \override Beam #'color = #(x11-color 'MediumTurquoise)
1926 @end example
1927
1928 or a string
1929
1930 @example
1931 \override Beam #'color = #(x11-color "MediumTurquoise")
1932 @end example
1933
1934 The first form is quicker to write and is more efficient.  However, using
1935 the second form it is possible to access X11 colors by the multi-word
1936 form of its name
1937
1938 @example
1939 \override Beam #'color = #(x11-color "medium turquoise")
1940 @end example
1941
1942 If x11-color cannot make sense of the parameter then the color returned
1943 defaults to black.  It should be obvious from the final score that
1944 something is wrong.
1945
1946 This example, illustrates the use of x11-color.  Notice that the stem
1947 color remains black after being set to (x11-color 'Boggle), which is
1948 deliberate nonsense.
1949
1950 @lilypond[quote,raggedright,verbatim]
1951 {
1952   \override Staff.StaffSymbol #'color = #(x11-color 'SlateBlue2)
1953   \set Staff.instrument = \markup {
1954     \with-color #(x11-color 'navy) "Clarinet"
1955   }
1956   \time 2/4
1957   gis''8 a''
1958   \override Beam #'color = #(x11-color "medium turquoise")
1959   gis'' a''
1960   \override NoteHead #'color = #(x11-color "LimeGreen")
1961   gis'' a''
1962   \override Stem #'color = #(x11-color 'Boggle)
1963   gis'' a''
1964 }
1965 @end lilypond
1966
1967
1968 @refbugs
1969 Not all x11 colors are distinguishable in a web browser.  For web use
1970 normal colors are recommended. 
1971
1972 An x11 color is not necessarily exactly the same shade as a similarly
1973 named normal color. 
1974
1975
1976 @seealso
1977
1978 COLORLIST
1979
1980
1981 @node Automatic notation
1982 @section Automatic notation
1983
1984 This section describes how to change the way that accidentals and
1985 beams are automatically displayed.
1986
1987 FIXME: this might get moved into Changing Defaults.  Please send
1988 opinions to lilypond-devel.  Thanks!  :)
1989
1990 @menu
1991 * Automatic accidentals::       
1992 * Setting automatic beam behavior::  
1993 * Beam formatting::             
1994 @end menu
1995
1996 @node Automatic accidentals
1997 @subsection Automatic accidentals
1998 @cindex Automatic accidentals
1999
2000 Common rules for typesetting accidentals have been placed in a
2001 function.  This function is called as follows
2002
2003 @cindex @code{set-accidental-style}
2004 @example
2005 #(set-accidental-style 'STYLE #('CONTEXT#))
2006 @end example
2007
2008 The function can take two arguments: the name of the accidental style,
2009 and an optional argument that denotes the context that should be
2010 changed.  If no context name is supplied, @code{Staff} is the default,
2011 but you may wish to apply the accidental style to a single @code{Voice}
2012 instead.
2013
2014 The following accidental styles are supported
2015 @table @code
2016 @item default
2017 This is the default typesetting behavior.  It corresponds
2018 to 18th century common practice: Accidentals are
2019 remembered to the end of the measure in which they occur and
2020 only on their own octave.
2021
2022 @item voice
2023 The normal behavior is to remember the accidentals on
2024 Staff-level.  This variable, however, typesets accidentals
2025 individually for each voice.  Apart from that, the rule is similar to
2026 @code{default}.
2027
2028 As a result, accidentals from one voice do not get canceled in other
2029 voices, which is often an unwanted result
2030
2031 @lilypond[quote,raggedright,relative=1,fragment,verbatim]
2032 \context Staff <<
2033   #(set-accidental-style 'voice)
2034   <<
2035     { es g } \\
2036     { c, e }
2037 >> >>
2038 @end lilypond
2039
2040 The @code{voice} option should be used if the voices
2041 are to be read solely by individual musicians.  If the staff is to be
2042 used by one musician (e.g., a conductor) then
2043 @code{modern} or @code{modern-cautionary}
2044 should be used instead.
2045
2046 @item modern
2047 @cindex @code{modern} style accidentals
2048 This rule corresponds to the common practice in the 20th century.  This rule
2049 prints the same accidentals as @code{default}, but temporary
2050 accidentals also are canceled in other octaves.  Furthermore,
2051 in the same octave, they also get canceled in the following
2052 measure
2053
2054 @lilypond[quote,raggedright,fragment,verbatim]
2055 #(set-accidental-style 'modern)
2056 cis' c'' cis'2 | c'' c'
2057 @end lilypond
2058
2059 @item @code{modern-cautionary}
2060 @cindex @code{modern-cautionary}
2061 This rule is similar to @code{modern}, but the ``extra'' accidentals
2062 (the ones not typeset by @code{default}) are typeset as cautionary
2063 accidentals.  They are printed in reduced size or with parentheses
2064 @lilypond[quote,raggedright,fragment,verbatim]
2065 #(set-accidental-style 'modern-cautionary)
2066 cis' c'' cis'2 | c'' c'
2067 @end lilypond
2068
2069 @cindex @code{modern-voice}
2070 @item modern-voice
2071 This rule is used for multivoice accidentals to be read both by musicians
2072 playing one voice and musicians playing all voices.  Accidentals are
2073 typeset for each voice, but they @emph{are} canceled across voices in
2074 the same @internalsref{Staff}.
2075
2076 @cindex @code{modern-voice-cautionary}
2077 @item modern-voice-cautionary
2078 This rule is the same as @code{modern-voice}, but with the extra
2079 accidentals (the ones not typeset by @code{voice}) typeset
2080 as cautionaries.  Even though all accidentals typeset by
2081 @code{default} @emph{are} typeset by this variable,
2082 some of them are typeset as cautionaries.
2083
2084 @item piano
2085 @cindex @code{piano} accidentals
2086 This rule reflects 20th century practice for piano notation.  Very similar to
2087 @code{modern} but accidentals also get canceled
2088 across the staves in the same @internalsref{GrandStaff} or
2089 @internalsref{PianoStaff}.
2090
2091 @item piano-cautionary
2092 @cindex @code{#(set-accidental-style 'piano-cautionary)}
2093 Same as @code{#(set-accidental-style 'piano)} but with the extra
2094 accidentals typeset as cautionaries.
2095
2096 @item no-reset
2097 @cindex @code{no-reset} accidental style
2098 This is the same as @code{default} but with accidentals lasting
2099 ``forever'' and not only until the next measure
2100 @lilypond[quote,raggedright,fragment,verbatim,relative=1]
2101 #(set-accidental-style 'no-reset)
2102 c1 cis cis c
2103 @end lilypond
2104
2105 @item forget
2106 This is sort of the opposite of @code{no-reset}: Accidentals
2107 are not remembered at all---and hence all accidentals are
2108 typeset relative to the key signature, regardless of what was
2109 before in the music
2110
2111 @lilypond[quote,raggedright,fragment,verbatim,relative=1]
2112 #(set-accidental-style 'forget)
2113 \key d\major c4 c cis cis d d dis dis
2114 @end lilypond
2115 @end table
2116
2117
2118 @seealso
2119
2120 Program reference: @internalsref{Accidental_engraver},
2121 @internalsref{Accidental}, and @internalsref{AccidentalPlacement}.
2122
2123
2124 @refbugs
2125
2126 Simultaneous notes are considered to be entered in sequential
2127 mode.  This means that in a chord the accidentals are typeset as if the
2128 notes in the chord happened once at a time - in the order in which
2129 they appear in the input file.
2130
2131 This is a problem when accidentals in a chord depend on each other,
2132 which does not happen for the default accidental style.  The problem
2133 can be solved by manually inserting @code{!} and @code{?} for the
2134 problematic notes.
2135
2136
2137 @node Setting automatic beam behavior
2138 @subsection Setting automatic beam behavior
2139
2140 @cindex @code{autoBeamSettings}
2141 @cindex @code{(end * * * *)}
2142 @cindex @code{(begin * * * *)}
2143 @cindex automatic beams, tuning
2144 @cindex tuning automatic beaming
2145
2146 @c [TODO: use \applycontext]
2147
2148 In normal time signatures, automatic beams can start on any note but can
2149 only end in a few positions within the measure: beams can end on a beat,
2150 or at durations specified by the properties in
2151 @code{autoBeamSettings}.  The defaults for @code{autoBeamSettings}
2152 are defined in @file{scm/@/auto@/-beam@/.scm}.
2153
2154 The value of @code{autoBeamSettings} is changed with three functions,
2155 @example
2156 #(override-auto-beam-setting
2157    '(@var{be} @var{p} @var{q} @var{n} @var{m}) @var{a} @var{b}
2158    [@var{context}])
2159 #(score-override-auto-beam-setting
2160    '(@var{be} @var{p} @var{q} @var{n} @var{m}) @var{a} @var{b})
2161 #(revert-auto-beam-setting '(@var{be} @var{p} @var{q} @var{n} @var{m})
2162    [@var{context}])
2163 @end example
2164 Here, @var{be} is the symbol @code{begin} or @code{end}, and
2165 @var{context} is an optional context (default: @code{'Voice}).  It
2166 determines whether the rule applies to begin or end-points.  The
2167 quantity @var{p}/@var{q} refers to the length of the beamed notes (and
2168 `@code{* *}' designates notes of any length), @var{n}/@var{M} refers
2169 to a time signature (wildcards `@code{* *}' may be entered to
2170 designate all time signatures), @var{a}/@var{b} is a duration.  By
2171 default, this command changes settings for the current voice.  It is
2172 also possible to adjust settings at higher contexts, by adding a
2173 @var{context} argument.  @code{score-override-auto-beam-setting} is
2174 equal to @code{override-auto-beam-setting} with the argument
2175 @var{context} set to @code{'Score}.
2176
2177 For example, if automatic beams should end on the first quarter note, use
2178 the following
2179 @example
2180 #(override-auto-beam-setting '(end * * * *) 1 4 'Staff)
2181 @end example
2182 Since the duration of a quarter note is 1/4 of a whole note, it is
2183 entered as @code{(ly:make-moment 1 4)}.
2184
2185 If automatic beams should end on every quarter in 5/4 time, specify
2186 all endings
2187 @example
2188 #(override-auto-beam-setting '(end * * * *) 1 4 'Staff)
2189 #(override-auto-beam-setting '(end * * * *) 1 2 'Staff)
2190 #(override-auto-beam-setting '(end * * * *) 3 4 'Staff)
2191 #(override-auto-beam-setting '(end * * * *) 5 4 'Staff)
2192 @dots{}
2193 @end example
2194
2195 The same syntax can be used to specify beam starting points.  In this
2196 example, automatic beams can only end on a dotted quarter note
2197 @example
2198 #(override-auto-beam-setting '(end * * * *) 3 8)
2199 #(override-auto-beam-setting '(end * * * *) 1 2)
2200 #(override-auto-beam-setting '(end * * * *) 7 8)
2201 @end example
2202 In 4/4 time signature, this means that automatic beams could end only on
2203 3/8 and on the fourth beat of the measure (after 3/4, that is 2 times
2204 3/8, has passed within the measure).
2205
2206 Rules can also be restricted to specific time signatures.  A rule that
2207 should only be applied in @var{N}/@var{M} time signature is formed by
2208 replacing the second asterisks by @var{N} and @var{M}.  For example, a
2209 rule for 6/8 time exclusively looks like
2210 @example
2211 #(override-auto-beam-setting '(begin * * 6 8) @dots{})
2212 @end example
2213
2214 If a rule should be to applied only to certain types of beams, use the
2215 first pair of asterisks.  Beams are classified according to the
2216 shortest note they contain.  For a beam ending rule that only applies
2217 to beams with 32nd notes (and no shorter notes), use @code{(end 1 32 *
2218 *)}.
2219
2220 For example,
2221
2222 @lilypond[quote,raggedright,relative=2,fragment,verbatim]
2223 \time 5/8
2224 #(override-auto-beam-setting '(end * * 5 8) 2 8)
2225 c8 c d d d
2226 \time 4/4
2227 e8 e f f e e d d
2228 \time 5/8
2229 c8 c d d d
2230 @end lilypond
2231
2232 @cindex automatic beam generation
2233 @cindex autobeam
2234 @cindex @code{autoBeaming}
2235 @cindex lyrics
2236
2237 If beams are used to indicate melismata in songs, then automatic
2238 beaming should be switched off.  This is done by setting
2239 @code{autoBeaming} to @code{#f}.
2240
2241 @refcommands
2242
2243 @cindex @code{\autoBeamOff}
2244 @code{\autoBeamOff},
2245 @cindex @code{\autoBeamOn}
2246 @code{\autoBeamOn}.
2247
2248
2249 @refbugs
2250
2251 If a score ends while an automatic beam has not been ended and is
2252 still accepting notes, this last beam will not be typeset at all.  The
2253 same holds polyphonic voices, entered with @code{<< @dots{} \\ @dots{}
2254 >>}.  If a polyphonic voice ends while an automatic beam is still
2255 accepting notes, it is not typeset.
2256
2257 @node Beam formatting
2258 @subsection Beam formatting
2259
2260 When a beam falls in the middle of the staff, the beams point normally
2261 down.  However, this behaviour can be altered with the
2262 @code{neutral-direction} property.
2263
2264 @lilypond[quote,raggedright,relative=2,fragment,verbatim]
2265 {
2266   b8[ b]
2267   \override Beam #'neutral-direction = #-1
2268   b[ b]
2269   \override Beam #'neutral-direction = #1
2270   b[ b]
2271 }
2272 @end lilypond
2273
2274