]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
Hopefully final version. ;-)
[lilypond.git] / Documentation / user / changing-defaults.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Changing defaults
3 @chapter Changing defaults
4
5
6 The purpose of LilyPond's design is to provide the finest output
7 quality as a default.  Nevertheless, it may happen that you need to
8 change this default layout.  The layout is controlled through a large
9 number of proverbial ``knobs and switches.''  This chapter does not
10 list each and every knob.  Rather, it outlines what groups of controls
11 are available and explains how to lookup which knob to use for a
12 particular effect.
13
14
15 @cindex Program reference
16
17 The controls available for tuning are described in a separate
18 document, the
19 @iftex
20 Program reference
21 @end iftex
22 @ifnottex
23 @ref{Top,Program reference,,lilypond-internals}.
24 @end ifnottex
25 manual.  That manual
26 lists all different variables, functions and options available in
27 LilyPond.  It is written as a HTML document, which is available
28 @uref{http://@/lilypond@/.org/@/doc/@/v2.7/@/Documentation/@/user/@/lilypond@/-internals/,on@/-line},
29 but is also included with the LilyPond documentation package.
30
31 There are three areas where the default settings may be changed:
32
33 @itemize @bullet
34 @item
35 Output: changing the appearance of individual
36 objects.  For example, changing stem directions or the location of
37 subscripts.
38   
39 @item
40 Context: changing aspects of the translation from music events to
41 notation.  For example, giving each staff a separate time signature. 
42   
43 @item
44 Global layout: changing the appearance of the spacing, line
45 breaks, and page dimensions.
46 @end itemize
47
48 Then there are separate systems for typesetting text (like
49 @emph{ritardando}) and selecting different fonts.  This chapter also
50 discusses these.
51
52 Internally, LilyPond uses Scheme (a LISP dialect) to provide
53 infrastructure.  Overriding layout decisions in effect accesses the
54 program internals, which requires Scheme input.  Scheme elements are
55 introduced in a @code{.ly} file with the hash mark
56 @code{#}.@footnote{@ref{Scheme tutorial} contains a short tutorial
57 on entering numbers, lists, strings, and symbols in Scheme.}
58
59
60 @menu
61 * Interpretation contexts::     
62 * The \override command::       
63 @end menu
64
65  
66 @node Interpretation contexts
67 @section Interpretation contexts
68
69 When music is printed, a lot of notational elements must be added to the
70 input, which is often bare bones.  For example, compare the input and
71 output of the following example:
72
73 @lilypond[quote,verbatim,relative=2,fragment]
74 cis4 cis2. g4
75 @end lilypond
76
77 The input is rather sparse, but in the output, bar lines, accidentals,
78 clef, and time signature are added.  LilyPond @emph{interprets} the
79 input.  During this step, the musical information is inspected in time
80 order, similar to reading a score from left to right.  While reading,
81 the input, the program remembers where measure boundaries are, and what
82 pitches need explicit accidentals.  This information can be presented on
83 several levels.  For example, the effect of an accidental is limited
84 to a single staff, while a bar line must be synchronized across the
85 entire score.
86
87 Within LilyPond, these rules and bits of information are grouped in
88 so-called Contexts.  Examples of context are @context{Voice},
89 @context{Staff}, and @context{Score}.  They are hierarchical, for
90 example, a @context{Staff} can contain many @context{Voice}s, and a
91 @context{Score} can contain many @context{Staff} contexts.
92
93 Each context has the responsibility for enforcing some notation rules,
94 creating some notation objects and maintaining the associated
95 properties.  So, the synchronization of bar lines is handled at
96 @context{Score} context.  The @context{Voice} may introduce an
97 accidental and then the @context{Staff} context maintains the rule to
98 show or suppress the accidental for the remainder of the measure.
99
100 For simple scores, contexts are created implicitly, and you need not
101 be aware of them.  For larger pieces, such as piano music, they must be
102 created explicitly to make sure that you get as many staves as you
103 need, and that they are in the correct order.  For typesetting pieces
104 with specialized notation, it can be useful to modify existing or
105 to define new contexts.
106
107
108 A complete description of all available contexts is in the program
109 reference, see
110 @ifhtml
111 @internalsref{Contexts}.
112 @end ifhtml
113 @ifnothtml 
114 Translation @arrow{} Context.
115 @end ifnothtml
116
117 @c [TODO: describe propagation]
118
119
120 @menu
121 * Creating contexts::           
122 * Changing context properties on the fly::  
123 * Modifying context plug-ins::  
124 * Layout tunings within contexts::  
125 * Changing context default settings::  
126 * Defining new contexts::       
127 @end menu
128
129 @node Creating contexts
130 @subsection Creating contexts
131
132 For scores with only one voice and one staff, correct contexts are
133 created automatically.  For more complex scores, it is necessary to
134 create them by hand.  There are three commands that do this.
135
136 The easiest command is @code{\new}, and it also the quickest to type.
137 It is prepended to a music expression, for example
138
139 @cindex @code{\new}
140 @cindex new contexts
141 @cindex Context, creating
142
143 @example
144 \new @var{type} @var{music expression}
145 @end example
146
147 @noindent
148 where @var{type} is a context name (like @code{Staff} or
149 @code{Voice}).  This command creates a new context, and starts
150 interpreting the @var{music expression} with that.
151
152 A practical application of @code{\new} is a score with many
153 staves.  Each part that should be on its own staff, is preceded with 
154 @code{\new Staff}.
155
156 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
157 << \new Staff { c4 c }
158    \new Staff { d4 d }
159 >>
160 @end lilypond
161
162 The @code{\new} command may also give a name to the context,
163
164 @example
165 \new @var{type} = @var{id} @var{music}
166 @end example
167 However, this user specified name is only used if there is no other
168 context already earlier with the same name.
169
170 @cindex @code{\context}
171
172 Like @code{\new}, the @code{\context} command also directs a music
173 expression to a context object, but gives the context an explicit name.  The
174 syntax is
175
176 @example
177 \context @var{type} = @var{id} @var{music}
178 @end example
179
180 This form will search for an existing context of type @var{type}
181 called @var{id}.  If that context does not exist yet, the result is
182 identical to @code{\new} @var{type} = @var{id} @var{music}, i.e. 
183 a new context with the specified name is created.
184 This is useful if the context is referred to later on.  For example, when
185 setting lyrics the melody is in a named context
186
187 @example
188 \context Voice = "@b{tenor}" @var{music}
189 @end example
190
191 @noindent
192 so the texts can be properly aligned to its notes,
193
194 @example
195 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics} 
196 @end example
197
198 @noindent
199
200 Another possibility is funneling two different music expressions into
201 one context.  In the following example, articulations and notes are
202 entered separately,
203
204 @example
205 music = @{ c4 c4 @}
206 arts = @{ s4-. s4-> @}
207 @end example
208
209 They are combined by sending both to the same @context{Voice} context,
210
211 @example
212 << \new Staff \context Voice = "A" \music
213    \context Voice = "A" \arts
214 >>
215 @end example
216 @lilypond[quote,ragged-right]
217 music = { c4 c4 }
218 arts = { s4-. s4-> }
219 \relative c'' <<
220   \new Staff \context Voice = "A" \music
221   \context Voice = "A" \arts
222 >>
223 @end lilypond
224
225 With this mechanism, it is possible to define an Urtext (original
226 edition), with the option to put several distinct articulations on the
227 same notes.
228
229 @cindex creating contexts
230
231 The third command for creating contexts is
232 @example
233 \context @var{type} @var{music}
234 @end example
235
236
237 @noindent
238 This is similar to @code{\context} with @code{= @var{id}}, but matches
239 any context of type @var{type}, regardless of its given name.
240
241 This variant is used with music expressions that can be interpreted at
242 several levels.  For example, the @code{\applyOutput} command (see
243 @ref{Running a function on all layout objects}).  Without an explicit
244 @code{\context}, it is usually applied to @context{Voice}
245
246 @example
247 \applyOutput #@var{function}   % apply to Voice
248 @end example
249
250 To have it interpreted at the @context{Score} or @context{Staff} level use
251 these forms
252
253 @example
254 \context Score \applyOutput #@var{function}
255 \context Staff \applyOutput #@var{function}
256 @end example
257
258
259 @node Changing context properties on the fly
260 @subsection Changing context properties on the fly
261
262 @cindex properties
263 @cindex @code{\set}
264 @cindex changing properties
265
266 Each context can have different @emph{properties}, variables contained
267 in that context.  They can be changed during the interpretation step.
268 This is achieved by inserting the @code{\set} command in the music,
269
270 @example
271 \set @var{context}.@var{prop} = #@var{value}
272 @end example
273
274 For example,
275 @lilypond[quote,verbatim,relative=2,fragment]
276 R1*2 
277 \set Score.skipBars = ##t
278 R1*2
279 @end lilypond
280
281 This command skips measures that have no notes.  The result is that
282 multi-rests are condensed.  The value assigned is a Scheme object.  In
283 this case, it is @code{#t}, the boolean True value.
284
285 If the @var{context} argument is left out, then the current bottom-most
286 context (typically @context{ChordNames}, @context{Voice}, or
287 @context{Lyrics}) is used.  In this example,
288
289 @lilypond[quote,verbatim,relative=2,fragment]
290 c8 c c c
291 \set autoBeaming = ##f
292 c8 c c c
293 @end lilypond
294
295 @noindent
296 the @var{context} argument to @code{\set} is left out, so automatic
297 beaming is switched off in the current @internalsref{Voice}.  Note that
298 the bottom-most context does not always contain the property that you
299 wish to change -- for example, attempting to set the @code{skipBars}
300 property (of the bottom-most context, in this case @code{Voice}) will
301 have no effect.
302
303 @lilypond[quote,verbatim,relative=2,fragment]
304 R1*2 
305 \set skipBars = ##t
306 R1*2
307 @end lilypond
308
309 Contexts are hierarchical, so if a bigger context was specified, for
310 example @context{Staff}, then the change would also apply to all
311 @context{Voice}s in the current stave.  The change is applied
312 `on-the-fly', during the music, so that the setting only affects the
313 second group of eighth notes.
314
315 @cindex @code{\unset} 
316
317 There is also an @code{\unset} command,
318 @example
319 \unset @var{context}.@var{prop}
320 @end example
321
322 @noindent
323 which removes the definition of @var{prop}.  This command removes
324 the definition only if it is set in @var{context}, so
325
326 @example
327 \set Staff.autoBeaming = ##f
328 @end example
329
330 @noindent
331 introduces a property setting at @code{Staff} level.  The setting also
332 applies to the current @code{Voice}.  However,
333
334 @example
335 \unset Voice.autoBeaming
336 @end example
337
338 @noindent
339 does not have any effect.  To cancel this setting, the @code{\unset}
340 must be specified on the same level as the original @code{\set}.  In
341 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
342 requires
343 @example
344 \unset Staff.autoBeaming
345 @end example
346
347 Like @code{\set}, the @var{context} argument does not have to be
348 specified for a bottom context, so the two statements
349
350 @example
351 \set Voice.autoBeaming = ##t 
352 \set autoBeaming = ##t 
353 @end example 
354
355 @noindent
356 are equivalent.
357
358
359 @cindex \once
360 Settings that should only apply to a single time-step can be entered
361 with @code{\once}, for example in
362
363 @lilypond[quote,verbatim,relative=2,fragment]
364 c4
365 \once \set fontSize = #4.7
366 c4
367 c4
368 @end lilypond
369
370 the property @code{fontSize} is unset automatically after the second
371 note.
372
373 A full description of all available context properties is in the
374 program reference, see
375 @ifhtml
376 @internalsref{Tunable context properties}.
377 @end ifhtml
378 @ifnothtml
379 Translation @arrow{} Tunable context properties.
380 @end ifnothtml
381
382
383 @node Modifying context plug-ins
384 @subsection Modifying context plug-ins
385
386 Notation contexts (like Score and Staff) not only store properties,
387 they also contain plug-ins, called ``engravers'' that create notation
388 elements.  For example, the Voice context contains a
389 @code{Note_head_engraver} and the Staff context contains a
390 @code{Key_signature_engraver}.
391
392 For a full a description of each plug-in, see 
393 @ifhtml
394 @internalsref{Engravers}.
395 @end ifhtml
396 @ifnothtml
397 Program reference @arrow Translation @arrow{} Engravers.
398 @end ifnothtml
399 Every context described in
400 @ifhtml
401 @internalsref{Contexts}
402 @end ifhtml
403 @ifnothtml 
404 Program reference @arrow Translation @arrow{} Context.
405 @end ifnothtml
406 lists the engravers used for that context.
407
408
409 It can be useful to shuffle around these plug-ins.  This is done by
410 starting a new context, with @code{\new} or @code{\context}, and
411 modifying it like this, 
412
413 @cindex @code{\with}
414
415 @example
416 \new @var{context} \with @{
417   \consists @dots{}
418   \consists @dots{}
419   \remove @dots{}
420   \remove @dots{}
421   @emph{etc.}
422 @}
423 @emph{..music..}
424 @end example
425
426 @noindent
427 where the @dots{} should be the name of an engraver.  Here is a simple
428 example which removes @code{Time_signature_engraver} and
429 @code{Clef_engraver} from a @code{Staff} context,
430
431 @lilypond[quote,relative=1,verbatim,fragment]
432 << \new Staff {
433     f2 g
434   }
435   \new Staff \with {
436      \remove "Time_signature_engraver"
437      \remove "Clef_engraver"
438   } {
439     f2 g2
440   }
441 >>
442 @end lilypond
443
444 In the second staff there are no time signature or clef symbols.  This
445 is a rather crude method of making objects disappear since it will affect
446 the entire staff.  The spacing is adversely influenced too.  A more
447 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
448
449 The next example shows a practical application.  Bar lines and time
450 signatures are normally synchronized across the score.  This is done
451 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
452 This plug-in keeps an administration of time signature, location
453 within the measure, etc.  By moving thes engraver from @code{Score} to
454 @code{Staff} context, we can have a score where each staff has its own
455 time signature.
456
457 @cindex polymetric scores
458 @cindex Time signatures, multiple
459
460 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
461 \new Score \with {
462   \remove "Timing_translator"
463   \remove "Default_bar_line_engraver"
464 } <<
465   \new Staff \with {
466     \consists "Timing_translator"
467     \consists "Default_bar_line_engraver"
468   } {
469       \time 3/4
470       c4 c c c c c
471   }
472   \new Staff \with {
473     \consists "Timing_translator"
474     \consists "Default_bar_line_engraver"
475   } {
476        \time 2/4
477        c4 c c c c c
478   }
479 >>
480 @end lilypond
481
482
483 @node Layout tunings within contexts
484 @subsection Layout tunings within contexts
485
486 Each context is responsible for creating certain types of graphical
487 objects.  The settings used for printing these objects are also stored by
488 context.  By changing these settings, the appearance of objects can be
489 altered.
490  
491 The syntax for this is
492
493 @example
494 \override @var{context}.@var{name} #'@var{property} = #@var{value}
495 @end example
496
497 Here @var{name} is the name of a graphical object, like @code{Stem} or
498 @code{NoteHead}, and @var{property} is an internal variable of the
499 formatting system (`grob property' or `layout property').  The latter is a
500 symbol, so it must be quoted.  The subsection @ref{Constructing a
501 tweak} explains what to fill in for @var{name}, @var{property}, and
502 @var{value}.  Here we only discuss the functionality of this command.
503
504 The command
505
506 @verbatim
507 \override Staff.Stem #'thickness = #4.0 
508 @end verbatim
509
510 @noindent
511 makes stems thicker (the default is 1.3, with staff line thickness as a
512 unit).  Since the command specifies @context{Staff} as context, it only
513 applies to the current staff.  Other staves will keep their normal
514 appearance.  Here we see the command in action:
515
516 @lilypond[quote,verbatim,relative=2,fragment]
517 c4
518 \override Staff.Stem #'thickness = #4.0 
519 c4
520 c4
521 c4
522 @end lilypond
523
524 The @code{\override} command changes the definition of the @code{Stem}
525 within the current @context{Staff}.  After the command is interpreted
526 all stems are thickened.
527
528 Analogous to @code{\set}, the @var{context} argument may be left out,
529 causing it to default to @context{Voice}, and adding @code{\once} applies
530 the change during one timestep only 
531
532 @lilypond[quote,fragment,verbatim,relative=2]
533 c4
534 \once \override Stem #'thickness = #4.0 
535 c4
536 c4 
537 @end lilypond
538
539 The @code{\override} must be done before the object is
540 started.  Therefore, when altering @emph{Spanner} objects, like slurs or
541 beams, the @code{\override} command must be executed at the moment when
542 the object is created.  In this example,
543
544
545 @lilypond[quote,fragment,verbatim,relative=2]
546 \override Slur #'thickness = #3.0
547 c8[( c
548 \override Beam #'thickness = #0.6
549 c8 c]) 
550 @end lilypond
551
552 @noindent
553 the slur is fatter but the beam is not.  This is because the command for
554 @code{Beam} comes after the Beam is started.  Therefore it has no effect.
555
556 Analogous to @code{\unset}, the @code{\revert} command for a context
557 undoes an @code{\override} command; like with @code{\unset}, it only
558 affects settings that were made in the same context.  In other words, the
559 @code{\revert} in the next example does not do anything.
560
561 @example
562 \override Voice.Stem #'thickness = #4.0
563 \revert Staff.Stem #'thickness
564 @end example
565
566 Some tweakable options are called ``subproperties'' and reside inside
567 properties.  To tweak those, use
568
569 @example
570 \override Stem #'details #'beamed-lengths = #'(4 4 3) 
571 @end example
572
573
574 @seealso
575
576 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
577 @internalsref{PropertySet}, @internalsref{Backend}, and
578 @internalsref{All layout objects}.
579
580
581 @refbugs
582
583 The back-end is not very strict in type-checking object properties.
584 Cyclic references in Scheme values for properties can cause hangs
585 or crashes, or both.
586
587
588 @node Changing context default settings
589 @subsection Changing context default settings
590
591 The adjustments of the previous subsections (@ref{Changing context
592 properties on the fly}, @ref{Modifying context plug-ins}, and
593 @ref{Layout tunings within contexts}) can also be entered separately
594 from the music, in the @code{\layout} block,
595
596 @example
597 \layout @{
598   @dots{}
599   \context @{
600     \Staff
601
602     \set fontSize = #-2
603     \override Stem #'thickness = #4.0
604     \remove "Time_signature_engraver"
605   @}
606 @}
607 @end example
608
609 Here
610 @example
611 \Staff
612 @end example
613
614 @noindent
615 takes the existing definition for context @context{Staff} from the
616 identifier @code{\Staff}. 
617
618 The statements
619 @example
620 \set fontSize = #-2
621 \override Stem #'thickness = #4.0
622 \remove "Time_signature_engraver"
623 @end example
624
625 @noindent
626 affect all staves in the score.
627
628 Other contexts can be modified analogously.
629
630 The @code{\set} keyword is optional within the @code{\layout} block, so
631
632 @example
633 \context @{
634   @dots{}
635   fontSize = #-2
636 @}
637 @end example
638
639 @noindent
640 will also work.
641
642
643
644 @refbugs
645
646 It is not possible to collect context changes in a variable, and apply
647 them to one @code{\context} definition by referring to that variable.
648
649 The @code{\RemoveEmptyStaffContext} will override your current
650 @code{\Staff} variable.  If you wish to change the defaults for a
651 staff that uses @code{\RemoveEmptyStaffContext}, you must do so
652 after calling @code{\RemoveemptyStaffContext}, ie
653
654 @example
655 \layout @{
656   \context @{
657     \RemoveEmptyStaffContext
658
659     \override Stem #'thickness = #4.0
660   @}
661 @}
662 @end example
663
664
665 @node Defining new contexts
666 @subsection Defining new contexts
667
668 Specific contexts, like @context{Staff} and @code{Voice}, are made of
669 simple building blocks, and it is possible to compose engraver
670 plug-ins in different combinations, thereby creating new types of
671 contexts.
672
673 The next example shows how to build a different type of
674 @context{Voice} context from scratch.  It will be similar to
675 @code{Voice}, but prints centered slash noteheads only.  It can be used
676 to indicate improvisation in Jazz pieces,
677
678 @lilypond[quote,ragged-right]
679 \layout { \context {
680   \name ImproVoice
681   \type "Engraver_group"
682   \consists "Note_heads_engraver"
683   \consists "Text_engraver"
684   \consists Pitch_squash_engraver
685   squashedPosition = #0
686   \override NoteHead #'style = #'slash
687   \override Stem #'transparent = ##t
688   \alias Voice
689 }
690 \context { \Staff
691   \accepts "ImproVoice"
692 }}
693
694 \relative c'' {
695   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c 
696    c4 c^"undress" c_"while playing :)" c } 
697   a1 
698 }
699 @end lilypond
700
701
702 These settings are again done within a @code{\context} block inside a
703 @code{\layout} block,
704
705 @example
706 \layout @{
707   \context @{
708     @dots{}
709   @}
710 @}
711 @end example
712
713 In the following discussion, the example input shown should go on the
714 @dots{} in the previous fragment.
715
716 First, the context gets a name.  Instead of @context{Voice} it
717 will be called @context{ImproVoice},
718
719 @example
720 \name ImproVoice
721 @end example
722
723 Since it is similar to the @context{Voice}, we want commands that work
724 on (existing) @context{Voice}s to remain working.  This is achieved by
725 giving the new context an alias @context{Voice},
726
727 @example
728 \alias Voice
729 @end example
730
731 The context will print notes, and instructive texts
732
733 @example
734 \consists Note_heads_engraver
735 \consists Text_engraver
736 @end example
737
738 but only on the center line,
739
740 @example
741 \consists Pitch_squash_engraver
742 squashedPosition = #0
743 @end example
744
745 The @internalsref{Pitch_squash_engraver} modifies note heads (created
746 by @internalsref{Note_heads_engraver}) and sets their vertical
747 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
748 the center line.
749
750 The notes look like a slash, without a stem,
751
752 @example
753 \override NoteHead #'style = #'slash
754 \override Stem #'transparent = ##t
755 @end example
756
757
758 All these plug-ins have to cooperate, and this is achieved with a
759 special plug-in, which must be marked with the keyword @code{\type}.
760 This should always be @internalsref{Engraver_group},
761
762 @example
763 \type "Engraver_group"
764 @end example
765
766 Put together, we get
767
768 @example
769 \context @{
770   \name ImproVoice
771   \type "Engraver_group"
772   \consists "Note_heads_engraver"
773   \consists "Text_engraver"
774   \consists Pitch_squash_engraver
775   squashedPosition = #0
776   \override NoteHead #'style = #'slash
777   \override Stem #'transparent = ##t
778   \alias Voice
779 @}
780 @end example
781
782 Contexts form hierarchies.  We want to hang the @context{ImproVoice}
783 under @context{Staff}, just like normal @code{Voice}s.  Therefore, we
784 modify the @code{Staff} definition with the @code{\accepts}
785 command,@footnote{The opposite of @code{\accepts} is @code{\denies},
786 which is sometimes needed when reusing existing context definitions.}
787
788
789
790 @example
791 \context @{
792   \Staff
793   \accepts ImproVoice    
794 @}
795 @end example
796
797 Putting both into a @code{\layout} block, like
798
799 @example
800 \layout @{
801   \context @{
802     \name ImproVoice
803     @dots{}
804   @}
805   \context @{
806     \Staff
807     \accepts "ImproVoice"
808   @}
809 @}
810 @end example
811
812 Then the output at the start of this subsection can be entered as
813
814 @example
815 \relative c'' @{
816   a4 d8 bes8
817   \new ImproVoice @{
818     c4^"ad lib" c 
819     c4 c^"undress"
820     c c_"while playing :)"
821   @}
822   a1
823 @}
824 @end example
825   
826
827     
828
829 @node The \override command
830 @section The \override command
831
832 In the previous section, we have already touched on a command that
833 changes layout details: the @code{\override} command.  In this section,
834 we will look in more detail at how to use the command in practice.
835 First, we will give a few versatile commands that are sufficient
836 for many situations.  The next section will discuss the general use of
837 @code{\override}.
838
839
840 @menu
841 * Constructing a tweak::        
842 * Navigating the program reference::  
843 * Layout interfaces::           
844 * Determining the grob property::  
845 * Objects connected to the input::  
846 * Difficult tweaks::            
847 @end menu
848
849
850
851 @node Constructing a tweak
852 @subsection Constructing a tweak
853
854 The general procedure of changing output, that is, entering
855 a command like
856
857 @example
858 \override Voice.Stem #'thickness = #3.0
859 @end example
860
861 @noindent
862 means that we have to determine these bits of information:
863
864 @itemize
865 @item the context: here @context{Voice}.
866 @item the layout object: here @code{Stem}.
867 @item the layout property: here @code{thickness}
868 @item a sensible value: here @code{3.0}
869 @end itemize  
870
871
872 @cindex internal documentation
873 @cindex finding graphical objects
874 @cindex graphical object descriptions 
875 @cindex tweaking
876 @cindex @code{\override}
877 @cindex internal documentation
878
879 We demonstrate how to glean this information from the notation manual
880 and the program reference.
881
882 @node Navigating the program reference
883 @subsection Navigating the program reference
884
885 Suppose we want to move the fingering indication in the fragment
886 below:
887
888 @lilypond[quote,fragment,relative=2,verbatim]
889 c-2
890 \stemUp
891 f
892 @end lilypond
893
894 If you visit the documentation on fingering instructions (in
895 @ref{Fingering instructions}), you will notice that there is written:
896
897 @quotation
898 @seealso
899
900 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
901
902 @end quotation
903
904
905
906 This fragment points to two parts of the program reference: a page
907 on @code{FingerEvent} and one on @code{Fingering}.
908
909 The page on @code{FingerEvent} describes the properties of the music
910 expression for the input @code{-2}.  The page contains many links
911 forward.  For example, it says
912
913 @quotation
914 Accepted by: @internalsref{Fingering_engraver},
915 @end quotation 
916
917 @noindent
918 That link brings us to the documentation for the Engraver, the
919 plug-in, which says
920
921 @quotation
922 This engraver creates the following layout objects: @internalsref{Fingering}.
923 @end quotation
924
925 In other words, once the @code{FingerEvent}s are interpreted, the
926 @code{Fingering_engraver} plug-in will process them.
927
928 @ignore
929 @c  I can't figure out what this is supposed to mean.  -gp
930
931 The @code{Fingering_engraver} is also listed to create
932 @internalsref{Fingering} objects,
933
934 @c  old info?  it doesn't make any sense to me with our current docs.
935 This is also the
936 second bit of information listed under @b{See also} in the Notation
937 manual.
938 @end ignore
939
940 By clicking around in the program reference, we can follow the
941 flow of information within the program, either forward (like we did
942 here), or backwards, following links like this:
943
944 @itemize @bullet
945
946 @item @internalsref{Fingering}:
947 @internalsref{Fingering} objects are created by:
948 @b{@internalsref{Fingering_engraver}}
949
950 @item @internalsref{Fingering_engraver}:
951 Music types accepted: @b{@internalsref{fingering-event}}
952
953 @item @internalsref{fingering-event}:
954 Music event type @code{fingering-event} is in Music expressions named
955 @b{@internalsref{FingerEvent}}
956 @end itemize
957
958 This path goes against the flow of information in the program: it
959 starts from the output, and ends at the input event.
960
961 The program reference can also be browsed like a normal document.  It
962 contains a chapter on
963 @ifhtml
964 @internalsref{Music definitions},
965 @end ifhtml
966 @ifnothtml
967 @code{Music definitions}
968 @end ifnothtml
969 on @internalsref{Translation}, and the @internalsref{Backend}.  Every
970 chapter lists all the definitions used, and all properties that may be
971 tuned.
972
973  
974 @node Layout interfaces
975 @subsection Layout interfaces
976
977 @cindex interface, layout
978 @cindex layout interface
979 @cindex grob
980
981 The HTML page that we found in the previous section, describes the
982 layout object called @internalsref{Fingering}.  Such an object is a
983 symbol within the score.  It has properties that store numbers (like
984 thicknesses and directions), but also pointers to related objects.  A
985 layout object is also called a @emph{Grob}, which is short for Graphical
986 Object.  For more details about Grobs, see @internalsref{grob-interface}.
987
988 The page for @code{Fingering} lists the definitions for the
989 @code{Fingering} object.  For example, the page says
990
991 @quotation
992 @code{padding} (dimension, in staff space):
993   
994 @code{0.6}
995 @end quotation
996
997 @noindent
998 which means that the number will be kept at a distance of at least 0.6
999 of the note head.
1000
1001
1002 Each layout object may have several functions as a notational or
1003 typographical element.  For example, the Fingering object
1004 has the following aspects
1005
1006 @itemize @bullet
1007 @item
1008 Its size is independent of the horizontal spacing, unlike slurs or beams.
1009
1010 @item
1011 It is a piece of text.  Granted, it is usually a very short text.
1012
1013 @item
1014 That piece of text is typeset with a font, unlike slurs or beams.
1015
1016 @item
1017 Horizontally, the center of the symbol should be aligned to the
1018 center of the notehead.
1019
1020 @item
1021 Vertically, the symbol is placed next to the note and the staff.
1022
1023 @item
1024 The vertical position is also coordinated with other super- and subscript
1025 symbols.
1026 @end itemize
1027
1028 Each of these aspects is captured in so-called @emph{interface}s,
1029 which are listed on the @internalsref{Fingering} page at the bottom
1030
1031 @quotation
1032 This object supports the following interfaces:
1033 @internalsref{item-interface},
1034 @internalsref{self-alignment-interface},
1035 @internalsref{side-position-interface}, @internalsref{text-interface},
1036 @internalsref{text-script-interface}, @internalsref{font-interface},
1037 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1038 @end quotation
1039
1040 Clicking any of the links will take you to the page of the respective
1041 object interface.  Each interface has a number of properties.  Some of
1042 them are not user-serviceable (``Internal properties''), but others
1043 are.
1044
1045 We have been talking of @emph{the} @code{Fingering} object, but actually it
1046 does not amount to much.  The initialization file
1047 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1048
1049 @example
1050 (Fingering
1051   . ((padding . 0.5)
1052      (avoid-slur . around)
1053      (slur-padding . 0.2)
1054      (staff-padding . 0.5)
1055      (self-alignment-X . 0)
1056      (self-alignment-Y . 0)
1057      (script-priority . 100)
1058      (stencil . ,ly:text-interface::print)
1059      (direction . ,ly:script-interface::calc-direction)
1060      (font-encoding . fetaNumber)
1061      (font-size . -5)           ; don't overlap when next to heads.
1062      (meta . ((class . Item)
1063      (interfaces . (finger-interface
1064                     font-interface
1065                     text-script-interface
1066                     text-interface
1067                     side-position-interface
1068                     self-alignment-interface
1069                     item-interface))))))
1070 @end example
1071
1072 @noindent
1073 As you can see, the @code{Fingering} object is nothing more than a
1074 bunch of variable settings, and the webpage in the Program Reference
1075 is directly generated from this definition.
1076
1077 @node Determining the grob property
1078 @subsection Determining the grob property
1079
1080
1081 Recall that we wanted to change the position of the @b{2} in 
1082
1083 @lilypond[quote,fragment,relative=2,verbatim]
1084 c-2
1085 \stemUp
1086 f
1087 @end lilypond
1088
1089 Since the @b{2} is vertically positioned next to its note, we have to
1090 meddle with the interface associated with this positioning.  This is
1091 done using @code{side-position-interface}.  The page for this interface 
1092 says
1093
1094 @quotation
1095 @code{side-position-interface}
1096
1097 Position a victim object (this one) next to other objects (the
1098 support).  The property @code{direction} signifies where to put the
1099 victim object relative to the support (left or right, up or down?)
1100 @end quotation
1101
1102 @cindex padding
1103 @noindent
1104 below this description, the variable @code{padding} is described as
1105
1106 @quotation
1107 @table @code
1108 @item padding
1109 (dimension, in staff space)
1110
1111 Add this much extra space between objects that are next to each other. 
1112 @end table
1113 @end quotation
1114
1115 By increasing the value of @code{padding}, we can move away the
1116 fingering.  The following command inserts 3 staff spaces of white
1117 between the note and the fingering:
1118 @example
1119 \once \override Voice.Fingering #'padding = #3
1120 @end example
1121
1122 Inserting this command before the Fingering object is created,
1123 i.e., before @code{c2}, yields the following result:
1124
1125 @lilypond[quote,relative=2,fragment,verbatim]
1126 \once \override Voice.Fingering #'padding = #3
1127 c-2
1128 \stemUp
1129 f
1130 @end lilypond
1131
1132
1133 In this case, the context for this tweak is @context{Voice}.  This
1134 fact can also be deduced from the program reference, for the page for
1135 the @internalsref{Fingering_engraver} plug-in says
1136
1137 @quotation
1138 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1139 @end quotation
1140
1141 @node Objects connected to the input
1142 @subsection Objects connected to the input
1143
1144 In some cases, it is possible to take a short-cut for tuning graphical
1145 objects. For objects that result directly from a piece of the input,
1146 you can use the @code{\tweak} function, for example
1147
1148 @lilypond[relative=2,fragment,verbatim,ragged-right]
1149 <
1150   c
1151   \tweak #'color #red d
1152   g
1153   \tweak #'duration-log #1  a
1154 >4-\tweak #'padding #10 -. 
1155 @end lilypond
1156
1157 As you can see, properties are set directly in the objects directly,
1158 without mentioning the grob name or context where this should be
1159 applied.
1160
1161 This technique only works for objects that are directly connected to
1162 an @internalsref{event} from the input, for example
1163
1164 @itemize @bullet
1165 @item note heads, caused by chord-pitch.
1166 @item articulation signs, caused by articulation instructions
1167 @end itemize
1168
1169 It notably does not work for stems and accidentals (these are caused
1170 by note heads, not by music events) or clefs (these are not caused by
1171 music inputs, but rather by the change of a property value).
1172  
1173
1174 @node Difficult tweaks
1175 @subsection Difficult tweaks
1176
1177 There are a few classes of difficult adjustments.  
1178
1179 @itemize @bullet
1180
1181
1182 @item
1183 One type of difficult adjustment is the appearance of spanner objects,
1184 such as slur and tie.  Initially, only one of these objects is created,
1185 and they can be adjusted with the normal mechanism.  However, in some
1186 cases the spanners cross line breaks.  If this happens, these objects
1187 are cloned.  A separate object is created for every system that it is
1188 in.  These are clones of the original object and inherit all
1189 properties, including @code{\override}s.
1190
1191
1192 In other words, an @code{\override} always affects all pieces of a
1193 broken spanner.  To change only one part of a spanner at a line break,
1194 it is necessary to hook into the formatting process.  The
1195 @code{after-line-breaking} callback contains the Scheme procedure that
1196 is called after the line breaks have been determined, and layout
1197 objects have been split over different systems.
1198
1199 In the following example, we define a procedure
1200 @code{my-callback}.  This procedure
1201  
1202 @itemize @bullet
1203 @item
1204 determines if we have been split across line breaks
1205 @item
1206 if yes, retrieves all the split objects
1207 @item
1208 checks if we are the last of the split objects
1209 @item
1210 if yes, it sets @code{extra-offset}.
1211 @end itemize
1212
1213 This procedure is installed into @internalsref{Tie}, so the last part
1214 of the broken tie is translated up.
1215
1216 @lilypond[quote,verbatim,ragged-right]
1217 #(define (my-callback grob)
1218   (let* (
1219          ; have we been split? 
1220          (orig (ly:grob-original grob))
1221
1222          ; if yes, get the split pieces (our siblings)
1223          (siblings (if (ly:grob? orig)
1224                      (ly:spanner-broken-into orig) '() )))
1225
1226    (if (and (>= (length siblings) 2)
1227              (eq? (car (last-pair siblings)) grob))
1228      (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1229
1230 \relative c'' { 
1231   \override Tie #'after-line-breaking =
1232   #my-callback
1233   c1 ~ \break c2 ~ c
1234 }
1235 @end lilypond
1236
1237 @noindent
1238 When applying this trick, the new @code{after-line-breaking} callback
1239 should also call the old one @code{after-line-breaking}, if there is
1240 one.  For example, if using this with @code{Hairpin},
1241 @code{ly:hairpin::after-line-breaking} should also be called.
1242
1243
1244 @item Some objects cannot be changed with @code{\override} for
1245 technical reasons. Examples of those are @code{NonMusicalPaperColumn}
1246 and @code{PaperColumn}.  They can be changed with the
1247 @code{\outputProperty} function, which works similar to @code{\once
1248 \override}, but uses a different syntax,
1249
1250 @example 
1251 \outputProperty
1252 #"Score.NonMusicalPaperColumn"  % Grob name
1253 #'line-break-system-details     % Property name  
1254 #'((next-padding . 20))         % Value
1255 @end example
1256
1257 @end itemize