]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/changing-defaults.itely
NR: General tidy up - @seealso @knownissue spacing
[lilypond.git] / Documentation / notation / changing-defaults.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @c \version "2.15.20"
12
13 @node Changing defaults
14 @chapter Changing defaults
15
16 The purpose of LilyPond's design is to provide the finest quality
17 output by default.  Nevertheless, it may happen that you need to
18 change this default layout.  The layout is controlled through a large
19 number of @q{knobs and switches} collectively called @q{properties}.
20 A tutorial introduction to accessing and modifying these properties
21 can be found in the Learning Manual, see @rlearning{Tweaking output}.
22 This should be read first.  This chapter covers similar ground, but
23 in a style more appropriate to a reference manual.
24
25 @cindex Internals Reference
26
27 The definitive description of the controls available for tuning can
28 be found in a separate document: @rinternalsnamed{Top,the Internals
29 Reference}.  That manual lists all the variables, functions and
30 options available in LilyPond.  It is written as a HTML document,
31 which is available
32 @c leave the @uref as one long line.
33 @uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/internals/,on@/-line},
34 and is also included with the LilyPond documentation package.
35
36 Internally, LilyPond uses Scheme (a LISP dialect) to provide
37 infrastructure.  Overriding layout decisions in effect accesses the
38 program internals, which requires Scheme input.  Scheme elements are
39 introduced in a @file{.ly} file with the hash
40 mark@tie{}@code{#}.@footnote{@rextend{Scheme tutorial}, contains a
41 short tutorial on entering numbers, lists, strings, and symbols in
42 Scheme.}
43
44
45 @menu
46 * Interpretation contexts::
47 * Explaining the Internals Reference::
48 * Modifying properties::
49 * Useful concepts and properties::
50 * Advanced tweaks::
51 * Using music functions::
52 @end menu
53
54
55 @node Interpretation contexts
56 @section Interpretation contexts
57
58 This section describes what contexts are, and how to modify them.
59
60 @menu
61 * Contexts explained::
62 * Creating contexts::
63 * Keeping contexts alive::
64 * Modifying context plug-ins::
65 * Changing context default settings::
66 * Defining new contexts::
67 * Context layout order::
68 @end menu
69
70 @seealso
71 Learning Manual:
72 @rlearning{Contexts and engravers}.
73
74 Installed Files:
75 @file{ly/engraver-init.ly},
76 @file{ly/performer-init.ly}.
77
78 Snippets:
79 @rlsr{Contexts and engravers}.
80
81 Internals Reference:
82 @rinternals{Contexts},
83 @rinternals{Engravers and Performers}.
84
85
86 @node Contexts explained
87 @subsection Contexts explained
88
89 @ignore
90 @c TODO Rethink and rewrite
91
92 >> > > - list of contexts: my *danger unmaintainable*
93 >> > > alarm just went off.  I'm
94
95 I knew it would... And leaving out some of them is perfectly fine
96 with me.
97 I do think that a list like this, with the main contexts and a
98 brief
99 description of  what they do (perhaps also with a note about what
100 default
101 behavior is associated with each of them, but this may be
102 unmanageable),
103 should be there, and then we could simply list the remaining ones
104 without
105 further explanation and with links to the IR.
106 @end ignore
107
108 @c TODO Improve layout, order and consistency of wording -td
109
110 @c TODO Add introduction which explains contexts in generality  -td
111
112 @c TODO Describe propagation of property values -td
113
114 Contexts are arranged hierarchically:
115
116 @menu
117 * Score - the master of all contexts::
118 * Top-level contexts - staff containers::
119 * Intermediate-level contexts - staves::
120 * Bottom-level contexts - voices::
121 @end menu
122
123 @node Score - the master of all contexts
124 @unnumberedsubsubsec Score - the master of all contexts
125
126 This is the top level notation context.  No other context can
127 contain a Score context.  By default the Score context handles
128 the administration of time signatures and makes sure that items
129 such as clefs, time signatures, and key-signatures are aligned
130 across staves.
131
132 A Score context is instantiated implicitly when a
133 @code{\score @{@dots{}@}} or @code{\layout @{@dots{}@}} block is
134 processed.
135
136 @node Top-level contexts - staff containers
137 @unnumberedsubsubsec Top-level contexts - staff containers
138
139 @strong{@emph{StaffGroup}}
140
141 Groups staves while adding a bracket on the left side, grouping
142 the staves together.  The bar lines of the contained staves are
143 connected vertically.  @code{StaffGroup} only consists of a collection
144 of staves, with a bracket in front and spanning bar lines.
145
146 @strong{@emph{ChoirStaff}}
147
148 Identical to @code{StaffGroup} except that the bar lines of the
149 contained staves are not connected vertically.
150
151 @strong{@emph{GrandStaff}}
152
153 A group of staves, with a brace on the left side, grouping the
154 staves together.  The bar lines of the contained staves are
155 connected vertically.
156
157 @strong{@emph{PianoStaff}}
158
159 Just like @code{GrandStaff}, but with support for instrument names
160 to the left of each system.
161
162 @node Intermediate-level contexts - staves
163 @unnumberedsubsubsec Intermediate-level contexts - staves
164
165 @strong{@emph{Staff}}
166
167 Handles clefs, bar lines, keys, accidentals.  It can contain
168 @code{Voice} contexts.
169
170 @strong{@emph{RhythmicStaff}}
171
172 Like @code{Staff} but for printing rhythms.  Pitches are ignored;
173 the notes are printed on one line.
174
175 @strong{@emph{TabStaff}}
176
177 Context for generating tablature.  By default lays the music
178 expression out as a guitar tablature, printed on six lines.
179
180 @strong{@emph{DrumStaff}}
181
182 Handles typesetting for percussion.  Can contain @code{DrumVoice}
183
184 @strong{@emph{VaticanaStaff}}
185
186 Same as @code{Staff}, except that it is designed for typesetting
187 a piece in gregorian style.
188
189 @strong{@emph{MensuralStaff}}
190
191 Same as @code{Staff}, except that it is designed for typesetting
192 a piece in mensural style.
193
194 @node Bottom-level contexts - voices
195 @unnumberedsubsubsec Bottom-level contexts - voices
196
197 Voice-level contexts initialise certain properties and start
198 appropriate engravers.  Being bottom-level contexts, they cannot
199 contain other contexts.
200
201 @strong{@emph{Voice}}
202
203 Corresponds to a voice on a staff.  This context handles the
204 conversion of dynamic signs, stems, beams, super- and sub-scripts,
205 slurs, ties, and rests.  You have to instantiate this explicitly
206 if you require multiple voices on the same staff.
207
208 @strong{@emph{VaticanaVoice}}
209
210 Same as @code{Voice}, except that it is designed for typesetting
211 a piece in gregorian style.
212
213 @strong{@emph{MensuralVoice}}
214
215 Same as @code{Voice}, with modifications for typesetting a piece in
216 mensural style.
217
218 @strong{@emph{Lyrics}}
219
220 Corresponds to a voice with lyrics.  Handles the printing of a
221 single line of lyrics.
222
223 @strong{@emph{DrumVoice}}
224
225 The voice context used in a percussion staff.
226
227 @strong{@emph{FiguredBass}}
228
229 The context in which @code{BassFigure} objects are created from
230 input entered in @code{\figuremode} mode.
231
232 @strong{@emph{TabVoice}}
233
234 The voice context used within a @code{TabStaff} context.  Usually
235 left to be created implicitly.
236
237 @strong{@emph{CueVoice}}
238
239 A voice context used to render notes of a reduced size, intended
240 primarily for adding cue notes to a staff, see @ref{Formatting
241 cue notes}.  Usually left to be created implicitly.
242
243 @strong{@emph{ChordNames}}
244
245 Typesets chord names.
246
247 @ignore
248 TODO
249
250 Then the following, which I don't know what to do with:
251
252     * GregorianTranscriptionVoice
253     * GregorianTranscriptionStaff
254
255     * FretBoards
256         Engraves fretboards from chords. Not easy... Not
257 documented.
258         There is now some documentation on FretBoards in the NR, under
259          instrument-specific notation -- cds.
260
261     * NoteNames
262
263     * Global
264         Hard coded entry point for LilyPond. Cannot be tuned.
265     * Devnull
266         Silently discards all musical information given to this
267 context.
268
269 @end ignore
270
271 @node Creating contexts
272 @subsection Creating contexts
273
274 @c TODO more complete descriptions rather than learning style
275
276 For scores with only one voice and one staff, contexts are
277 created automatically.  For more complex scores, it is necessary to
278 create them by hand.  There are three commands that do this.
279
280 @itemize
281
282 @item
283 The easiest command is @code{\new}, and it also the quickest to type.
284 It is prepended to a music expression, for example
285
286 @funindex \new
287 @cindex new contexts
288 @cindex Context, creating
289
290 @example
291 \new @var{type} @var{music expression}
292 @end example
293
294 @noindent
295 where @var{type} is a context name (like @code{Staff} or
296 @code{Voice}).  This command creates a new context, and starts
297 interpreting the @var{music expression} with that.
298
299 A practical application of @code{\new} is a score with many
300 staves.  Each part that should be on its own staff, is preceded with
301 @code{\new Staff}.
302
303 @lilypond[quote,verbatim,relative=2,ragged-right]
304 <<
305   \new Staff { c4 c }
306   \new Staff { d4 d }
307 >>
308 @end lilypond
309
310 The @code{\new} command may also give a name to the context,
311
312 @example
313 \new @var{type} = @var{id} @var{music}
314 @end example
315 However, this user specified name is only used if there is no other
316 context already earlier with the same name.
317
318
319 @funindex \context
320
321 @item
322 Like @code{\new}, the @code{\context} command also directs a music
323 expression to a context object, but gives the context an explicit name.  The
324 syntax is
325
326 @example
327 \context @var{type} = @var{id} @var{music}
328 @end example
329
330 This form will search for an existing context of type @var{type}
331 called @var{id}.  If that context does not exist yet, a new
332 context with the specified name is created.  This is useful if
333 the context is referred to later on.  For example, when
334 setting lyrics the melody is in a named context
335
336 @example
337 \context Voice = "@b{tenor}" @var{music}
338 @end example
339
340 @noindent
341 so the texts can be properly aligned to its notes,
342
343 @example
344 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
345 @end example
346
347 @noindent
348
349 Another possible use of named contexts is funneling two different
350 music expressions into one context.  In the following example,
351 articulations and notes are entered separately,
352
353 @example
354 music = @{ c4 c4 @}
355 arts = @{ s4-. s4-> @}
356 @end example
357
358 They are combined by sending both to the same @code{Voice} context,
359
360 @example
361 <<
362   \new Staff \context Voice = "A" \music
363   \context Voice = "A" \arts
364 >>
365 @end example
366 @lilypond[quote,ragged-right]
367 music = { c4 c4 }
368 arts = { s4-. s4-> }
369 \relative c'' <<
370   \new Staff \context Voice = "A" \music
371   \context Voice = "A" \arts
372 >>
373 @end lilypond
374
375 With this mechanism, it is possible to define an Urtext (original
376 edition), with the option to put several distinct articulations on the
377 same notes.
378
379 @cindex creating contexts
380
381 @item
382 The third command for creating contexts is
383 @example
384 \context @var{type} @var{music}
385 @end example
386
387
388 @noindent
389 This is similar to @code{\context} with @code{= @var{id}}, but matches
390 any context of type @var{type}, regardless of its given name.
391
392 This variant is used with music expressions that can be interpreted at
393 several levels.  For example, the @code{\applyOutput} command (see
394 @rextend{Running a function on all layout objects}).  Without an explicit
395 @code{\context}, it is usually applied to @code{Voice}
396
397 @example
398 \applyOutput #'@var{context} #@var{function}   % apply to Voice
399 @end example
400
401 To have it interpreted at the @code{Score} or @code{Staff} level use
402 these forms
403
404 @example
405 \applyOutput #'Score #@var{function}
406 \applyOutput #'Staff #@var{function}
407 @end example
408
409 @end itemize
410
411 @node Keeping contexts alive
412 @subsection Keeping contexts alive
413
414 @cindex contexts, keeping alive
415 @cindex contexts, lifetime
416
417 Contexts are usually terminated at the first musical moment in
418 which they have nothing to do.  So @code{Voice} contexts die as
419 soon as they contain no events; @code{Staff} contexts die as soon
420 as all the @code{Voice} contexts within them contain no events; etc.
421 This can cause difficulties if earlier contexts which have died
422 have to be referenced, for example, when changing staves with
423 @code{\change} commands, associating lyrics with a voice with
424 @code{\lyricsto} commands, or when adding further musical events to
425 an earlier context.
426
427 There is an exception to this general rule: just one of the
428 @code{Voice} contexts in a @code{Staff} context or in a
429 @code{<<...>>} construct will always persist to the end of the
430 enclosing @code{Staff} context or @code{<<...>>} construct, even
431 though there may be periods when it has nothing to do.  The context
432 to persist in this way will be the first one encountered in the
433 first enclosed @code{@{...@}} construct, ignoring any in enclosed
434 @code{<<...>>} constructs.
435
436 Any context can be kept alive by ensuring it has something to do at
437 every musical moment.  @code{Staff} contexts are kept alive by
438 ensuring one of their voices is kept alive.  One way of doing this
439 is to add spacer rests to a voice in parallel with the real music.
440 These need to be added to every @code{Voice} context which needs to
441 be kept alive.  If several voices are to be used sporadically it is
442 safest to keep them all alive rather than attempting to rely on the
443 exceptions mentioned above.
444
445 In the following example, both voice A and voice B are kept alive
446 in this way for the duration of the piece:
447
448 @lilypond[quote,verbatim]
449 musicA = \relative c'' { d4 d d d }
450 musicB = \relative c'' { g4 g g g }
451 keepVoicesAlive = {
452   <<
453     \new Voice = "A" { s1*5 }  % Keep Voice "A" alive for 5 bars
454     \new Voice = "B" { s1*5 }  % Keep Voice "B" alive for 5 bars
455   >>
456 }
457
458 music = {
459   \context Voice = "A" {
460     \voiceOneStyle
461     \musicA
462   }
463   \context Voice = "B" {
464     \voiceTwoStyle
465     \musicB
466   }
467   \context Voice = "A" { \musicA }
468   \context Voice = "B" { \musicB }
469   \context Voice = "A" { \musicA }
470 }
471
472 \score {
473   \new Staff <<
474     \keepVoicesAlive
475     \music
476   >>
477 }
478 @end lilypond
479
480 @cindex lyrics, aligning with sporadic melody
481
482 The following example shows how a sporadic melody line with lyrics
483 might be written using this approach.  In a real situation the
484 melody and accompaniment would consist of several different
485 sections, of course.
486
487 @lilypond[quote,verbatim]
488 melody = \relative c'' { a4 a a a }
489 accompaniment = \relative c' { d4 d d d }
490 words = \lyricmode { These words fol -- low the mel -- o -- dy }
491 \score {
492   <<
493     \new Staff = "music" {
494       <<
495         \new Voice = "melody" {
496           \voiceOne
497           s1*4  % Keep Voice "melody" alive for 4 bars
498         }
499         {
500           \new Voice = "accompaniment" {
501             \voiceTwo
502             \accompaniment
503           }
504           <<
505             \context Voice = "melody" { \melody }
506             \context Voice = "accompaniment" { \accompaniment }
507           >>
508           \context Voice = "accompaniment" { \accompaniment }
509           <<
510             \context Voice = "melody" { \melody }
511             \context Voice = "accompaniment" { \accompaniment }
512           >>
513         }
514       >>
515     }
516     \new Lyrics \with { alignAboveContext = #"music" }
517     \lyricsto "melody" { \words }
518   >>
519 }
520 @end lilypond
521
522 An alternative way, which may be better in many circumstances, is
523 to keep the melody line alive by simply including spacer notes to
524 line it up correctly with the accompaniment:
525
526 @lilypond[quote,verbatim]
527 melody = \relative c'' {
528   s1  % skip a bar
529   a4 a a a
530   s1  % skip a bar
531   a4 a a a
532 }
533 accompaniment = \relative c' {
534   d4 d d d
535   d4 d d d
536   d4 d d d
537   d4 d d d
538 }
539 words = \lyricmode { These words fol -- low the mel -- o -- dy }
540
541 \score {
542   <<
543     \new Staff = "music" {
544       <<
545         \new Voice = "melody" {
546           \voiceOne
547           \melody
548         }
549         \new Voice = "accompaniment" {
550           \voiceTwo
551           \accompaniment
552         }
553       >>
554     }
555     \new Lyrics \with { alignAboveContext = #"music" }
556     \lyricsto "melody" { \words }
557   >>
558 }
559 @end lilypond
560
561
562 @node Modifying context plug-ins
563 @subsection Modifying context plug-ins
564
565 @c TODO Should this be Modifying engravers or Modifying contexts?
566
567 Notation contexts (like @code{Score} and @code{Staff}) not only
568 store properties,
569 they also contain plug-ins called @q{engravers} that create notation
570 elements.  For example, the @code{Voice} context contains a
571 @code{Note_heads_engraver} and the @code{Staff} context contains a
572 @code{Key_signature_engraver}.
573
574 For a full a description of each plug-in, see
575 @ifhtml
576 @rinternals{Engravers and Performers}.
577 @end ifhtml
578 @ifnothtml
579 Internals Reference @expansion{} Translation @expansion{} Engravers.
580 @end ifnothtml
581 Every context described in
582 @ifhtml
583 @rinternals{Contexts}
584 @end ifhtml
585 @ifnothtml
586 Internals Reference @expansion{} Translation @expansion{} Context.
587 @end ifnothtml
588 lists the engravers used for that context.
589
590
591 It can be useful to shuffle around these plug-ins.  This is done by
592 starting a new context with @code{\new} or @code{\context}, and
593 modifying it,
594
595 @funindex \with
596
597 @example
598 \new @var{context} \with @{
599   \consists @dots{}
600   \consists @dots{}
601   \remove @dots{}
602   \remove @dots{}
603   @emph{etc.}
604 @}
605 @{
606   @emph{..music..}
607 @}
608 @end example
609
610 @noindent
611 where the @dots{} should be the name of an engraver.  Here is a simple
612 example which removes @code{Time_signature_engraver} and
613 @code{Clef_engraver} from a @code{Staff} context,
614
615 @lilypond[quote,relative=1,verbatim]
616 <<
617   \new Staff {
618     f2 g
619   }
620   \new Staff \with {
621      \remove "Time_signature_engraver"
622      \remove "Clef_engraver"
623   } {
624     f2 g2
625   }
626 >>
627 @end lilypond
628
629 In the second staff there are no time signature or clef symbols.  This
630 is a rather crude method of making objects disappear since it will affect
631 the entire staff.  This method also influences the spacing, which may or
632 may not be desirable.  More sophisticated methods of blanking objects
633 are shown in @rlearning{Visibility and color of objects}.
634
635 The next example shows a practical application.  Bar lines and time
636 signatures are normally synchronized across the score.  This is done
637 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
638 This plug-in keeps an administration of time signature, location
639 within the measure, etc.  By moving these engraver from @code{Score} to
640 @code{Staff} context, we can have a score where each staff has its own
641 time signature.
642
643 @cindex polymetric scores
644 @cindex Time signatures, multiple
645
646 @lilypond[quote,verbatim]
647 \score {
648   <<
649     \new Staff \with {
650       \consists "Timing_translator"
651       \consists "Default_bar_line_engraver"
652     } {
653         \time 3/4
654         c4 c c c c c
655     }
656   \new Staff \with {
657     \consists "Timing_translator"
658     \consists "Default_bar_line_engraver"
659   } {
660       \time 2/4
661       c4 c c c c c
662   }
663 >>
664 \layout {
665   \context {
666     \Score
667     \remove "Timing_translator"
668     \remove "Default_bar_line_engraver"
669     }
670   }
671 }
672 @end lilypond
673
674 @knownissues
675
676 Usually the order in which the engravers are specified
677 does not matter, but in a few special cases the order
678 is important, for example where one engraver writes
679 a property and another reads it, or where one engraver
680 creates a grob and another must process it.  The order in
681 which the engravers are specified is the order in which
682 they are called to carry out their processing.
683
684 The following orderings are important: the
685 @code{Bar_engraver} must normally be first, and
686 the @code{New_fingering_engraver} must come before
687 the @code{Script_column_engraver}.  There may be others
688 with ordering dependencies.
689
690 @node Changing context default settings
691 @subsection Changing context default settings
692
693 The context settings which are to be used by default in
694 @code{Score}, @code{Staff} and @code{Voice} contexts may be specified
695 in a @code{\layout} block, as illustrated in the following example.
696 The @code{\layout} block should be placed within the @code{\score}
697 block to which it is to apply, but outside any music.
698
699 Note that the @code{\set} command itself and the context must be
700 omitted when the context default values are specified in this way:
701
702 @lilypond[quote,verbatim]
703 \score {
704   \relative c'' {
705     a4^"Really small, thicker stems, no time signature" a a a
706     a a a a
707   }
708   \layout {
709     \context {
710       \Staff
711       fontSize = #-4
712       \override Stem #'thickness = #4.0
713       \remove "Time_signature_engraver"
714     }
715   }
716 }
717 @end lilypond
718
719 In this example, the @code{\Staff} command specifies that the
720 subsequent specifications are to be applied to all staves within
721 this score block.
722
723 Modifications can be made to the @code{Score} context or all
724 @code{Voice} contexts in a similar way.
725
726 Context changes can be placed in a variable and applied to a
727 @code{\context} definition by prepending the modification with
728 @code{\with}:
729 @lilypond[quote,verbatim]
730 blubb = \with {
731   fontSize = #-4
732   \override Stem #'thickness = #4.0
733   \remove "Time_signature_engraver"
734 }
735
736 bla = \with {
737   fontSize = #3
738   \override Stem #'thickness = #-2.0
739 }
740
741 melody = \relative c'' {
742   a4 a a a |
743   a4 a a a |
744 }
745
746 \score {
747   <<
748     \new Staff <<
749       \melody
750       s1*0^"Small, thicker stems, no time signature"
751     >>
752     \new Staff \bla <<
753       \melody
754       s1*0^"Different"
755     >>
756   >>
757   \layout {
758     \context {
759       \Staff
760       \blubb
761     }
762   }
763 }
764 @end lilypond
765
766 @c TODO: add \with in here.
767
768
769
770 @node Defining new contexts
771 @subsection Defining new contexts
772
773 @cindex contexts, defining new
774 @cindex engravers, including in contexts
775
776 @funindex \alias
777 @funindex alias
778 @funindex \name
779 @funindex name
780 @funindex \type
781 @funindex type
782 @funindex \consists
783 @funindex consists
784 @funindex \accepts
785 @funindex accepts
786 @funindex \denies
787 @funindex denies
788
789 Specific contexts, like @code{Staff} and @code{Voice}, are made of
790 simple building blocks.  It is possible to create new types of
791 contexts with different combinations of engraver plug-ins.
792
793 The next example shows how to build a different type of
794 @code{Voice} context from scratch.  It will be similar to
795 @code{Voice}, but only prints centered slash note heads.  It can be used
796 to indicate improvisation in jazz pieces,
797
798 @lilypond[quote,ragged-right]
799 \layout { \context {
800   \name ImproVoice
801   \type "Engraver_group"
802   \consists "Note_heads_engraver"
803   \consists "Rhythmic_column_engraver"
804   \consists "Text_engraver"
805   \consists Pitch_squash_engraver
806   squashedPosition = #0
807   \override NoteHead #'style = #'slash
808   \override Stem #'transparent = ##t
809   \override Flag #'transparent = ##t
810   \alias Voice
811 }
812 \context { \Staff
813   \accepts "ImproVoice"
814 }}
815
816 \relative c'' {
817   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
818    c4 c^"undress" c_"while playing :)" c }
819   a1
820 }
821 @end lilypond
822
823
824 These settings are defined within a @code{\context} block inside a
825 @code{\layout} block,
826
827 @example
828 \layout @{
829   \context @{
830     @dots{}
831   @}
832 @}
833 @end example
834
835 In the following discussion, the example input shown should go in place
836 of the @dots{} in the previous fragment.
837
838 First it is necessary to define a name for the new context:
839
840 @example
841 \name ImproVoice
842 @end example
843
844 Since it is similar to the @code{Voice}, we want commands that work
845 on (existing) @code{Voice}s to remain working.  This is achieved by
846 giving the new context an alias @code{Voice},
847
848 @example
849 \alias Voice
850 @end example
851
852 The context will print notes and instructive texts, so we need to add
853 the engravers which provide this functionality,
854
855 @example
856 \consists Note_heads_engraver
857 \consists Text_engraver
858 @end example
859
860 but we only need this on the center line,
861
862 @example
863 \consists Pitch_squash_engraver
864 squashedPosition = #0
865 @end example
866
867 The @rinternals{Pitch_squash_engraver} modifies note heads (created
868 by @rinternals{Note_heads_engraver}) and sets their vertical
869 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
870 the center line.
871
872 The notes look like a slash, and have no stem,
873
874 @example
875 \override NoteHead #'style = #'slash
876 \override Stem #'transparent = ##t
877 \override Flag #'transparent = ##t
878 @end example
879
880 All these plug-ins have to cooperate, and this is achieved with a
881 special plug-in, which must be marked with the keyword @code{\type}.
882 This should always be @code{Engraver_group}.
883
884 @example
885 \type "Engraver_group"
886 @end example
887
888 Put together, we get
889
890 @example
891 \context @{
892   \name ImproVoice
893   \type "Engraver_group"
894   \consists "Note_heads_engraver"
895   \consists "Text_engraver"
896   \consists Pitch_squash_engraver
897   squashedPosition = #0
898   \override NoteHead #'style = #'slash
899   \override Stem #'transparent = ##t
900   \override Flag #'transparent = ##t
901   \alias Voice
902 @}
903 @end example
904
905 @funindex \accepts
906 Contexts form hierarchies.  We want to hang the @code{ImproVoice}
907 under @code{Staff}, just like normal @code{Voice}s.  Therefore, we
908 modify the @code{Staff} definition with the @code{\accepts}
909 command,
910
911 @example
912 \context @{
913   \Staff
914   \accepts ImproVoice
915 @}
916 @end example
917
918 @funindex \denies
919 The opposite of @code{\accepts} is @code{\denies},
920 which is sometimes needed when reusing existing context definitions.
921
922 Putting both into a @code{\layout} block, like
923
924 @example
925 \layout @{
926   \context @{
927     \name ImproVoice
928     @dots{}
929   @}
930   \context @{
931     \Staff
932     \accepts "ImproVoice"
933   @}
934 @}
935 @end example
936
937 Then the output at the start of this subsection can be entered as
938
939 @example
940 \relative c'' @{
941   a4 d8 bes8
942   \new ImproVoice @{
943     c4^"ad lib" c
944     c4 c^"undress"
945     c c_"while playing :)"
946   @}
947   a1
948 @}
949 @end example
950
951
952 @node Context layout order
953 @subsection Context layout order
954
955 @cindex contexts, layout order
956 @funindex \accepts
957 @funindex \denies
958
959 Contexts are normally positioned in a system from top to bottom
960 in the order in which they are encountered in the input file.  When
961 contexts are nested, the outer context will include inner nested
962 contexts as specified in the input file, provided the inner contexts
963 are included in the outer context's @qq{accepts} list.  Nested
964 contexts which are not included in the outer context's @qq{accepts}
965 list will be repositioned below the outer context rather than nested
966 within it.
967
968 The @qq{accepts} list of a context can be changed with the
969 @code{\accepts} and @code{\denies} commands.  @code{\accepts} adds a
970 context to the @qq{accepts} list and @code{\denies} removes a context
971 from the list.  For example, it would not normally be desirable for
972 chord names to be nested within a @code{Staff} context, so the
973 @code{ChordNames} context is not included by default in the @qq{accepts}
974 list of the @code{Staff} context, but if this were to be required it can
975 be done:
976
977 @lilypond[verbatim,quote]
978 \score {
979   \new Staff {
980     c' d' e' f'
981     \chords { d1:m7 b1:min7.5- }
982   }
983 }
984 @end lilypond
985
986 @lilypond[verbatim,quote]
987 \score {
988   \new Staff {
989     c' d' e' f'
990     \chords { d1:m7 b1:min7.5- }
991   }
992   \layout {
993     \context {
994       \Staff
995       \accepts "ChordNames"
996     }
997   }
998 }
999 @end lilypond
1000
1001 @code{\denies} is mainly used when a new context is being based on
1002 another, but the required nesting differs.  For example, the
1003 @code{VaticanaStaff} context is based on the @code{Staff} context, but
1004 with the @code{VaticanaVoice} context substituted for the @code{Voice}
1005 context in the @qq{accepts} list.
1006
1007 Note that a context will be silently created implicitly if a command
1008 is encountered when there is no suitable context available to
1009 contain it.  This can give rise to unexpected new staves or scores.
1010
1011 @seealso
1012 Application Usage:
1013 @rprogram{An extra staff appears}.
1014
1015 Installed Files:
1016 @file{ly/engraver-init.ly}.
1017
1018
1019 @node Explaining the Internals Reference
1020 @section Explaining the Internals Reference
1021
1022 @menu
1023 * Navigating the program reference::
1024 * Layout interfaces::
1025 * Determining the grob property::
1026 * Naming conventions::
1027 @end menu
1028
1029 @node Navigating the program reference
1030 @subsection Navigating the program reference
1031
1032 @c TODO remove this (it's in the LM)
1033 @c Replace with more factual directions
1034
1035 Suppose we want to move the fingering indication in the fragment
1036 below:
1037
1038 @lilypond[quote,relative=2,verbatim]
1039 c-2
1040 \stemUp
1041 f
1042 @end lilypond
1043
1044 If you visit the documentation on fingering instructions (in
1045 @ref{Fingering instructions}), you will notice:
1046
1047 @quotation
1048 @strong{See also}
1049
1050 Internals Reference: @rinternals{Fingering}.
1051
1052 @end quotation
1053
1054
1055 @c  outdated info; probably will delete.
1056 @ignore
1057 This fragment points to two parts of the program reference: a page
1058 on @code{FingeringEvent} and one on @code{Fingering}.
1059
1060 The page on @code{FingeringEvent} describes the properties of the music
1061 expression for the input @w{@code{-2}}.  The page contains many links
1062 forward.  For example, it says
1063
1064 @quotation
1065 Accepted by: @rinternals{Fingering_engraver},
1066 @end quotation
1067
1068 @noindent
1069 That link brings us to the documentation for the Engraver, the
1070 plug-in, which says
1071
1072 @quotation
1073 This engraver creates the following layout objects: @rinternals{Fingering}.
1074 @end quotation
1075
1076 In other words, once the @code{FingeringEvent}s are interpreted, the
1077 @code{Fingering_engraver} plug-in will process them.
1078 @end ignore
1079
1080 @ignore
1081 @c  I can't figure out what this is supposed to mean.  -gp
1082
1083 The @code{Fingering_engraver} is also listed to create
1084 @rinternals{Fingering} objects,
1085
1086 @c  old info?  it doesn't make any sense to me with our current docs.
1087 This is also the
1088 second bit of information listed under @b{See also} in the Notation
1089 manual.
1090 @end ignore
1091
1092 @ifnothtml
1093 The programmer's reference is available as an HTML document.  It is
1094 highly recommended that you read it in HTML form, either online or
1095 by downloading the HTML documentation.  This section will be much more
1096 difficult to understand if you are using the
1097 PDF manual.
1098 @end ifnothtml
1099
1100 Follow the link to @rinternals{Fingering}.  At the top of the
1101 page, you will see
1102
1103 @quotation
1104 Fingering objects are created by: @rinternals{Fingering_engraver} and
1105 @rinternals{New_fingering_engraver}.
1106 @end quotation
1107
1108 By following related links inside the program reference, we can follow the
1109 flow of information within the program:
1110
1111 @itemize
1112
1113 @item @rinternals{Fingering}:
1114 @rinternals{Fingering} objects are created by:
1115 @rinternals{Fingering_engraver}
1116
1117 @item @rinternals{Fingering_engraver}:
1118 Music types accepted: @rinternals{fingering-event}
1119
1120 @item @rinternals{fingering-event}:
1121 Music event type @code{fingering-event} is in Music expressions named
1122 @rinternals{FingeringEvent}
1123 @end itemize
1124
1125 This path goes against the flow of information in the program: it
1126 starts from the output, and ends at the input event.  You could
1127 also start at an input event, and read with the flow of
1128 information, eventually ending up at the output object(s).
1129
1130 The program reference can also be browsed like a normal document.  It
1131 contains chapters on
1132 @ifhtml
1133 @rinternals{Music definitions},
1134 @end ifhtml
1135 @ifnothtml
1136 @code{Music definitions}
1137 @end ifnothtml
1138 on @rinternals{Translation}, and the @rinternals{Backend}.  Every
1139 chapter lists all the definitions used and all properties that may be
1140 tuned.
1141
1142
1143 @node Layout interfaces
1144 @subsection Layout interfaces
1145
1146 @cindex interface, layout
1147 @cindex layout interface
1148 @cindex grob
1149
1150 The HTML page that we found in the previous section describes the
1151 layout object called @rinternals{Fingering}.  Such an object is a
1152 symbol within the score.  It has properties that store numbers (like
1153 thicknesses and directions), but also pointers to related objects.  A
1154 layout object is also called a @emph{Grob}, which is short for Graphical
1155 Object.  For more details about Grobs, see @rinternals{grob-interface}.
1156
1157 The page for @code{Fingering} lists the definitions for the
1158 @code{Fingering} object.  For example, the page says
1159
1160 @quotation
1161 @code{padding} (dimension, in staff space):
1162
1163 @code{0.5}
1164 @end quotation
1165
1166 @noindent
1167 which means that the number will be kept at a distance of at least 0.5
1168 of the note head.
1169
1170
1171 Each layout object may have several functions as a notational or
1172 typographical element.  For example, the Fingering object
1173 has the following aspects
1174
1175 @itemize
1176 @item
1177 Its size is independent of the horizontal spacing, unlike slurs or beams.
1178
1179 @item
1180 It is a piece of text.  Granted, it is usually a very short text.
1181
1182 @item
1183 That piece of text is typeset with a font, unlike slurs or beams.
1184
1185 @item
1186 Horizontally, the center of the symbol should be aligned to the
1187 center of the note head.
1188
1189 @item
1190 Vertically, the symbol is placed next to the note and the staff.
1191
1192 @item
1193 The vertical position is also coordinated with other superscript
1194 and subscript symbols.
1195 @end itemize
1196
1197 Each of these aspects is captured in so-called @emph{interface}s,
1198 which are listed on the @rinternals{Fingering} page at the bottom
1199
1200 @quotation
1201 This object supports the following interfaces:
1202 @rinternals{item-interface},
1203 @rinternals{self-alignment-interface},
1204 @rinternals{side-position-interface}, @rinternals{text-interface},
1205 @rinternals{text-script-interface}, @rinternals{font-interface},
1206 @rinternals{finger-interface}, and @rinternals{grob-interface}.
1207 @end quotation
1208
1209 Clicking any of the links will take you to the page of the respective
1210 object interface.  Each interface has a number of properties.  Some of
1211 them are not user-serviceable (@q{Internal properties}), but others
1212 can be modified.
1213
1214 We have been talking of @emph{the} @code{Fingering} object, but actually it
1215 does not amount to much.  The initialization file (see
1216 @rlearning{Other sources of information})
1217 @file{scm/define-grobs.scm} shows the soul of the @q{object},
1218
1219 @example
1220 (Fingering
1221   . ((padding . 0.5)
1222      (avoid-slur . around)
1223      (slur-padding . 0.2)
1224      (staff-padding . 0.5)
1225      (self-alignment-X . 0)
1226      (self-alignment-Y . 0)
1227      (script-priority . 100)
1228      (stencil . ,ly:text-interface::print)
1229      (direction . ,ly:script-interface::calc-direction)
1230      (font-encoding . fetaText)
1231      (font-size . -5)           ; don't overlap when next to heads.
1232      (meta . ((class . Item)
1233      (interfaces . (finger-interface
1234                     font-interface
1235                     text-script-interface
1236                     text-interface
1237                     side-position-interface
1238                     self-alignment-interface
1239                     item-interface))))))
1240 @end example
1241
1242 @noindent
1243 As you can see, the @code{Fingering} object is nothing more than a
1244 bunch of variable settings, and the webpage in the Internals Reference
1245 is directly generated from this definition.
1246
1247
1248 @node Determining the grob property
1249 @subsection Determining the grob property
1250
1251 @c TODO remove this (it's in the LM)
1252 @c Replace with more factual directions
1253
1254 Recall that we wanted to change the position of the @b{2} in
1255
1256 @lilypond[quote,relative=2,verbatim]
1257 c-2
1258 \stemUp
1259 f
1260 @end lilypond
1261
1262 Since the @b{2} is vertically positioned next to its note, we have to
1263 meddle with the interface associated with this positioning.  This is
1264 done using @code{side-position-interface}.  The page for this interface
1265 says
1266
1267 @quotation
1268 @code{side-position-interface}
1269
1270 Position a victim object (this one) next to other objects (the
1271 support).  The property @code{direction} signifies where to put the
1272 victim object relative to the support (left or right, up or down?)
1273 @end quotation
1274
1275 @cindex padding
1276 @noindent
1277 Below this description, the variable @code{padding} is described as
1278
1279 @quotation
1280 @table @code
1281 @item padding
1282 (dimension, in staff space)
1283
1284 Add this much extra space between objects that are next to each other.
1285 @end table
1286 @end quotation
1287
1288 By increasing the value of @code{padding}, we can move the
1289 fingering away from the note head.  The following command inserts
1290 3 staff spaces of white
1291 between the note and the fingering:
1292 @example
1293 \once \override Voice.Fingering #'padding = #3
1294 @end example
1295
1296 Inserting this command before the Fingering object is created,
1297 i.e., before @code{c2}, yields the following result:
1298
1299 @lilypond[quote,relative=2,verbatim]
1300 \once \override Voice.Fingering #'padding = #3
1301 c-2
1302 \stemUp
1303 f
1304 @end lilypond
1305
1306
1307 In this case, the context for this tweak is @code{Voice}.  This
1308 fact can also be deduced from the program reference, for the page for
1309 the @rinternals{Fingering_engraver} plug-in says
1310
1311 @quotation
1312 Fingering_engraver is part of contexts: @dots{} @rinternals{Voice}
1313 @end quotation
1314
1315
1316 @node Naming conventions
1317 @subsection Naming conventions
1318
1319 Another thing that is needed, is an overview of the various naming
1320 conventions:
1321
1322 @itemize
1323 @item scheme functions: lowercase-with-hyphens (incl. one-word
1324 names)
1325 @item scheme functions: ly:plus-scheme-style
1326 @item music events, music classes and music properties:
1327 as-scheme-functions
1328 @item Grob interfaces: scheme-style
1329 @item backend properties: scheme-style (but X and Y!)
1330 @item contexts (and MusicExpressions and grobs): Capitalized or
1331 CamelCase
1332 @item context properties: lowercaseFollowedByCamelCase
1333 @item engravers:
1334 Capitalized_followed_by_lowercase_and_with_underscores
1335 @end itemize
1336
1337 Questions to be answered:
1338 @itemize
1339 @item Which of these are conventions and which are rules?
1340 @item Which are rules of the underlying language, and which are
1341 LP-specific?
1342 @end itemize
1343
1344 @node Modifying properties
1345 @section Modifying properties
1346
1347 @c TODO change the menu and subsection node names to use
1348 @c backslash once the new macro to handle the refs
1349 @c is available.  Need to find and change all refs at
1350 @c the same time. -td
1351
1352 @menu
1353 * Overview of modifying properties::
1354 * The set command::
1355 * The override command::
1356 * The tweak command::
1357 * set versus override::
1358 * Modifying alists::
1359 @end menu
1360
1361
1362 @node Overview of modifying properties
1363 @subsection Overview of modifying properties
1364
1365 Each context is responsible for creating certain types of graphical
1366 objects.  The settings used for printing these objects are also stored by
1367 context.  By changing these settings, the appearance of objects can be
1368 altered.
1369
1370 There are two different kinds of properties stored in contexts:
1371 context properties and grob properties.  Context properties are
1372 properties that apply to the context as a whole and control
1373 how the context itself is displayed.  In contrast, grob properties
1374 apply to specific grob types that will be displayed in the context.
1375
1376 The @code{\set} and @code{\unset} commands are used to change values
1377 for context properties.  The @code{\override} and @code{\revert}
1378 commands are used to change values for grob properties.
1379
1380 @ignore
1381 The syntax for this is
1382
1383 @example
1384 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1385 @end example
1386
1387 Here @var{name} is the name of a graphical object, like
1388 @code{Stem} or @code{NoteHead}, and @var{property} is an internal
1389 variable of the formatting system (@q{grob property} or @q{layout
1390 property}).  The latter is a symbol, so it must be quoted.  The
1391 subsection @ref{Modifying properties}, explains what to fill in
1392 for @var{name}, @var{property}, and @var{value}.  Here we only
1393 discuss the functionality of this command.
1394
1395 The command
1396
1397 @verbatim
1398 \override Staff.Stem #'thickness = #4.0
1399 @end verbatim
1400
1401 @noindent
1402 makes stems thicker (the default is 1.3, with staff line thickness as a
1403 unit).  Since the command specifies @code{Staff} as context, it only
1404 applies to the current staff.  Other staves will keep their normal
1405 appearance.  Here we see the command in action:
1406
1407 @lilypond[quote,verbatim,relative=2]
1408 c4
1409 \override Staff.Stem #'thickness = #4.0
1410 c4
1411 c4
1412 c4
1413 @end lilypond
1414
1415 The @code{\override} command changes the definition of the @code{Stem}
1416 within the current @code{Staff}.  After the command is interpreted
1417 all stems are thickened.
1418
1419 Analogous to @code{\set}, the @var{context} argument may be left out,
1420 causing the default context @code{Voice} to be used.  Adding
1421 @code{\once} applies the change during one timestep only.
1422
1423 @lilypond[quote,verbatim,relative=2]
1424 c4
1425 \once \override Stem #'thickness = #4.0
1426 c4
1427 c4
1428 @end lilypond
1429
1430 The @code{\override} must be done before the object is
1431 started.  Therefore, when altering @emph{Spanner} objects such as slurs
1432 or beams, the @code{\override} command must be executed at the moment
1433 when the object is created.  In this example,
1434
1435 @lilypond[quote,verbatim,relative=2]
1436 \override Slur #'thickness = #3.0
1437 c8[( c
1438 \override Beam #'beam-thickness = #0.6
1439 c8 c])
1440 @end lilypond
1441
1442 @noindent
1443 the slur is fatter but the beam is not.  This is because the command for
1444 @code{Beam} comes after the Beam is started, so it has no effect.
1445
1446 Analogous to @code{\unset}, the @code{\revert} command for a context
1447 undoes an @code{\override} command; like with @code{\unset}, it only
1448 affects settings that were made in the same context.  In other words, the
1449 @code{\revert} in the next example does not do anything.
1450
1451 @example
1452 \override Voice.Stem #'thickness = #4.0
1453 \revert Staff.Stem #'thickness
1454 @end example
1455
1456 Some tweakable options are called @q{subproperties} and reside inside
1457 properties.  To tweak those, use commands of the form
1458
1459 @c leave this as a long long
1460 @example
1461 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
1462 @end example
1463
1464 @noindent
1465 such as
1466
1467 @example
1468 \override Stem #'(details beamed-lengths) = #'(4 4 3)
1469 @end example
1470
1471 @end ignore
1472
1473 @seealso
1474 Internals Reference:
1475 @rinternals{Backend},
1476 @rinternals{All layout objects},
1477 @rinternals{OverrideProperty},
1478 @rinternals{RevertProperty},
1479 @rinternals{PropertySet}.
1480
1481 @knownissues
1482 The back-end is not very strict in type-checking object properties.
1483 Cyclic references in Scheme values for properties can cause hangs
1484 or crashes, or both.
1485
1486
1487 @node The set command
1488 @subsection The @code{@bs{}set} command
1489
1490 @cindex properties
1491 @funindex \set
1492 @cindex changing properties
1493
1494 Each context has a set of @emph{properties}, variables contained
1495 in that context.  Context properties are changed with the @code{\set}
1496 command, which has the following syntax:
1497
1498 @example
1499 \set @var{context}.@var{property} = #@var{value}
1500 @end example
1501
1502 @var{value} is a Scheme object, which is why it must be preceded by
1503 the @code{#}@tie{}character.
1504
1505 Contexts properties are usually named in
1506 @code{studlyCaps}.  They mostly control the translation from
1507 music to notation, e.g. @code{localKeySignature} (for determining
1508 whether to print accidentals), or @code{measurePosition} (for
1509 determining when to print a bar line).  Context properties can
1510 change value over time while interpreting a piece of music;
1511 @code{measurePosition} is an obvious example of
1512 this.  Context properties are modified with @code{\set}.
1513
1514 For example, multimeasure rests will be combined into a single bar
1515 if the context property @code{skipBars} is set to @code{#t}:
1516
1517 @lilypond[quote,verbatim,relative=2]
1518 R1*2
1519 \set Score.skipBars = ##t
1520 R1*2
1521 @end lilypond
1522
1523 If the @var{context} argument is left out, then the property will be
1524 set in the current bottom context (typically @code{ChordNames},
1525 @code{Voice}, @code{TabVoice}, or @code{Lyrics}).
1526
1527 @lilypond[quote,verbatim,relative=2]
1528 \set Score.autoBeaming = ##f
1529 <<
1530   {
1531     e8 e e e
1532     \set autoBeaming = ##t
1533     e8 e e e
1534   } \\ {
1535     c8 c c c c8 c c c
1536   }
1537 >>
1538 @end lilypond
1539
1540 The change is applied @q{on-the-fly}, during the music, so that the
1541 setting only affects the second group of eighth notes.
1542
1543 Note that the bottom-most context does not always contain the property
1544 that you wish to change -- for example, attempting to set the
1545 @code{skipBars} property of the default bottom context, in this case
1546 @code{Voice}, will have no effect, because skipBars is a property of
1547 the @code{Score} context.
1548
1549 @lilypond[quote,verbatim,relative=2]
1550 R1*2
1551 \set skipBars = ##t
1552 R1*2
1553 @end lilypond
1554
1555 Contexts are hierarchical, so if an enclosing context was specified, for
1556 example @code{Staff}, then the change would also apply to all
1557 @code{Voice}s in the current staff.
1558
1559 @funindex \unset
1560
1561 The @code{\unset} command:
1562
1563 @example
1564 \unset @var{context}.@var{property}
1565 @end example
1566
1567 @noindent
1568 is used to remove the definition of @var{property} from
1569 @var{context}.  This command removes
1570 the definition only if it is set in @var{context}.
1571 Properties that have been set in enclosing contexts will
1572 not be altered by an unset in an enclosed context:
1573
1574 @lilypond[quote,verbatim,relative=2]
1575 \set Score.autoBeaming = ##t
1576 <<
1577   {
1578     \unset autoBeaming
1579     e8 e e e
1580     \unset Score.autoBeaming
1581     e8 e e e
1582   } \\ {
1583     c8 c c c c8 c c c
1584   }
1585 >>
1586 @end lilypond
1587
1588 Like @code{\set}, the @var{context} argument does not have to be
1589 specified for a bottom context, so the two statements
1590
1591 @example
1592 \set Voice.autoBeaming = ##t
1593 \set autoBeaming = ##t
1594 @end example
1595
1596 @noindent
1597 are equivalent if the current bottom context is @code{Voice}.
1598
1599
1600 @cindex \once
1601 Preceding a @code{\set} command by @code{\once} makes the
1602 setting apply to only a single time-step:
1603
1604 @lilypond[quote,verbatim,relative=2]
1605 c4
1606 \once \set fontSize = #4.7
1607 c4
1608 c4
1609 @end lilypond
1610
1611 A full description of all available context properties is in the
1612 internals reference, see
1613 @ifhtml
1614 @rinternals{Tunable context properties}.
1615 @end ifhtml
1616 @ifnothtml
1617 Translation @expansion{} Tunable context properties.
1618 @end ifnothtml
1619
1620 @seealso
1621 Internals Reference:
1622 @rinternals{Tunable context properties}.
1623
1624 @cindex grob properties
1625 @cindex properties, grob
1626 @funindex \override
1627
1628
1629 @node The override command
1630 @subsection The @code{\override} command
1631
1632 There is a special type of context property: the grob
1633 description.  Grob descriptions are named in @code{StudlyCaps}
1634 (starting with capital letters).  They contain the
1635 @q{default settings} for a particular kind of grob as an
1636 association list.  See @file{scm/define-grobs.scm}
1637 to see the settings for each grob description.  Grob descriptions
1638 are modified with @code{\override}.
1639
1640 @code{\override} is actually a shorthand;
1641
1642 @example
1643 \override @var{context}.@var{GrobName} #'@var{property} = #@var{value}
1644 @end example
1645
1646 @noindent
1647 is more or less equivalent to
1648
1649 @c  leave this long line -gp
1650 @example
1651 \set @var{context}.@var{GrobName}  =
1652   #(cons (cons '@var{property} @var{value})
1653          <previous value of @var{context}.@var{GrobName}>)
1654 @end example
1655
1656 The value of @code{context}.@code{GrobName} (the alist) is used to initialize
1657 the properties of individual grobs.  Grobs have
1658 properties, named in Scheme style, with
1659 @code{dashed-words}.  The values of grob properties change
1660 during the formatting process: formatting basically amounts
1661 to computing properties using callback functions.
1662
1663 For example, we can increase the thickness of a note stem by
1664 overriding the @code{thickness} property of the @code{Stem}
1665 object:
1666
1667 @lilypond[quote,verbatim,relative=2]
1668 c4 c
1669 \override Voice.Stem #'thickness = #3.0
1670 c4 c
1671 @end lilypond
1672
1673 If no context is specified in an @code{\override}, the bottom
1674 context is used:
1675
1676 @lilypond[quote,verbatim,relative=2]
1677 { \override Staff.Stem #'thickness = #3.0
1678   <<
1679     {
1680       e4 e
1681       \override Stem #'thickness = #0.5
1682       e4 e
1683     } \\ {
1684       c4 c c c
1685     }
1686   >>
1687 }
1688 @end lilypond
1689
1690 @funindex \revert
1691 @cindex reverting overrides
1692 @cindex overrides, reverting
1693
1694 The effects of @code{\override} can be undone by @code{\revert}:
1695
1696 @lilypond[quote,verbatim,relative=2]
1697 c4
1698 \override Voice.Stem #'thickness = #3.0
1699 c4 c
1700 \revert Voice.Stem #'thickness
1701 c4
1702 @end lilypond
1703
1704 The effects of @code{\override} and @code{\revert} apply to all
1705 grobs in the affected context from the current time forward:
1706
1707 @lilypond[quote,verbatim,relative=2]
1708 {
1709   <<
1710     {
1711       e4
1712       \override Staff.Stem #'thickness = #3.0
1713       e4 e e
1714     } \\ {
1715       c4 c c
1716       \revert Staff.Stem #'thickness
1717       c4
1718     }
1719   >>
1720 }
1721 @end lilypond
1722
1723 @funindex \once
1724 @cindex overriding for only one moment
1725
1726 @code{\once} can be used with @code{\override}
1727 to affect only the current time step:
1728
1729 @lilypond[quote,verbatim,relative=2]
1730 {
1731   <<
1732     {
1733       \override Stem #'thickness = #3.0
1734       e4 e e e
1735     } \\ {
1736       c4
1737       \once \override Stem #'thickness = #3.0
1738       c4 c c
1739     }
1740   >>
1741 }
1742 @end lilypond
1743
1744
1745 @ignore
1746 Commands which change output generally look like
1747
1748 @example
1749 \override Voice.Stem #'thickness = #3.0
1750 @end example
1751
1752 @noindent
1753 To construct this tweak we must determine these bits of information:
1754
1755 @itemize
1756 @item the context: here @code{Voice}.
1757 @item the layout object: here @code{Stem}.
1758 @item the layout property: here @code{thickness}.
1759 @item a sensible value: here @code{3.0}.
1760 @end itemize
1761
1762 Some tweakable options are called @q{subproperties} and reside inside
1763 properties.  To tweak those, use commands in the form
1764
1765 @example
1766 \override Stem #'(details beamed-lengths) = #'(4 4 3)
1767 @end example
1768
1769 @cindex internal documentation
1770 @cindex finding graphical objects
1771 @cindex graphical object descriptions
1772 @cindex tweaking
1773 @funindex \override
1774 @cindex internal documentation
1775
1776 For many properties, regardless of the data type of the property, setting the
1777 property to false (@code{#f}) will result in turning it off, causing
1778 LilyPond to ignore that property entirely.  This is particularly useful for
1779 turning off grob properties which may otherwise be causing problems.
1780
1781 We demonstrate how to glean this information from the notation manual
1782 and the program reference.
1783 @end ignore
1784
1785 @seealso
1786 Internals Reference:
1787 @rinternals{Backend}
1788
1789
1790 @node The tweak command
1791 @subsection The @code{\tweak} command
1792
1793 @funindex \tweak
1794 @cindex tweaking
1795
1796 Changing grob properties
1797 with @code{\override} causes the changes to apply to all of the
1798 given grobs in the context at the moment the change applies.
1799 Sometimes, however, it is desirable to have changes apply to just
1800 one grob, rather than to all grobs in the affected context.  This is
1801 accomplished with the @code{\tweak} command, which has the following
1802 syntax:
1803
1804 @example
1805 \tweak #'@code{grob-property} #@code{value}
1806 @end example
1807
1808 The @code{\tweak} command applies to the object that immediately
1809 follows @code{value} in the music stream.
1810
1811 @ignore
1812 In some cases, it is possible to take a short-cut for tuning
1813 graphical objects.  For objects that are created directly from
1814 an item in the input file, you can use the @code{\tweak} command.
1815 For example:
1816
1817 @lilypond[relative=2,verbatim,quote]
1818 < c
1819   \tweak #'color #red
1820   d
1821   g
1822   \tweak #'duration-log #1
1823   a
1824 > 4
1825 -\tweak #'padding #8
1826 -^
1827 @end lilypond
1828
1829
1830
1831 But the main use of the @code{\tweak} command is to modify just
1832 one of a number of notation elements which start at the same musical
1833 moment, like the notes of a chord, or tuplet brackets which start
1834 at the same time.
1835
1836 The @code{\tweak} command sets a property in the following object
1837 directly, without requiring the grob name or context to be
1838 specified.  For this to work, it is necessary for the @code{\tweak}
1839 command to remain immediately adjacent to the object to which it is
1840 to apply after the input file has been converted to a music stream.
1841 This is often not the case, as many additional elements are inserted
1842 into the music stream implicitly.  For example, when a note which is
1843 not part of a chord is processed, LilyPond implicitly inserts a
1844 @code{ChordEvent} event before the note, so separating the tweak
1845 from the note.  However, if chord symbols are placed round the
1846 tweak and the note, the @code{\tweak} command comes after the
1847 @code{ChordEvent} in the music stream, so remaining adjacent to the
1848 note, and able to modify it.
1849
1850 So, this works:
1851
1852 @lilypond[relative=2,verbatim,quote]
1853 <\tweak #'color #red c>4
1854 @end lilypond
1855
1856 @noindent
1857 but this does not:
1858
1859 @lilypond[relative=2,verbatim,quote]
1860 \tweak #'color #red c4
1861 @end lilypond
1862
1863 @end ignore
1864
1865 For an introduction to the syntax and uses of the tweak command
1866 see @rlearning{Tweaking methods}.
1867
1868 When several similar items are placed at the same musical moment,
1869 the @code{\override} command cannot be used to modify just one of
1870 them -- this is where the @code{\tweak} command must be used.
1871 Items which may appear more than once at the same musical moment
1872 include the following:
1873
1874 @c TODO expand to include any further uses of \tweak
1875 @itemize
1876 @item note heads of notes inside a chord
1877 @item articulation signs on a single note
1878 @item ties between notes in a chord
1879 @item tuplet brackets starting at the same time
1880 @end itemize
1881
1882 @c TODO add examples of these
1883
1884 @cindex chord, modifying one note in
1885
1886 In this example, the color of one note head and the type of another
1887 note head are modified within a single chord:
1888
1889 @lilypond[relative=2,verbatim,quote]
1890 < c
1891   \tweak #'color #red
1892   d
1893   g
1894   \tweak #'duration-log #1
1895   a
1896 > 4
1897 @end lilypond
1898
1899 @code{\tweak} can be used to modify slurs:
1900
1901 @lilypond[verbatim,quote,relative=1]
1902 c-\tweak #'thickness #5 ( d e f)
1903 @end lilypond
1904
1905
1906 For the @code{\tweak} command to work, it must
1907 remain immediately adjacent to the object to which it is
1908 to apply after the input file has been converted to a music stream.
1909 At times, LilyPond may insert additional items into the music stream
1910 during the parsing process.  For example, when a note that is not
1911 explicitly part of a chord will be placed in a chord by LilyPond,
1912 so notes to be modified with @code{\tweak} must be placed inside
1913 a chord construct:
1914
1915 @lilypond[relative=2,verbatim,quote]
1916 \tweak #'color #red c4
1917 <\tweak #'color #red c>4
1918 @end lilypond
1919
1920 The @code{\tweak} command cannot be used to modify any item
1921 that does not appear explicitly in the input file.  In particular
1922 it cannot be used to modify stems,
1923 beams or accidentals directly, since these are generated later by
1924 note heads, rather than by music elements in the input stream.
1925 Nor can @code{\tweak} be used to modify clefs or time
1926 signatures, since these become separated from any preceding
1927 @code{\tweak} command in the input stream by the automatic
1928 insertion of extra elements required to specify the context.
1929
1930 Several @code{\tweak} commands may be placed before a
1931 notational element -- all affect it:
1932
1933 @lilypond[verbatim,quote,relative=1]
1934 c
1935 -\tweak #'style #'dashed-line
1936 -\tweak #'dash-fraction #0.2
1937 -\tweak #'thickness #3
1938 -\tweak #'color #red
1939  \glissando
1940 f'
1941 @end lilypond
1942
1943 The music stream which is generated from a section of an input file,
1944 including any automatically inserted elements, may be examined,
1945 see @rextend{Displaying music expressions}.  This may be helpful in
1946 determining what may be modified by a @code{\tweak} command, or
1947 in determining how to adjust the input to make a @code{\tweak}
1948 apply.
1949
1950 @seealso
1951 Learning Manual:
1952 @rlearning{Tweaking methods}.
1953
1954 Extending LilyPond:
1955 @rextend{Displaying music expressions}.
1956
1957 @knownissues
1958 @cindex tweaks in a variable
1959
1960 The @code{\tweak} command cannot be used inside a variable.
1961
1962 @cindex tweaks in lyrics
1963 The @code{\tweak} commands cannot be used in @code{\lyricmode}.
1964
1965 @cindex tweaking control points
1966 @cindex control points, tweaking
1967
1968 The @code{\tweak} command will apply to only the first of several
1969 generated ties in a chord.
1970
1971
1972 @node set versus override
1973 @subsection @code{\set} vs. @code{\override}
1974
1975 @c TODO -- This section is probably unnecessary now.
1976
1977 @ignore
1978 We have seen two methods of changing properties: @code{\set} and
1979 @code{\override}.  There are actually two different kinds of
1980 properties.
1981
1982 @code{fontSize} is a special property: it is equivalent to
1983 entering @code{\override ... #'font-size} for all pertinent
1984 objects.  Since this is a common change, the special
1985 property (modified with @code{\set}) was created.
1986
1987 @end ignore
1988
1989
1990 @node Modifying alists
1991 @subsection Modifying alists
1992
1993 Some user-configurable properties are internally represented as
1994 @emph{alists} (association lists), which store pairs of
1995 @emph{keys} and @emph{values}.  The structure of an alist is:
1996
1997 @example
1998 '((@var{key1} . @var{value1})
1999   (@var{key2} . @var{value2})
2000   (@var{key3} . @var{value3})
2001   @dots{})
2002 @end example
2003
2004 If an alist is a grob property or @code{\paper} variable, its keys
2005 can be modified individually without affecting other keys.
2006
2007 For example, to reduce the space between adjacent staves in a
2008 staff-group, use the @code{staff-staff-spacing} property of the
2009 @code{StaffGrouper} grob.  The property is an alist with four
2010 keys: @code{basic-distance}, @code{minimum-distance},
2011 @code{padding}, and @code{stretchability}.  The standard settings
2012 for this property are listed in the @qq{Backend} section of the
2013 Internals Reference (see @rinternals{StaffGrouper}):
2014
2015 @example
2016 '((basic-distance . 9)
2017   (minimum-distance . 7)
2018   (padding . 1)
2019   (stretchability . 5))
2020 @end example
2021
2022 One way to bring the staves closer together is by reducing the
2023 value of the @code{basic-distance} key (@code{9}) to match the
2024 value of @code{minimum-distance} (@code{7}).  To modify a single
2025 key individually, use a @emph{nested declaration}:
2026
2027 @lilypond[quote,verbatim]
2028 % default space between staves
2029 \new PianoStaff <<
2030   \new Staff { \clef treble c''1 }
2031   \new Staff { \clef bass   c1   }
2032 >>
2033
2034 % reduced space between staves
2035 \new PianoStaff \with {
2036   % this is the nested declaration
2037   \override StaffGrouper #'staff-staff-spacing #'basic-distance = #7
2038 } <<
2039   \new Staff { \clef treble c''1 }
2040   \new Staff { \clef bass   c1   }
2041 >>
2042 @end lilypond
2043
2044 Using a nested declaration will update the specified key (such as
2045 @code{basic-distance} in the above example) without altering any
2046 other keys already set for the same property.
2047
2048 Now suppose we want the staves to be as close as possible without
2049 overlapping.  The simplest way to do this is to set all four alist
2050 keys to zero.  However, it is not necessary to enter four nested
2051 declarations, one for each key.  Instead, the property can be
2052 completely re-defined with one declaration, as an alist:
2053
2054 @lilypond[quote,verbatim]
2055 \new PianoStaff \with {
2056   \override StaffGrouper #'staff-staff-spacing =
2057     #'((basic-distance . 0)
2058        (minimum-distance . 0)
2059        (padding . 0)
2060        (stretchability . 0))
2061 } <<
2062   \new Staff { \clef treble c''1 }
2063   \new Staff { \clef bass   c1   }
2064 >>
2065 @end lilypond
2066
2067 Note that any keys not explicitly listed in the alist definition
2068 will be reset to their @emph{default-when-unset} values.  In the
2069 case of @code{staff-staff-spacing}, any unset key-values would be
2070 reset to zero (except @code{stretchability}, which takes the value
2071 of @code{basic-distance} when unset).  Thus the following two
2072 declarations are equivalent:
2073
2074 @example
2075 \override StaffGrouper #'staff-staff-spacing =
2076   #'((basic-distance . 7))
2077
2078 \override StaffGrouper #'staff-staff-spacing =
2079   #'((basic-distance . 7)
2080      (minimum-distance . 0)
2081      (padding . 0)
2082      (stretchability . 7))
2083 @end example
2084
2085 One (possibly unintended) consequence of this is the removal of
2086 any standard settings that are set in an initialization file and
2087 loaded each time an input file is compiled.  In the above example,
2088 the standard settings for @code{padding} and
2089 @code{minimum-distance} (defined in @file{scm/define-grobs.scm})
2090 are reset to their default-when-unset values (zero for both keys).
2091 Defining a property or variable as an alist (of any size) will
2092 always reset all unset key-values to their default-when-unset
2093 values.  Unless this is the intended result, it is safer to update
2094 key-values individually with a nested declaration.
2095
2096 @warning{Nested declarations will not work for context property
2097 alists (such as @code{beamExceptions}, @code{keySignature},
2098 @code{timeSignatureSettings}, etc.).  These properties can only be
2099 modified by completely re-defining them as alists.}
2100
2101
2102 @node Useful concepts and properties
2103 @section Useful concepts and properties
2104
2105
2106 @menu
2107 * Input modes::
2108 * Direction and placement::
2109 * Distances and measurements::
2110 * Staff symbol properties::
2111 * Spanners::
2112 * Visibility of objects::
2113 * Line styles::
2114 * Rotating objects::
2115 @end menu
2116
2117 @node Input modes
2118 @subsection Input modes
2119
2120 The way in which the notation contained within an input file is
2121 interpreted is determined by the current input mode.
2122
2123 @strong{Chord mode}
2124
2125 This is activated with the @code{\chordmode} command, and causes
2126 input to be interpreted with the syntax of chord notation, see
2127 @ref{Chord notation}.  Chords are rendered as notes on a staff.
2128
2129 Chord mode is also activated with the @code{\chords} command.
2130 This also creates a new @code{ChordNames} context and
2131 causes the following input to be interpreted with the syntax of
2132 chord notation and rendered as chord names in the @code{ChordNames}
2133 context, see @ref{Printing chord names}.
2134
2135 @strong{Drum mode}
2136
2137 This is activated with the @code{\drummode} command, and causes
2138 input to be interpreted with the syntax of drum notation, see
2139 @ref{Basic percussion notation}.
2140
2141 Drum mode is also activated with the @code{\drums} command.
2142 This also creates a new @code{DrumStaff} context and causes the
2143 following input to be interpreted with the syntax of drum notation
2144 and rendered as drum symbols on a drum staff, see @ref{Basic
2145 percussion notation}.
2146
2147 @strong{Figure mode}
2148
2149 This is activated with the @code{\figuremode} command, and causes
2150 input to be interpreted with the syntax of figured bass, see
2151 @ref{Entering figured bass}.
2152
2153 Figure mode is also activated with the @code{\figures} command.
2154 This also creates a new @code{FiguredBass} context and causes the
2155 following input to be interpreted with the figured bass syntax
2156 and rendered as figured bass symbols in the @code{FiguredBass}
2157 context, see @ref{Introduction to figured bass}.
2158
2159 @strong{Fret and tab modes}
2160
2161 There are no special input modes for entering fret and tab symbols.
2162
2163 To create tab diagrams, enter notes or chords in note mode and
2164 render them in a @code{TabStaff} context, see
2165 @ref{Default tablatures}.
2166
2167 To create fret diagrams above a staff, you have two choices.
2168 You can either use the @code{FretBoards} context (see
2169 @ref{Automatic fret diagrams} or you can enter them as a markup
2170 above the notes using the @code{\fret-diagram} command (see
2171 @ref{Fret diagram markups}).
2172
2173 @strong{Lyrics mode}
2174
2175 This is activated with the @code{\lyricmode} command, and causes
2176 input to be interpreted as lyric syllables with optional durations
2177 and associated lyric modifiers, see @ref{Vocal music}.
2178
2179 Lyric mode is also activated with the @code{\addlyrics} command.
2180 This also creates a new @code{Lyrics} context and an implicit
2181 @code{\lyricsto} command which associates the following lyrics
2182 with the preceding music.
2183
2184 @strong{Markup mode}
2185
2186 This is activated with the @code{\markup} command, and causes
2187 input to be interpreted with the syntax of markup, see
2188 @ref{Text markup commands}.
2189
2190 @c silly work-around for texinfo broken-ness
2191 @c (@strong{Note...} causes a spurious cross-reference in Info)
2192 @b{Note mode}
2193
2194 This is the default mode or it may be activated with the
2195 @code{\notemode} command.  Input is interpreted as pitches,
2196 durations, markup, etc and typeset as musical notation on a staff.
2197
2198 It is not normally necessary to specify note mode explicitly, but
2199 it may be useful to do so in certain situations, for example if you
2200 are in lyric mode, chord mode or any other mode and want to insert
2201 something that only can be done with note mode syntax.
2202
2203 For example, to indicate dynamic markings for the verses of a
2204 choral pieces it is necessary to enter note mode to interpret
2205 the markings:
2206
2207 @lilypond[verbatim,relative=2,quote]
2208 { c4 c4 c4 c4 }
2209 \addlyrics {
2210   \notemode{\set stanza = \markup{ \dynamic f 1. } }
2211   To be sung loudly
2212 }
2213 \addlyrics {
2214   \notemode{\set stanza = \markup{ \dynamic p 2. } }
2215   To be sung quietly
2216 }
2217 @end lilypond
2218
2219
2220
2221 @node Direction and placement
2222 @subsection Direction and placement
2223
2224 In typesetting music the direction and placement of many items is
2225 a matter of choice.  For example, the stems of notes can
2226 be directed up or down; lyrics, dynamics, and other expressive
2227 marks may be placed above or below the staff; text may be aligned
2228 left, right or center; etc.  Most of these choices may be left to
2229 be determined automatically by LilyPond, but in some cases it may
2230 be desirable to force a particular direction or placement.
2231
2232 @strong{Articulation direction indicators}
2233
2234 By default some directions are always up or always down (e.g.
2235 dynamics or fermata), while other things can alternate between
2236 up or down based on the stem direction (like slurs or accents).
2237
2238 @c TODO Add table showing these
2239
2240 The default action may be overridden by prefixing the articulation
2241 by a @emph{direction indicator}.  Three direction indicators are
2242 available: @code{^} (meaning @qq{up}), @code{_} (meaning @qq{down})
2243 and @code{-} (meaning @qq{use default direction}).  The direction
2244 indicator can usually be omitted, in which case @code{-} is assumed,
2245 but a direction indicator is @strong{always} required before
2246
2247 @itemize
2248 @item @code{\tweak} commands
2249 @item @code{\markup} commands
2250 @item @code{\tag} commands
2251 @item string markups, e.g. -"string"
2252 @item fingering instructions, e.g. @w{@code{-1}}
2253 @item articulation shortcuts, e.g. @w{@code{-.}}, @w{@code{->}}, @w{@code{--}}
2254 @end itemize
2255
2256 Direction indicators affect only the next note:
2257
2258 @lilypond[verbatim,quote,relative=2]
2259 c2( c)
2260 c2_( c)
2261 c2( c)
2262 c2^( c)
2263 @end lilypond
2264
2265 @strong{The direction property}
2266
2267 The position or direction of many layout objects is controlled
2268 by the @code{direction} property.
2269
2270 The value of the @code{direction} property may be
2271 set to @code{1}, meaning @qq{up} or @qq{above}, or to @w{@code{-1}},
2272 meaning @qq{down} or @qq{below}.  The symbols @code{UP} and
2273 @code{DOWN} may be used instead of @code{1} and @w{@code{-1}}
2274 respectively.  The default direction may be specified by setting
2275 @code{direction} to @code{0} or @code{CENTER}.  Alternatively,
2276 in many cases predefined commands
2277 exist to specify the direction.  These are all of the form
2278
2279 @noindent
2280 @code{\xxxUp}, @code{xxxDown}, @code{xxxNeutral}
2281
2282 @noindent
2283 where @code{xxxNeutral} means @qq{use the default direction}.
2284 See @rlearning{Within-staff objects}.
2285
2286 In a few cases, arpeggio being the only common example, the value
2287 of the @code{direction} property specifies whether the object
2288 is to be placed to the right or left of the parent object.  In
2289 this case @w{@code{-1}} or @code{LEFT} means @qq{to the left} and
2290 @code{1} or @code{RIGHT} means @qq{to the right}.  @code{0}
2291 or @code{CENTER} means @qq{use the default} direction, as before.
2292
2293 @ignore
2294 These all have side-axis set to #X
2295 AmbitusAccidental - direction has no effect
2296 Arpeggio - works
2297 StanzaNumber - not tried
2298 TrillPitchAccidental - not tried
2299 TrillPitchGroup - not tried
2300 @end ignore
2301
2302 These indications affect all notes until they are canceled.
2303
2304 @lilypond[verbatim,quote,relative=2]
2305 c2( c)
2306 \slurDown
2307 c2( c)
2308 c2( c)
2309 \slurNeutral
2310 c2( c)
2311 @end lilypond
2312
2313
2314 @node Distances and measurements
2315 @subsection Distances and measurements
2316
2317 @cindex distances, absolute
2318 @cindex distances, scaled
2319
2320 @funindex \mm
2321 @funindex \cm
2322 @funindex \in
2323 @funindex \pt
2324
2325 Distances in LilyPond are of two types: absolute and scaled.
2326
2327 Absolute distances are used for specifying margins, indents, and
2328 other page layout details, and are by default specified in
2329 millimeters.  Distances may be specified in other units by
2330 following the quantity by @code{\mm}, @code{\cm},
2331 @code{\in}@tie{}(inches), or @code{\pt}@tie{}(points, 1/72.27 of
2332 an inch).  Page layout distances can also be specified in scalable
2333 units (see the following paragraph) by appending
2334 @code{\staff-space} to the quantity.  Page layout is described in
2335 detail in @ref{Page layout}.
2336
2337 Scaled distances are always specified in units of the staff-space
2338 or, rarely, the half staff-space.  The staff-space is the distance
2339 between two adjacent staff lines.  The default value can be changed
2340 globally by setting the global staff size, or it can be overridden
2341 locally by changing the @code{staff-space} property of
2342 @code{StaffSymbol}.  Scaled distances automatically scale with any
2343 change to the either the global staff size or the
2344 @code{staff-space} property of @code{StaffSymbol}, but fonts scale
2345 automatically only with changes to the global staff size.
2346 The global staff size thus enables the overall size of a rendered
2347 score to be easily varied.  For the methods of setting the global
2348 staff size see @ref{Setting the staff size}.
2349
2350 @funindex magstep
2351
2352 If just a section of a score needs to be rendered to a different
2353 scale, for example an ossia section or a footnote, the global staff
2354 size cannot simply be changed as this would affect the entire score.
2355 In such cases the change in size is made by overriding both the
2356 @code{staff-space} property of @code{StaffSymbol} and the size of
2357 the fonts.  A Scheme function, @code{magstep}, is available to
2358 convert from a font size change to the equivalent change in
2359 @code{staff-space}.  For an explanation and an example of its use,
2360 see @rlearning{Length and thickness of objects}.
2361
2362 @seealso
2363 Learning Manual:
2364 @rlearning{Length and thickness of objects}.
2365
2366 Notation Reference:
2367 @ref{Page layout},
2368 @ref{Setting the staff size}.
2369
2370
2371 @node Staff symbol properties
2372 @subsection Staff symbol properties
2373
2374 @cindex adjusting staff symbol
2375 @cindex drawing staff symbol
2376 @cindex staff symbol, setting of
2377
2378 @c TODO Extend or remove this section.  See also NR 1.6.2 Staff symbol
2379 @c      Need to think of uses for these properties.  Eg 'line-positions
2380 @c      is used in a snippet to thicken centre line.
2381 @c      If retained, add @ref to here in 1.6.2  -td
2382
2383 The vertical position of staff lines and the number of staff lines
2384 can be defined at the same time.  As the following example shows,
2385 note positions are not influenced by the staff line positions.
2386
2387 @warning{The @code{'line-positions} property overrides the
2388 @code{'line-count} property.  The number of staff lines is
2389 implicitly defined by the number of elements in the list of values
2390 for @code{'line-positions}.}
2391
2392 @lilypond[verbatim,quote,relative=1]
2393 \new Staff \with {
2394   \override StaffSymbol #'line-positions = #'(7 3 0 -4 -6 -7)
2395 }
2396 { a4 e' f b | d1 }
2397 @end lilypond
2398
2399 The width of a staff can be modified.  The units are staff
2400 spaces.  The spacing of objects inside the staff is not affected by
2401 this setting.
2402
2403 @lilypond[verbatim,quote,relative=1]
2404 \new Staff \with {
2405   \override StaffSymbol #'width = #23
2406 }
2407 { a4 e' f b | d1 }
2408 @end lilypond
2409
2410
2411 @node Spanners
2412 @subsection Spanners
2413
2414 Many objects of musical notation extend over several notes or even
2415 several bars.  Examples are slurs, beams, tuplet brackets, volta
2416 repeat brackets, crescendi, trills, and glissandi.  Such objects
2417 are collectively called @qq{spanners}, and have special properties to control
2418 their appearance and behaviour.  Some of these properties are common
2419 to all spanners; others are restricted to a sub-set of the spanners.
2420
2421 All spanners support the @code{spanner-interface}.  A few, essentially
2422 those that draw a straight line between the two objects, support in
2423 addition the @code{line-spanner-interface}.
2424
2425 @unnumberedsubsubsec Using the @code{spanner-interface}
2426
2427 This interface provides two properties that apply to several spanners.
2428
2429 @strong{@i{The @code{minimum-length} property}}
2430
2431 The minimum length of the spanner is specified by the
2432 @code{minimum-length} property.  Increasing this usually has the
2433 necessary effect of increasing the spacing of the notes between the
2434 two end points.  However, this override has no effect on
2435 many spanners, as their length is determined by other considerations.
2436 A few examples where it is effective are shown below.
2437
2438 @ignore
2439 Works for:
2440   Tie
2441   MultiMeasureRest
2442   Hairpin
2443   Slur
2444   PhrasingSlur
2445
2446 Works as long as callback is made:
2447   Glissando
2448   Beam
2449
2450 Works not at all for:
2451   LyricSpace
2452   LyricHyphen
2453   LyricExtender
2454   TextSpanner
2455   System
2456
2457 @end ignore
2458
2459 @lilypond[verbatim,quote,relative=2]
2460 a~a
2461 a
2462 % increase the length of the tie
2463 -\tweak #'minimum-length #5
2464 ~a
2465 @end lilypond
2466
2467 @lilypond[verbatim,quote,relative=2]
2468 a1
2469 \compressFullBarRests
2470 R1*23
2471 % increase the length of the rest bar
2472 \once \override MultiMeasureRest #'minimum-length = #20
2473 R1*23
2474 a1
2475 @end lilypond
2476
2477 @lilypond[verbatim,quote,relative=2]
2478 a \< a a a \!
2479 % increase the length of the hairpin
2480 \override Hairpin #'minimum-length = #20
2481 a \< a a a \!
2482 @end lilypond
2483
2484 This override can also be used to increase the length of slurs and
2485 phrasing slurs:
2486
2487 @lilypond[verbatim,quote,relative=2]
2488 a( a)
2489 a
2490 -\tweak #'minimum-length #5
2491 ( a)
2492
2493 a\( a\)
2494 a
2495 -\tweak #'minimum-length #5
2496 \( a\)
2497 @end lilypond
2498
2499 For some layout objects, the @code{minimum-length} property becomes
2500 effective only if the @code{set-spacing-rods} procedure is called
2501 explicitly.  To do this, the @code{springs-and-rods} property should
2502 be set to @code{ly:spanner::set-spacing-rods}.  For example,
2503 the minimum length of a glissando has no effect unless the
2504 @code{springs-and-rods} property is set:
2505
2506 @lilypond[verbatim,quote,relative=1]
2507 % default
2508 e \glissando c'
2509
2510 % not effective alone
2511 \once \override Glissando #'minimum-length = #20
2512 e, \glissando c'
2513
2514 % effective only when both overrides are present
2515 \once \override Glissando #'minimum-length = #20
2516 \once \override Glissando #'springs-and-rods = #ly:spanner::set-spacing-rods
2517 e, \glissando c'
2518 @end lilypond
2519
2520 The same is true of the @code{Beam} object:
2521
2522 @lilypond[verbatim,quote,relative=1]
2523 % not effective alone
2524 \once \override Beam #'minimum-length = #20
2525 e8 e e e
2526
2527 % effective only when both overrides are present
2528 \once \override Beam #'minimum-length = #20
2529 \once \override Beam #'springs-and-rods = #ly:spanner::set-spacing-rods
2530 e8 e e e
2531 @end lilypond
2532
2533 @strong{@i{The @code{to-barline} property}}
2534
2535 The second useful property of the @code{spanner-interface} is
2536 @code{to-barline}.  By default this is true, causing hairpins and
2537 other spanners which are terminated on the first note of a measure to
2538 end instead on the immediately preceding bar line.  If set to false,
2539 the spanner will extend beyond the bar line and end on the note
2540 itself:
2541
2542 @lilypond[verbatim,quote,relative=2]
2543 a \< a a a a \! a a a \break
2544 \override Hairpin #'to-barline = ##f
2545 a \< a a a a \! a a a
2546 @end lilypond
2547
2548 This property is not effective for all spanners.  For example,
2549 setting it to @code{#t} has no effect on slurs or phrasing slurs
2550 or on other spanners for which terminating on the bar line would
2551 not be meaningful.
2552
2553 @unnumberedsubsubsec Using the @code{line-spanner-interface}
2554
2555 Objects which support the @code{line-spanner-interface} include
2556
2557 @itemize
2558 @item @code{DynamicTextSpanner}
2559 @item @code{Glissando}
2560 @item @code{TextSpanner}
2561 @item @code{TrillSpanner}
2562 @item @code{VoiceFollower}
2563 @end itemize
2564
2565 The routine responsible for drawing the stencils for these spanners is
2566 @code{ly:line-interface::print}.  This routine determines the
2567 exact location of the two end points and draws a line
2568 between them, in the style requested.  The locations of the two
2569 end points of the spanner are computed on-the-fly, but it is
2570 possible to override their Y-coordinates.  The
2571 properties which need to be specified are nested
2572 two levels down within the property hierarchy, but the syntax of
2573 the @code{\override} command is quite simple:
2574
2575 @lilypond[relative=2,quote,verbatim]
2576 e2 \glissando b
2577 \once \override Glissando #'(bound-details left Y) = #3
2578 \once \override Glissando #'(bound-details right Y) = #-2
2579 e2 \glissando b
2580 @end lilypond
2581
2582 The units for the @code{Y} property are @code{staff-space}s,
2583 with the center line of the staff being the zero point.
2584 For the glissando, this is the value for @code{Y} at the
2585 X-coordinate corresponding to the center point of each note head,
2586 if the line is imagined to be extended to there.
2587
2588 If @code{Y} is not set, the value is computed from the vertical
2589 position of the corresponding attachment point of the spanner.
2590
2591 In case of a line break, the values for the end points are
2592 specified by the @code{left-broken} and @code{right-broken}
2593 sub-lists of @code{bound-details}.  For example:
2594
2595 @lilypond[relative=2,ragged-right,verbatim,quote]
2596 \override Glissando #'breakable = ##t
2597 \override Glissando #'(bound-details right-broken Y) = #-3
2598 c1 \glissando \break
2599 f1
2600 @end lilypond
2601
2602
2603 A number of further properties of the @code{left} and
2604 @code{right} sub-lists of the @code{bound-details} property
2605 may be modified in the same way as @code{Y}:
2606
2607 @table @code
2608 @item Y
2609 This sets the Y-coordinate of the end point, in @code{staff-space}s
2610 offset from the staff center line.  By default, it is the center of
2611 the bound object, so a glissando points to the vertical center of
2612 the note head.
2613
2614 For horizontal spanners, such as text spanners and trill spanners,
2615 it is hardcoded to 0.
2616
2617 @item attach-dir
2618 This determines where the line starts and ends in the X-direction,
2619 relative to the bound object.  So, a value of @w{@code{-1}} (or
2620 @code{LEFT}) makes the line start/end at the left side of the note
2621 head it is attached to.
2622
2623 @item X
2624 This is the absolute X-coordinate of the end point.  It is usually
2625 computed on the fly, and overriding it has little useful effect.
2626
2627 @item stencil
2628 Line spanners may have symbols at the beginning or end, which is
2629 contained in this sub-property.  This is for internal use; it is
2630 recommended that @code{text} be used instead.
2631
2632 @item text
2633 This is a markup that is evaluated to yield the stencil.  It is used
2634 to put @i{cresc.}, @i{tr} and other text on horizontal spanners.
2635
2636 @lilypond[quote,ragged-right,relative=2,verbatim]
2637 \override TextSpanner #'(bound-details left text)
2638    = \markup { \small \bold Slower }
2639 c2\startTextSpan b c a\stopTextSpan
2640 @end lilypond
2641
2642 @item stencil-align-dir-y
2643 @item stencil-offset
2644 Without setting one of these, the stencil is simply put at the
2645 end-point, centered on the line, as defined by the @code{X} and
2646 @code{Y} sub-properties.  Setting either @code{stencil-align-dir-y}
2647 or @code{stencil-offset} will move the symbol at the edge vertically
2648 relative to the end point of the line:
2649
2650 @lilypond[relative=1,quote,verbatim]
2651 \override TextSpanner
2652   #'(bound-details left stencil-align-dir-y) = #-2
2653 \override TextSpanner
2654   #'(bound-details right stencil-align-dir-y) = #UP
2655
2656 \override TextSpanner
2657   #'(bound-details left text) = #"ggg"
2658 \override TextSpanner
2659   #'(bound-details right text) = #"hhh"
2660 c4^\startTextSpan c c c \stopTextSpan
2661 @end lilypond
2662
2663 Note that negative values move the text @emph{up}, contrary to the
2664 effect that might be expected, as a value of @w{@code{-1}} or
2665 @code{DOWN} means align the @emph{bottom} edge of the text with
2666 the spanner line.  A value of @code{1} or @code{UP} aligns
2667 the top edge of the text with the spanner line.
2668
2669 @item arrow
2670 Setting this sub-property to @code{#t} produces an arrowhead at the
2671 end of the line.
2672
2673 @item padding
2674 This sub-property controls the space between the specified
2675 end point of the line and the actual end.  Without padding, a
2676 glissando would start and end in the center of each note head.
2677
2678 @end table
2679
2680 The music function @code{\endSpanners} terminates the spanner
2681 which starts on the immediately following note prematurely.  It
2682 is terminated after exactly one note, or at the following bar line
2683 if @code{to-barline} is true and a bar line occurs before the next
2684 note.
2685
2686 @lilypond[verbatim,quote,ragged-right,relative=2]
2687 \endSpanners
2688 c2 \startTextSpan c2 c2
2689 \endSpanners
2690 c2 \< c2 c2
2691 @end lilypond
2692
2693 When using @code{\endSpanners} it is not necessary to close
2694 \startTextSpan with \stopTextSpan, nor is it necessary to close
2695 hairpins with @code{\!}.
2696
2697 @seealso
2698 Internals Reference:
2699 @rinternals{TextSpanner},
2700 @rinternals{Glissando},
2701 @rinternals{VoiceFollower},
2702 @rinternals{TrillSpanner},
2703 @rinternals{line-spanner-interface}.
2704
2705
2706 @node Visibility of objects
2707 @subsection Visibility of objects
2708
2709 @cindex objects, visibility of
2710 @cindex grobs, visibility of
2711 @cindex visibility of objects
2712
2713 There are four main ways in which the visibility of layout objects
2714 can be controlled: their stencil can be removed, they can be made
2715 transparent, they can be colored white, or their
2716 @code{break-visibility} property can be overridden.  The first
2717 three apply to all layout objects; the last to just a few -- the
2718 @emph{breakable} objects.  The Learning Manual introduces these
2719 four techniques, see @rlearning{Visibility and color of objects}.
2720
2721 There are also a few other techniques which are specific to
2722 certain layout objects.  These are covered under Special
2723 considerations.
2724
2725 @menu
2726 * Removing the stencil::
2727 * Making objects transparent::
2728 * Painting objects white::
2729 * Using break-visibility::
2730 * Special considerations::
2731 @end menu
2732
2733
2734 @node Removing the stencil
2735 @unnumberedsubsubsec Removing the stencil
2736
2737 @cindex stencil, removing
2738
2739 Every layout object has a stencil property.  By default this is set
2740 to the specific function which draws that object.  If this property
2741 is overridden to @code{#f} no function will be called and the object
2742 will not be drawn.  The default action can be recovered with
2743 @code{\revert}.
2744
2745 @lilypond[quote,verbatim,relative=1]
2746 a1 a
2747 \override Score.BarLine #'stencil = ##f
2748 a a
2749 \revert Score.BarLine #'stencil
2750 a a a
2751 @end lilypond
2752
2753 @node Making objects transparent
2754 @unnumberedsubsubsec Making objects transparent
2755
2756 @cindex transparent, making objects
2757
2758 Every layout object has a transparent property which by default is
2759 set to @code{#f}.  If set to @code{#t} the object still occupies
2760 space but is made invisible.
2761
2762 @lilypond[quote,verbatim,relative=2]
2763 a4 a
2764 \once \override NoteHead #'transparent = ##t
2765 a a
2766 @end lilypond
2767
2768 @node Painting objects white
2769 @unnumberedsubsubsec Painting objects white
2770
2771 @cindex objects, coloring
2772 @cindex coloring objects
2773 @cindex layers
2774 @cindex printing order
2775 @cindex overwriting objects
2776 @cindex objects, overwriting
2777 @cindex grobs, overwriting
2778
2779 Every layout object has a color property which by default is set
2780 to @code{black}.  If this is overridden to @code{white} the object
2781 will be indistinguishable from the white background.  However,
2782 if the object crosses other objects the color of the crossing
2783 points will be determined by the order in which they are drawn,
2784 and this may leave a ghostly image of the white object, as shown
2785 here:
2786
2787 @lilypond[quote,verbatim,relative=2]
2788 \override Staff.Clef #'color = #white
2789 a1
2790 @end lilypond
2791
2792 This may be avoided by changing the order of printing the objects.
2793 All layout objects have a @code{layer} property which should be set
2794 to an integer.  Objects with the lowest value of @code{layer} are
2795 drawn first, then objects with progressively higher values are drawn,
2796 so objects with higher values overwrite objects with lower values.
2797 By default most objects are assigned a @code{layer} value of
2798 @code{1}, although a few objects, including @code{StaffSymbol} and
2799 @code{BarLine}, are assigned a value of @code{0}.  The order of
2800 printing objects with the same value of @code{layer} is indeterminate.
2801
2802 In the example above the white clef, with a default @code{layer}
2803 value of @code{1}, is drawn after the staff lines (default
2804 @code{layer} value @code{0}), so overwriting them.  To change this,
2805 the @code{Clef} object must be given in a lower value of
2806 @code{layer}, say @w{@code{-1}}, so that it is drawn earlier:
2807
2808 @lilypond[quote,verbatim,relative=2]
2809 \override Staff.Clef #'color = #white
2810 \override Staff.Clef #'layer = #-1
2811 a1
2812 @end lilypond
2813
2814 @node Using break-visibility
2815 @unnumberedsubsubsec Using break-visibility
2816
2817 @c TODO Add making other objects breakable
2818
2819 @cindex break-visibility
2820
2821 Most layout objects are printed only once, but some like
2822 bar lines, clefs, time signatures and key signatures, may need
2823 to be printed twice when a line break occurs -- once at the end
2824 of the line and again at the start of the next line.  Such
2825 objects are called @emph{breakable}, and have a property, the
2826 @code{break-visibility} property to control their visibility
2827 at the three positions in which they may appear -- at the
2828 start of a line, within a line if they are changed, and at the
2829 end of a line if a change takes place there.
2830
2831 For example, the time signature
2832 by default will be printed at the start of the first line, but
2833 nowhere else unless it changes, when it will be printed at the
2834 point at which the change occurs.  If this change occurs at the
2835 end of a line the new time signature will be printed at the start
2836 of the next line and a cautionary time signature will be printed
2837 at the end of the previous line as well.
2838
2839 This behaviour is controlled by the @code{break-visibility}
2840 property, which is explained in
2841 @c Leave this ref on a newline - formats incorrectly otherwise -td
2842 @rlearning{Visibility and color of objects}.  This property takes
2843 a vector of three booleans which, in order, determine whether the
2844 object is printed at the end of, within the body of, or at the
2845 beginning of a line.  Or to be more precise, before a line break,
2846 where there is no line break, or after a line break.
2847
2848 Alternatively, these eight combinations may be specified
2849 by pre-defined functions, defined in @file{scm/output-lib.scm},
2850 where the last three columns indicate whether the layout objects
2851 will be visible in the positions shown at the head of the columns:
2852
2853 @multitable {@code{begin-of-line-invisible}} {@code{'#(#t #t #t)}} {yes} {yes} {yes}
2854 @headitem Function                   @tab Vector                  @tab Before @tab At no    @tab After
2855 @headitem form                       @tab form                    @tab break  @tab break    @tab break
2856
2857 @item @code{all-visible}             @tab @code{'#(#t #t #t)}     @tab yes    @tab yes      @tab yes
2858 @item @code{begin-of-line-visible}   @tab @code{'#(#f #f #t)}     @tab no     @tab no       @tab yes
2859 @item @code{center-visible}          @tab @code{'#(#f #t #f)}     @tab no     @tab yes      @tab no
2860 @item @code{end-of-line-visible}     @tab @code{'#(#t #f #f)}     @tab yes    @tab no       @tab no
2861 @item @code{begin-of-line-invisible} @tab @code{'#(#t #t #f)}     @tab yes    @tab yes      @tab no
2862 @item @code{center-invisible}        @tab @code{'#(#t #f #t)}     @tab yes    @tab no       @tab yes
2863 @item @code{end-of-line-invisible}   @tab @code{'#(#f #t #t)}     @tab no     @tab yes      @tab yes
2864 @item @code{all-invisible}           @tab @code{'#(#f #f #f)}     @tab no     @tab no       @tab no
2865 @end multitable
2866
2867 The default settings of @code{break-visibility} depend on the
2868 layout object.  The following table shows all the layout objects
2869 of interest which are affected by @code{break-visibility} and the
2870 default setting of this property:
2871
2872 @multitable @columnfractions .3 .3 .4
2873
2874 @headitem Layout object   @tab Usual context  @tab Default setting
2875
2876 @c omit Ambitus as it appears not to be affected by break-visibility -td
2877 @c @item @code{Ambitus}          @tab as specified   @tab @code{begin-of-line-visible}
2878 @item @code{BarLine}             @tab @code{Score}          @tab calculated
2879 @item @code{BarNumber}           @tab @code{Score}          @tab @code{begin-of-line-visible}
2880 @c omit the following item until it can be explained -td
2881 @c @item @code{BreakAlignGroup}  @tab @code{Score}          @tab calculated
2882 @item @code{BreathingSign}       @tab @code{Voice}          @tab @code{begin-of-line-invisible}
2883 @item @code{Clef}                @tab @code{Staff}          @tab @code{begin-of-line-visible}
2884 @item @code{Custos}              @tab @code{Staff}          @tab @code{end-of-line-visible}
2885 @item @code{DoublePercentRepeat} @tab @code{Voice}          @tab @code{begin-of-line-invisible}
2886 @c omit KeyCancellation until it can be explained -td
2887 @c @item @code{KeyCancellation}  @tab ??             @tab @code{begin-of-line-invisible}
2888 @item @code{KeySignature}        @tab @code{Staff}          @tab @code{begin-of-line-visible}
2889 @c omit LeftEdge until it can be explained -td
2890 @c @item @code{LeftEdge}         @tab @code{Score}          @tab @code{center-invisible}
2891 @item @code{OctavateEight}       @tab @code{Staff}          @tab @code{begin-of-line-visible}
2892 @item @code{RehearsalMark}       @tab @code{Score}          @tab @code{end-of-line-invisible}
2893 @item @code{TimeSignature}       @tab @code{Staff}          @tab @code{all-visible}
2894
2895 @end multitable
2896
2897 The example below shows the use of the vector form to control the
2898 visibility of bar lines:
2899
2900 @lilypond[quote,verbatim,relative=1,ragged-right]
2901 f4 g a b
2902 f4 g a b
2903 % Remove bar line at the end of the current line
2904 \once \override Score.BarLine #'break-visibility = #'#(#f #t #t)
2905 \break
2906 f4 g a b
2907 f4 g a b
2908 @end lilypond
2909
2910 Although all three components of the vector used to override
2911 @code{break-visibility} must be present, not all of them are
2912 effective with every layout object, and some combinations may
2913 even give errors.  The following limitations apply:
2914
2915 @itemize @bullet
2916 @item Bar lines cannot be printed at start of line.
2917 @item A bar number cannot be printed at the start of the first
2918 line unless it is set to be different from 1.
2919 @item Clef -- see below
2920 @item Double percent repeats are either all printed or all
2921 suppressed.  Use begin-of line-invisible to print and
2922 all-invisible to suppress.
2923 @item Key signature -- see below
2924 @item OctavateEight -- see below
2925 @end itemize
2926
2927 @node Special considerations
2928 @unnumberedsubsubsec Special considerations
2929
2930 @strong{@emph{Visibility following explicit changes}}
2931
2932 @cindex key signature, visibility following explicit change
2933 @cindex explicitKeySignatureVisibility
2934 @cindex clef, visibility following explicit change
2935 @cindex explicitClefVisibility
2936
2937 The @code{break-visibility} property controls the visibility of
2938 key signatures and changes of clef only at the start of lines,
2939 i.e. after a break.  It has no effect on the visibility of the
2940 key signature or clef following an explicit key change or an
2941 explicit clef change within or at the end of a line.  In the
2942 following example the key signature following the explicit change
2943 to B-flat major is still visible, even though @code{all-invisible}
2944 is set.
2945
2946 @lilypond[quote,verbatim,relative=1,ragged-right]
2947 \key g \major
2948 f4 g a b
2949 % Try to remove all key signatures
2950 \override Staff.KeySignature #'break-visibility = #all-invisible
2951 \key bes \major
2952 f4 g a b
2953 \break
2954 f4 g a b
2955 f4 g a b
2956 @end lilypond
2957
2958 The visibility of such explicit key signature and clef changes is
2959 controlled by the @code{explicitKeySignatureVisibility} and
2960 @code{explicitClefVisibility} properties.  These are the equivalent
2961 of the @code{break-visibility} property and both take a vector of
2962 three booleans or the predefined functions listed above, exactly like
2963 @code{break-visibility}.  Both are properties of the Staff context,
2964 not the layout objects themselves, and so they are set using the
2965 @code{\set} command.  Both are set by default to @code{all-visible}.
2966 These properties control only the visibility of key signatures and
2967 clefs resulting from explicit changes and do not affect key
2968 signatures and clefs at the beginning of lines;
2969 @code{break-visibility} must still be overridden in the appropriate
2970 object to remove these.
2971
2972 @lilypond[quote,verbatim,relative=1,ragged-right]
2973 \key g \major
2974 f4 g a b
2975 \set Staff.explicitKeySignatureVisibility = #all-invisible
2976 \override Staff.KeySignature #'break-visibility = #all-invisible
2977 \key bes \major
2978 f4 g a b \break
2979 f4 g a b
2980 f4 g a b
2981 @end lilypond
2982
2983 @strong{@emph{Visibility of cautionary accidentals}}
2984
2985 To remove the cautionary accidentals printed at an explicit key
2986 change, set the Staff context property @code{printKeyCancellation}
2987 to @code{#f}:
2988
2989 @lilypond[quote,verbatim,relative=1,ragged-right]
2990 \key g \major
2991 f4 g a b
2992 \set Staff.explicitKeySignatureVisibility = #all-invisible
2993 \set Staff.printKeyCancellation = ##f
2994 \override Staff.KeySignature #'break-visibility = #all-invisible
2995 \key bes \major
2996 f4 g a b \break
2997 f4 g a b
2998 f4 g a b
2999 @end lilypond
3000
3001 With these overrides only the accidentals before the notes remain
3002 to indicate the change of key.
3003
3004 @c TODO Add visibility of cautionary accidentals before notes
3005
3006 @strong{@emph{Automatic bars}}
3007
3008 @cindex automaticBars
3009 @cindex bar lines, suppressing
3010
3011 As a special case, the printing of bar lines can also be turned off
3012 by setting the @code{automaticBars} property in the Score context.
3013 If set to @code{#f}, bar lines will not be printed automatically;
3014 they must be explicitly created with a @code{\bar} command.  Unlike
3015 the @code{\cadenzaOn} predefined command, measures are still counted.
3016 Bar generation will resume according to that count if this property
3017 is later set to @code{#t}.  When set to @code{#f}, line breaks can
3018 occur only at explicit @code{\bar} commands.
3019
3020 @c TODO Add example
3021
3022 @strong{@emph{Octavated clefs}}
3023
3024 @cindex octavated clefs, visibility of
3025 @cindex visibility of octavated clefs
3026 @cindex clefs, visibility of octavation
3027
3028 The small octavation symbol on octavated clefs is produced by the
3029 @code{OctavateEight} layout object.  Its visibility is automatically
3030 inherited from the @code{Clef} object, so it is not necessary to apply
3031 any required @code{break-visibility} overrides to the @code{OctavateEight} 
3032 layout objects to suppress octavation symbols for invisible clefs.
3033
3034 For explicit clef changes, the @code{explicitClefVisibility}
3035 property controls both the clef symbol and any octavation symbol
3036 associated with it.
3037
3038 @seealso
3039 Learning Manual:
3040 @rlearning{Visibility and color of objects}.
3041
3042
3043 @node Line styles
3044 @subsection Line styles
3045
3046 Some performance indications, e.g., @i{rallentando} and
3047 @i{accelerando} and @i{trills} are written as text and are
3048 extended over many measures with lines, sometimes dotted or wavy.
3049
3050 These all use the same routines as the glissando for drawing the
3051 texts and the lines, and tuning their behavior is therefore also
3052 done in the same way.  It is done with a spanner, and the routine
3053 responsible for drawing the spanners is
3054 @code{ly:line-interface::print}.  This routine determines the
3055 exact location of the two @i{span points} and draws a line
3056 between them, in the style requested.
3057
3058 Here is an example showing the different line styles available,
3059 and how to tune them.
3060
3061 @lilypond[relative=2,ragged-right,verbatim,quote]
3062 d2 \glissando d'2
3063 \once \override Glissando #'style = #'dashed-line
3064 d,2 \glissando d'2
3065 \override Glissando #'style = #'dotted-line
3066 d,2 \glissando d'2
3067 \override Glissando #'style = #'zigzag
3068 d,2 \glissando d'2
3069 \override Glissando #'style = #'trill
3070 d,2 \glissando d'2
3071 @end lilypond
3072
3073 The locations of the end-points of the spanner are computed
3074 on-the-fly for every graphic object, but it is possible to
3075 override these:
3076
3077 @c TODO Complete
3078 @lilypond[relative=2,ragged-right,verbatim,quote]
3079 e2 \glissando f
3080 \once \override Glissando #'(bound-details right Y) = #-2
3081 e2 \glissando f
3082 @end lilypond
3083
3084 The value for @code{Y} is set to @w{@code{-2}} for the right end
3085 point.  The left side may be similarly adjusted by specifying
3086 @code{left} instead of @code{right}.
3087
3088 If @code{Y} is not set, the value is computed from the vertical
3089 position of the left and right attachment points of the spanner.
3090
3091 Other adjustments of spanners are possible, for details, see
3092 @ref{Spanners}.
3093
3094 @node Rotating objects
3095 @subsection Rotating objects
3096
3097 Both layout objects and elements of markup text can be rotated by
3098 any angle about any point, but the method of doing so differs.
3099
3100 @menu
3101 * Rotating layout objects::
3102 * Rotating markup::
3103 @end menu
3104
3105 @node Rotating layout objects
3106 @unnumberedsubsubsec Rotating layout objects
3107
3108 @cindex rotating objects
3109 @cindex objects, rotating
3110
3111 All layout objects which support the @code{grob-interface} can be
3112 rotated by setting their @code{rotation} property.  This takes a
3113 list of three items: the angle of rotation counter-clockwise,
3114 and the x and y coordinates of the point relative to the object's
3115 reference point about which the rotation is to be performed.  The
3116 angle of rotation is specified in degrees and the coordinates in
3117 staff-spaces.
3118
3119 The angle of rotation and the coordinates of the rotation point must
3120 be determined by trial and error.
3121
3122 @cindex hairpins, angled
3123 @cindex angled hairpins
3124
3125 There are only a few situations where the rotation of layout
3126 objects is useful; the following example shows one situation where
3127 they may be:
3128
3129 @lilypond[quote,verbatim,relative=1]
3130 g4\< e' d' f\!
3131 \override Hairpin #'rotation = #'(20 -1 0)
3132 g,,4\< e' d' f\!
3133 @end lilypond
3134
3135 @node Rotating markup
3136 @unnumberedsubsubsec Rotating markup
3137
3138 All markup text can be rotated to lie at any angle by prefixing it
3139 with the @code{\rotate} command.  The command takes two arguments:
3140 the angle of rotation in degrees counter-clockwise and the text to
3141 be rotated.  The extents of the text are not rotated: they take
3142 their values from the extremes of the x and y coordinates of the
3143 rotated text.  In the following example the
3144 @code{outside-staff-priority} property for text is set to @code{#f}
3145 to disable the automatic collision avoidance, which would push some
3146 of the text too high.
3147
3148 @lilypond[quote,verbatim,relative=1]
3149 \override TextScript #'outside-staff-priority = ##f
3150 g4^\markup { \rotate #30 "a G" }
3151 b^\markup { \rotate #30 "a B" }
3152 des^\markup { \rotate #30 "a D-Flat" }
3153 fis^\markup { \rotate #30 "an F-Sharp" }
3154 @end lilypond
3155
3156 @node Advanced tweaks
3157 @section Advanced tweaks
3158
3159 This section discusses various approaches to fine tuning the
3160 appearance of the printed score.
3161
3162 @menu
3163 * Aligning objects::
3164 * Vertical grouping of grobs::
3165 * Modifying stencils::
3166 * Modifying shapes::
3167 * Unpure-pure containers::
3168 @end menu
3169
3170 @seealso
3171 Learning Manual:
3172 @rlearning{Tweaking output},
3173 @rlearning{Other sources of information}.
3174
3175 Notation Reference:
3176 @ref{Explaining the Internals Reference},
3177 @ref{Modifying properties}.
3178
3179 Extending LilyPond:
3180 @rextend{Interfaces for programmers}.
3181
3182 Installed Files:
3183 @file{scm/define-grobs.scm}.
3184
3185 Snippets:
3186 @rlsr{Tweaks and overrides}.
3187
3188 Internals Reference:
3189 @rinternals{All layout objects}.
3190
3191
3192 @node Aligning objects
3193 @subsection Aligning objects
3194
3195 Graphical objects which support the @code{self-alignment-interface}
3196 and/or the @code{side-position-interface} can be aligned to a previously
3197 placed object in a variety of ways.  For a list of these objects, see
3198 @rinternals{self-alignment-interface} and @rinternals{side-position-interface}.
3199
3200 All graphical objects have a reference point, a horizontal extent and a
3201 vertical extent.  The horizontal extent is a pair of numbers
3202 giving the displacements from the reference point of the left and
3203 right edges, displacements to the left being negative.  The vertical
3204 extent is a pair of numbers giving the displacement from the reference
3205 point to the bottom and top edges, displacements down being negative.
3206
3207 An object's position on a staff is given by the values of the
3208 @code{X-offset} and @code{Y-offset} properties.  The value of
3209 @code{X-offset} gives the displacement from the X coordinate of
3210 the reference point of the parent object, and the value of
3211 @code{Y-offset} gives the displacement from the center line of the
3212 staff.  The values of @code{X-offset} and @code{Y-offset} may
3213 be set directly or may be set to be calculated by procedures in order
3214 to achieve alignment with the parent object.
3215
3216 @warning{Many objects have special positioning considerations which
3217 cause any setting of @code{X-offset} or @code{Y-offset} to be
3218 ignored or modified, even though the object supports the
3219 @code{self-alignment-interface}.  Overriding the @code{X-offset}
3220 or @code{Y-offset} properties to a fixed value causes the respective
3221 @code{self-alignment} property to be disregarded.}
3222
3223 For example, an accidental can be repositioned vertically by setting
3224 @code{Y-offset} but any changes to @code{X-offset} have no effect.
3225
3226 Rehearsal marks may be aligned with breakable objects such as bar
3227 lines, clef symbols, time signature symbols and key signatures.  There
3228 are special properties to be found in the @code{break-aligned-interface}
3229 for positioning rehearsal marks on such objects.
3230
3231 @seealso
3232 Internals Reference:
3233 @ref{Using the break-alignable-interface}.
3234
3235 Exending LilyPond:
3236 @rextend{Callback functions}.
3237
3238 @menu
3239 * Setting X-offset and Y-offset directly::
3240 * Using the side-position-interface::
3241 * Using the self-alignment-interface::
3242 * Using the break-alignable-interface::
3243 @end menu
3244
3245 @node Setting X-offset and Y-offset directly
3246 @unnumberedsubsubsec Setting @code{X-offset} and @code{Y-offset} directly
3247
3248 Numerical values may be given to the @code{X-offset} and @code{Y-offset}
3249 properties of many objects.  The following example shows three
3250 notes with the default fingering position and the positions with @code{X-offset}
3251 and @code{Y-offset} modified.
3252
3253 @lilypond[verbatim,quote,relative=2]
3254 a-3
3255 a
3256 -\tweak #'X-offset #0
3257 -\tweak #'Y-offset #0
3258 -3
3259 a
3260 -\tweak #'X-offset #-1
3261 -\tweak #'Y-offset #1
3262 -3
3263 @end lilypond
3264
3265 @c TODO write more
3266
3267 @node Using the side-position-interface
3268 @unnumberedsubsubsec Using the @code{side-position-interface}
3269
3270 An object which supports the @code{side-position-interface} can be
3271 placed next to its parent object so that
3272 the specified edges of the two objects touch.  The object may be
3273 placed above, below, to the right or to the left of the parent.
3274 The parent cannot be specified; it is determined by the order of
3275 elements in the input stream.  Most objects have the associated
3276 note head as their parent.
3277
3278 The values of the @code{side-axis} and @code{direction} properties
3279 determine where the object is to be placed, as follows:
3280
3281 @c TODO add an example of each to the table
3282
3283 @multitable @columnfractions .3 .3 .3
3284 @headitem @code{side-axis}  @tab @code{direction}  @tab
3285 @headitem property          @tab property          @tab Placement
3286
3287 @item     @code{0}          @tab @code{-1}         @tab left
3288 @item     @code{0}          @tab @code{1}          @tab right
3289 @item     @code{1}          @tab @code{-1}         @tab below
3290 @item     @code{1}          @tab @code{1}          @tab above
3291
3292 @end multitable
3293
3294 When @code{side-axis} is @code{0}, @code{X-offset} should be set to
3295 the procedure @code{ly:side-position-interface::x-aligned-side}.
3296 This procedure will return the correct value of @code{X-offset} to
3297 place the object to the left or right side of the parent according
3298 to value of @code{direction}.
3299
3300 When @code{side-axis} is @code{1}, @code{Y-offset} should be set to
3301 the procedure @code{ly:side-position-interface::y-aligned-side}.
3302 This procedure will return the correct value of @code{Y-offset} to
3303 place the object to the top or bottom of the parent according
3304 to value of @code{direction}.
3305
3306 @c TODO Add examples
3307
3308 @node Using the self-alignment-interface
3309 @unnumberedsubsubsec Using the @code{self-alignment-interface}
3310
3311 @emph{Self-aligning objects horizontally}
3312
3313 The horizontal alignment of an object which supports the
3314 @code{self-alignment-interface} is controlled by the value of
3315 the @code{self-alignment-X} property, provided the object's
3316 @code{X-offset} property is set to
3317 @code{ly:self-alignment-interface::x-aligned-on-self}.
3318 @code{self-alignment-X}  may be given any
3319 real value, in units of half the total X extent of the
3320 object.  Negative values move the object to the right, positive
3321 to the left.  A value of @code{0} centers the object on the
3322 reference point of its parent, a value of @w{@code{-1}} aligns the
3323 left edge of the object on the reference point of its parent,
3324 and a value of @code{1} aligns the right edge of the object on the
3325 reference point of its parent.  The symbols @code{LEFT},
3326 @code{CENTER}, and @code{RIGHT} may be used instead of the values
3327 @w{@code{-1}}, @code{0}, and @code{1}, respectively.
3328
3329 Normally the @code{\override} command would be used to modify the
3330 value of @code{self-alignment-X}, but the @code{\tweak} command
3331 can be used to separately align several annotations on a single
3332 note:
3333
3334 @lilypond[quote,verbatim,relative=1]
3335 a'
3336 -\tweak #'self-alignment-X #-1
3337 ^"left-aligned"
3338 -\tweak #'self-alignment-X #0
3339 ^"center-aligned"
3340 -\tweak #'self-alignment-X #RIGHT
3341 ^"right-aligned"
3342 -\tweak #'self-alignment-X #-2.5
3343 ^"aligned further to the right"
3344 @end lilypond
3345
3346 @emph{Self-aligning objects vertically}
3347
3348 Objects may be aligned vertically in an analogous way to aligning
3349 them horizontally if the @code{Y-offset} property is set to
3350 @code{ly:self-alignment-interface::y-aligned-on-self}.  However,
3351 other mechanisms are often involved in vertical alignment: the
3352 value of @code{Y-offset} is just one variable taken into account.
3353 This may make adjusting the value of some objects tricky.
3354 The units are just half the vertical extent of the object, which
3355 is usually quite small, so quite large numbers may be required.
3356 A value of @w{@code{-1}} aligns the lower edge of the object with
3357 the reference point of the parent object, a value of @code{0}
3358 aligns the center of the object with the reference point of the
3359 parent, and a value of @code{1} aligns the top edge of the object
3360 with the reference point of the parent.  The symbols @code{DOWN},
3361 @code{CENTER}, and @code{UP} may be substituted for @w{@code{-1}},
3362 @code{0}, and @code{1}, respectively.
3363
3364 @emph{Self-aligning objects in both directions}
3365
3366 By setting both @code{X-offset} and @code{Y-offset}, an object may
3367 be aligned in both directions simultaneously.
3368
3369 The following example shows how to adjust a fingering mark so
3370 that it nestles close to the note head.
3371
3372 @lilypond[quote,verbatim,relative=2]
3373 a
3374 -\tweak #'self-alignment-X #0.5  % move horizontally left
3375 -\tweak #'Y-offset #ly:self-alignment-interface::y-aligned-on-self
3376 -\tweak #'self-alignment-Y #-1  % move vertically up
3377 -3  % third finger
3378 @end lilypond
3379
3380 @ignore
3381 @unnumberedsubsubsec Using the @code{aligned-on-parent} procedures
3382
3383 @c Cannot document as they do not seem to operate consistently on all objects -td
3384 @c TODO investigate further
3385
3386 The @code{aligned-on-parent} procedures are used in the same way
3387 as the @code{aligned-on-self} procedures, they difference being
3388 that they permit an object to be aligned with the @emph{edges} of
3389 the parent rather than the parent's reference point.  The following
3390 example shows the difference:
3391
3392 @c TODO Add example
3393
3394 @lilypond[verbatim,quote]
3395 @end lilypond
3396
3397 @end ignore
3398
3399 @ignore
3400 @unnumberedsubsubsec Using the @code{centered-on-parent} procedures
3401
3402 @c Cannot document as they do not seem to operate consistently on all objects -td
3403 @c TODO investigate further
3404
3405 @end ignore
3406
3407 @c TODO The align-interface, BassFigureAlignment and VerticalAlignment
3408
3409 @node Using the break-alignable-interface
3410 @unnumberedsubsubsec Using the @code{break-alignable-interface}
3411
3412 @cindex align to objects
3413 @cindex break-align-symbols
3414
3415 Rehearsal marks and bar numbers may be aligned with notation
3416 objects other than bar lines.  These objects include @code{ambitus},
3417 @code{breathing-sign}, @code{clef}, @code{custos}, @code{staff-bar},
3418 @code{left-edge}, @code{key-cancellation}, @code{key-signature}, and
3419 @code{time-signature}.
3420
3421 By default, rehearsal marks and bar numbers will be horizontally
3422 centered above the object:
3423
3424 @lilypond[verbatim,quote,relative=1]
3425 % The rehearsal mark will be centered above the Clef
3426 \override Score.RehearsalMark #'break-align-symbols = #'(clef)
3427 \key a \major
3428 \clef treble
3429 \mark "↓"
3430 e1
3431 % The rehearsal mark will be centered above the Time Signature
3432 \override Score.RehearsalMark #'break-align-symbols = #'(time-signature)
3433 \key a \major
3434 \clef treble
3435 \time 3/4
3436 \mark "↓"
3437 e2.
3438 % The rehearsal mark will be centered above the Breath Mark
3439 \override Score.RehearsalMark #'break-align-symbols = #'(breathing-sign)
3440 \key a \major
3441 \clef treble
3442 \time 4/4
3443 e1
3444 \breathe
3445 \mark "↓"
3446 @end lilypond
3447
3448 A list of possible target alignment objects may be specified.  If
3449 some of the objects are invisible at that point due to the setting
3450 of @code{break-visibility} or the explicit visibility settings for
3451 keys and clefs, the rehearsal mark or bar number is aligned to the
3452 first object in the list which is visible.  If no objects in the
3453 list are visible the object is aligned to the bar line.  If the bar
3454 line is invisible the object is aligned to the place where the bar
3455 line would be.
3456
3457 @lilypond[verbatim,quote,relative=1]
3458 % The rehearsal mark will be centered above the Key Signature
3459 \override Score.RehearsalMark #'break-align-symbols = #'(key-signature clef)
3460 \key a \major
3461 \clef treble
3462 \mark "↓"
3463 e1
3464 % The rehearsal mark will be centered above the Clef
3465 \set Staff.explicitKeySignatureVisibility = #all-invisible
3466 \override Score.RehearsalMark #'break-align-symbols = #'(key-signature clef)
3467 \key a \major
3468 \clef bass
3469 \mark "↓"
3470 gis,,1
3471 % The rehearsal mark will be centered above the Bar Line
3472 \set Staff.explicitKeySignatureVisibility = #all-invisible
3473 \set Staff.explicitClefVisibility = #all-invisible
3474 \override Score.RehearsalMark #'break-align-symbols = #'(key-signature clef)
3475 \key a \major
3476 \clef treble
3477 \mark "↓"
3478 e''1
3479 @end lilypond
3480
3481 The alignment of the rehearsal mark relative to the notation object
3482 can be changed, as shown in the following example.  In a score with
3483 multiple staves, this setting should be done for all the staves.
3484
3485 @lilypond[verbatim,quote,relative=1]
3486 % The RehearsalMark will be centered above the Key Signature
3487 \override Score.RehearsalMark #'break-align-symbols = #'(key-signature)
3488 \key a \major
3489 \clef treble
3490 \time 4/4
3491 \mark "↓"
3492 e1
3493 % The RehearsalMark will be aligned with the left edge of the Key Signature
3494 \once \override Score.KeySignature #'break-align-anchor-alignment = #LEFT
3495 \mark "↓"
3496 \key a \major
3497 e1
3498 % The RehearsalMark will be aligned with the right edge of the Key Signature
3499 \once \override Score.KeySignature #'break-align-anchor-alignment = #RIGHT
3500 \key a \major
3501 \mark "↓"
3502 e1
3503 @end lilypond
3504
3505 The rehearsal mark can also be offset to the right or left of the left
3506 edge by an arbitrary amount.  The units are staff-spaces:
3507
3508 @lilypond[verbatim,quote,relative=1]
3509 % The RehearsalMark will be aligned with the left edge of the Key Signature
3510 % and then shifted right by 3.5 staff-spaces
3511 \override Score.RehearsalMark #'break-align-symbols = #'(key-signature)
3512 \once \override Score.KeySignature #'break-align-anchor = #3.5
3513 \key a \major
3514 \mark "↓"
3515 e1
3516 % The RehearsalMark will be aligned with the left edge of the Key Signature
3517 % and then shifted left by 2 staff-spaces
3518 \once \override Score.KeySignature #'break-align-anchor = #-2
3519 \key a \major
3520 \mark "↓"
3521 e1
3522 @end lilypond
3523
3524
3525 @node Vertical grouping of grobs
3526 @subsection Vertical grouping of grobs
3527
3528 @c TODO Expand this section
3529
3530 The VerticalAlignment and VerticalAxisGroup grobs work together.
3531 VerticalAxisGroup groups together different grobs like Staff, Lyrics,
3532 etc.  VerticalAlignment then vertically aligns the different grobs
3533 grouped together by VerticalAxisGroup.  There is usually only one
3534 VerticalAlignment per score but every Staff, Lyrics, etc. has its own
3535 VerticalAxisGroup.
3536
3537
3538 @node Modifying stencils
3539 @subsection Modifying stencils
3540
3541 All layout objects have a @code{stencil} property which is part of
3542 the @code{grob-interface}.  By default, this property is usually
3543 set to a function specific to the object that is tailor-made to
3544 render the symbol which represents it in the output.  For example,
3545 the standard setting for the @code{stencil} property of the
3546 @code{MultiMeasureRest} object is @code{ly:multi-measure-rest::print}.
3547
3548 The standard symbol for any object can be replaced by modifying the
3549 @code{stencil} property to reference a different, specially-written,
3550 procedure.  This requires a high level of knowledge of the internal
3551 workings of LilyPond, but there is an easier way which can often
3552 produce adequate results.
3553
3554 This is to set the @code{stencil} property to the procedure which
3555 prints text -- @code{ly:text-interface::print} -- and to add a
3556 @code{text} property to the object which is set to contain the
3557 markup text which produces the required symbol.  Due to the
3558 flexibility of markup, much can be achieved -- see in particular
3559 @ref{Graphic notation inside markup}.
3560
3561 The following example demonstrates this by changing the note head
3562 symbol to a cross within a circle.
3563
3564 @lilypond[verbatim,quote]
3565 XinO = {
3566   \once \override NoteHead  #'stencil = #ly:text-interface::print
3567   \once \override NoteHead #'text = \markup {
3568     \combine
3569       \halign #-0.7 \draw-circle #0.85 #0.2 ##f
3570       \musicglyph #"noteheads.s2cross"
3571   }
3572 }
3573 \relative c'' {
3574   a a \XinO a a
3575 }
3576 @end lilypond
3577
3578 Any of the glyphs in the feta Font can be supplied to the
3579 @code{\musicglyph} markup command -- see @ref{The Feta font}.
3580
3581 @c TODO Add inserting eps files or ref to later
3582
3583 @c TODO Add inserting Postscript or ref to later
3584
3585 @seealso
3586 Notation Reference:
3587 @ref{Graphic notation inside markup},
3588 @ref{Formatting text},
3589 @ref{Text markup commands},
3590 @ref{The Feta font}.
3591
3592
3593 @node Modifying shapes
3594 @subsection Modifying shapes
3595
3596 @menu
3597 * Modifying ties and slurs::
3598 @end menu
3599
3600 @node Modifying ties and slurs
3601 @unnumberedsubsubsec Modifying ties and slurs
3602
3603 @cindex slurs, modifying
3604 @cindex ties, modifying
3605 @cindex Bézier curves, control points
3606 @cindex control points, Bézier curves
3607
3608 Ties, slurs and phrasing slurs are drawn as third-order Bézier
3609 curves.  If the shape of the tie or slur which is calculated
3610 automatically is not optimum, the shape may be modified manually by
3611 explicitly specifying the four control points required to define
3612 a third-order Bézier curve.
3613
3614 Third-order or cubic Bézier curves are defined by four control
3615 points.  The first and fourth control points are precisely the
3616 starting and ending points of the curve.  The intermediate two
3617 control points define the shape.  Animations showing how the curve
3618 is drawn can be found on the web, but the following description
3619 may be helpful.  The curve starts from the first control point
3620 heading directly towards the second, gradually bending over to
3621 head towards the third and continuing to bend over to head towards
3622 the fourth, arriving there travelling directly from the third
3623 control point.  The curve is entirely contained in the
3624 quadrilateral defined by the four control points.
3625
3626 Here is an example of a case where the tie is not optimum, and
3627 where @code{\tieDown} would not help.
3628
3629 @lilypond[verbatim,quote,relative=1]
3630 <<
3631   { e1~ e }
3632 \\
3633   { r4 <g c,> <g c,> <g c,> }
3634 >>
3635 @end lilypond
3636
3637 One way of improving this tie is to manually modify its control
3638 points, as follows.
3639
3640 The coordinates of the Bézier control points are specified in units
3641 of staff-spaces.  The X@tie{}coordinate is relative to the reference
3642 point of the note to which the tie or slur is attached, and the
3643 Y@tie{}coordinate is relative to the staff center line.  The
3644 coordinates are entered as a list of four pairs of decimal numbers
3645 (reals).  One approach is to estimate the coordinates of the two
3646 end points, and then guess the two intermediate points.  The optimum
3647 values are then found by trial and error.
3648
3649 It is useful to remember that a symmetric curve requires symmetric
3650 control points, and that Bézier curves have the useful property that
3651 transformations of the curve such as translation, rotation and
3652 scaling can be achieved by applying the same transformation to the
3653 curve's control points.
3654
3655 For the example above the following override gives a satisfactory
3656 tie.  Note the placement -- it has to be immediately before the note
3657 to which the start of the tie (or slur) is attached.
3658
3659 @lilypond[verbatim,quote,relative=1]
3660 <<
3661   {
3662     \once \override Tie
3663       #'control-points = #'((1 . -1) (3 . 0.6) (12.5 . 0.6) (14.5 . -1))
3664      e1 ~ e
3665   }
3666 \\
3667   { r4 <g c,> <g c,> <g c,> }
3668 >>
3669 @end lilypond
3670
3671 @knownissues
3672 It is not possible to modify shapes of ties or slurs by changing
3673 the @code{control-points} property if there are multiple ties or slurs
3674 at the same musical moment -- the @code{\tweak} command will also not
3675 work in this case.  However, the @code{tie-configuration} property of
3676 @code{TieColumn} can be overridden to set start line and direction as
3677 required.
3678
3679 @seealso
3680 Internals Reference:
3681 @rinternals{TieColumn}.
3682
3683 @cindex Scheme, pure containers
3684 @cindex Scheme, unpure containers
3685 @cindex pure containers, Scheme
3686 @cindex unpure containers, Scheme
3687 @cindex horizontal spacing, overriding
3688
3689
3690 @node Unpure-pure containers
3691 @subsection Unpure-pure containers
3692
3693 Unpure-pure containers are useful for overriding @emph{Y-axis} spacing
3694 calculations - specifically @code{Y-offset} and @code{Y-extent} - with a
3695 Scheme function instead of a literal (i.e. a number or pair).
3696
3697 For certain grobs, the @code{Y-extent} is based on the @code{stencil}
3698 property, overriding the stencil property of one of these will
3699 require an additional @code{Y-extent} override with an unpure-pure
3700 container.  When a function overrides a @code{Y-offset} and/or
3701 @code{Y-extent} it is assumed that this will trigger line breaking
3702 calculations too early during compilation.  So the function is not
3703 evaluated at all (usually returning a value of @samp{0} or
3704 @samp{'(0 . 0)}) which can result in collisions.  A @q{pure} function
3705 will not affect properties, objects or grob suicides and therefore will
3706 always have its Y-axis-related evaluated correctly.
3707
3708 Currently, there are about thirty functions that are already considered
3709 @q{pure} and Unpure-pure containers are a way to set functions not on
3710 this list as @q{pure}.  The @q{pure} function is evaluated @emph{before}
3711 any line-breaking and so the horizontal spacing can be adjusted
3712 @q{in time}.  The @q{unpure} function is then evaluated @emph{after}
3713 line breaking.
3714
3715 @warning{As it is difficult to always know which functions are on this
3716 list we recommend that any @q{pure} functions you create do not use
3717 @code{Beam} or @code{VerticalAlignment} grobs.}
3718
3719 An unpure-pure container is constructed as follows;
3720
3721 @code{(ly:make-unpure-pure-container f0 f1)}
3722
3723 where @code{f0} is a function taking @var{n} arguments (@var{n >= 1})
3724 and the first argument must always be the grob.  This is the function
3725 that gives the actual result.  @var{f1} is the function being labeled
3726 as @q{pure} that takes @var{n + 2} arguments.  Again, the first argument
3727 must always still be the grob but the second and third are @q{start}
3728 and @q{end} arguments.
3729
3730 @var{start} and @var{end} are, for all intents and purposes, dummy
3731 values that only matter for @code{Spanners} (i.e @code{Hairpin} or
3732 @code{Beam}), that can return different height estimations based on a
3733 starting and ending column.
3734
3735 The rest are the other arguments to the first function (which
3736 may be none if @var{n = 1}).
3737
3738 The results of the second function are used as an approximation of the
3739 value needed which is then used by the first function to get the real
3740 value which is then used for fine-tuning much later during the spacing
3741 process.
3742
3743 @lilypond[verbatim,quote,ragged-right]
3744 #(define (square-line-circle-space grob)
3745 (let* ((pitch (ly:event-property (ly:grob-property grob 'cause) 'pitch))
3746       (notename (ly:pitch-notename pitch)))
3747  (if (= 0 (modulo notename 2))
3748      (make-circle-stencil 0.5 0.0 #t)
3749      (make-filled-box-stencil '(0 . 1.0)
3750                               '(-0.5 . 0.5)))))
3751
3752 squareLineCircleSpace = {
3753   \override NoteHead #'stencil = #square-line-circle-space
3754 }
3755
3756 smartSquareLineCircleSpace = {
3757   \squareLineCircleSpace
3758   \override NoteHead #'Y-extent =
3759    #(ly:make-unpure-pure-container
3760       ly:grob::stencil-height
3761       (lambda (grob start end) (ly:grob::stencil-height grob)))
3762 }
3763
3764 \new Voice \with { \remove "Stem_engraver" }
3765 \relative c'' {
3766   \squareLineCircleSpace
3767   cis4 ces cisis c
3768   \smartSquareLineCircleSpace
3769   cis4 ces cisis c
3770 }
3771 @end lilypond
3772
3773 In the first measure, without the unpure-pure container, the spacing
3774 engine does not know the width of the note head and lets it collide with
3775 the accidentals.  In the second measure, with unpure-pure containers,
3776 the spacing engine knows the width of the note heads and avoids the
3777 collision by lengthening the line accordingly.
3778
3779 Usually for simple calculations nearly-identical functions for both the
3780 @q{unpure} and @q{pure} parts can be used, by only changing the number
3781 of arguments passed to, and the scope of, the function.
3782
3783 @warning{If a function is labeled as @q{pure} and it turns out not to
3784 be, the results can be unexpected.}
3785
3786
3787 @node Using music functions
3788 @section Using music functions
3789
3790 @c TODO -- add @seealso, etc. to these subsections
3791
3792 Where tweaks need to be reused with different music expressions,
3793 it is often convenient to make the tweak part of a @emph{music
3794 function}.  In this section, we discuss only @emph{substitution}
3795 functions, where the object is to substitute a variable into a
3796 piece of LilyPond input code.  Other more complex functions are
3797 described in @rextend{Music functions}.
3798
3799 @menu
3800 * Substitution function syntax::
3801 * Substitution function examples::
3802 @end menu
3803
3804 @node Substitution function syntax
3805 @subsection Substitution function syntax
3806
3807 Making a function that substitutes a variable into LilyPond
3808 code is easy.  The general form of these functions is
3809
3810 @example
3811 function =
3812 #(define-music-function
3813      (parser location @var{arg1} @var{arg2} @dots{})
3814      (@var{type1?} @var{type2?} @dots{})
3815    #@{
3816      @var{@dots{}music@dots{}}
3817    #@})
3818 @end example
3819
3820 @noindent
3821 where
3822
3823 @multitable @columnfractions .33 .66
3824 @item @code{@var{argN}}
3825 @tab @var{n}th argument
3826
3827 @item @code{@var{typeN?}}
3828 @tab a scheme @emph{type predicate} for which @code{@var{argN}}
3829 must return @code{#t}.
3830
3831 @item @code{@var{@dots{}music@dots{}}}
3832 @tab normal LilyPond input, using @code{$} (in places where only
3833 Lilypond constructs are allowed) or @code{#} (to use it as a Scheme
3834 value or music function argument) to reference arguments
3835 (eg. @samp{#arg1}).
3836 @end multitable
3837
3838 The @code{parser} and @code{location} arguments are mandatory, and
3839 are used in some advanced situations as described in the
3840 @q{Extending} manual (see @rextend{Music functions}).  For
3841 substitution functions, just be sure to include them.
3842
3843 The list of type predicates is also required.  Some of the most
3844 common type predicates used in music functions are:
3845
3846 @example
3847 boolean?
3848 cheap-list?  @emph{(use instead of }@q{list?}@emph{ for faster processing)}
3849 ly:duration?
3850 ly:music?
3851 ly:pitch?
3852 markup?
3853 number?
3854 pair?
3855 string?
3856 symbol?
3857 @end example
3858
3859 @noindent
3860 For a list of available type predicates, see
3861 @ref{Predefined type predicates}.  User-defined type predicates
3862 are also allowed.
3863
3864 @seealso
3865 Notation Reference:
3866 @ref{Predefined type predicates}.
3867
3868 Extending Lilypond:
3869 @rextend{Music functions}.
3870
3871 Installed Files:
3872 @file{lily/music-scheme.cc},
3873 @file{scm/c++.scm},
3874 @file{scm/lily.scm}.
3875
3876
3877 @node Substitution function examples
3878 @subsection Substitution function examples
3879
3880 This section introduces some substitution function examples.
3881 These are not intended to be exhaustive, but rather to demonstrate
3882 some of the possibilities of simple substitution functions.
3883
3884 In the first example, a function is defined that simplifies
3885 setting the padding of a TextScript:
3886
3887 @lilypond[quote,verbatim,ragged-right]
3888 padText =
3889 #(define-music-function
3890      (parser location padding)
3891      (number?)
3892    #{
3893      \once \override TextScript #'padding = #padding
3894    #})
3895
3896 \relative c''' {
3897   c4^"piu mosso" b a b
3898   \padText #1.8
3899   c4^"piu mosso" d e f
3900   \padText #2.6
3901   c4^"piu mosso" fis a g
3902 }
3903 @end lilypond
3904
3905 In addition to numbers, we can use music expressions such
3906 as notes for arguments to music functions:
3907
3908 @c TODO: use a better example (the music argument is redundant).
3909
3910 @lilypond[quote,verbatim,ragged-right]
3911 custosNote =
3912 #(define-music-function
3913      (parser location note)
3914      (ly:music?)
3915    #{
3916      \once \override Voice.NoteHead #'stencil =
3917        #ly:text-interface::print
3918      \once \override Voice.NoteHead #'text =
3919        \markup \musicglyph #"custodes.mensural.u0"
3920      \once \override Voice.Stem #'stencil = ##f
3921      $note
3922    #})
3923
3924 \relative c' { c4 d e f \custosNote g }
3925 @end lilypond
3926
3927 Substitution functions with multiple arguments can be defined:
3928
3929 @lilypond[quote,verbatim,ragged-right]
3930 tempoPadded =
3931 #(define-music-function
3932      (parser location padding tempotext)
3933      (number? string?)
3934    #{
3935      \once \override Score.MetronomeMark #'padding = #padding
3936      \tempo \markup { \bold #tempotext }
3937    #})
3938
3939 \relative c'' {
3940   \tempo \markup { "Low tempo" }
3941   c4 d e f g1
3942   \tempoPadded #4.0 #"High tempo"
3943   g4 f e d c1
3944 }
3945 @end lilypond
3946
3947 @c TODO: add appropriate @@ref's here.