]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
More accidental stuff from Valentin.
[lilypond.git] / Documentation / user / changing-defaults.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
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.  See TRANSLATION for details.
8 @end ignore
9
10 @node Changing defaults
11 @chapter Changing defaults
12
13
14 The purpose of LilyPond's design is to provide the finest output
15 quality as a default.  Nevertheless, it may happen that you need to
16 change this default layout.  The layout is controlled through a large
17 number of proverbial @q{knobs and switches.}  This chapter does not
18 list each and every knob.  Rather, it outlines what groups of controls
19 are available and explains how to lookup which knob to use for a
20 particular effect.
21
22
23 @cindex Program reference
24
25 The controls available for tuning are described in a separate
26 document, the
27 @iftex
28 Program reference manual.
29 @end iftex
30 @ifnottex
31 @ref{Top,Program reference,,lilypond-internals}.
32 @end ifnottex
33 That manual
34 lists all different variables, functions and options available in
35 LilyPond.  It is written as a HTML document, which is available
36 @c leave the @uref as one long line.
37 @uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/user/@/lilypond@/-internals/,on@/-line},
38 but is also included with the LilyPond documentation package.
39
40 There are four areas where the default settings may be changed:
41
42 @itemize @bullet
43 @item
44 Automatic notation: changing the automatic creation of notation
45 elements.  For example, changing the beaming rules.
46
47 @item
48 Output: changing the appearance of individual
49 objects.  For example, changing stem directions or the location of
50 subscripts.
51
52 @item
53 Context: changing aspects of the translation from music events to
54 notation.  For example, giving each staff a separate time signature.
55
56 @item
57 Page layout: changing the appearance of the spacing, line
58 breaks, and page dimensions.  These modifications are discussed
59 in @ref{Non-musical notation}, and @ref{Spacing issues}.
60 @end itemize
61
62 Internally, LilyPond uses Scheme (a LISP dialect) to provide
63 infrastructure.  Overriding layout decisions in effect accesses the
64 program internals, which requires Scheme input.  Scheme elements are
65 introduced in a @code{.ly} file with the hash mark
66 @code{#}.@footnote{@ref{Scheme tutorial}, contains a short tutorial
67 on entering numbers, lists, strings, and symbols in Scheme.}
68
69
70 @menu
71 * Automatic notation::          
72 * Interpretation contexts::     
73 * The \override command::       
74 @end menu
75
76
77 @node Automatic notation
78 @section Automatic notation
79
80 This section describes how to change the way that accidentals and
81 beams are automatically displayed.
82
83 @menu
84 * Automatic accidentals::       
85 * Setting automatic beam behavior::  
86 @end menu
87
88 @node Automatic accidentals
89 @subsection Automatic accidentals
90 @cindex Automatic accidentals
91
92 Common rules for typesetting accidentals have been placed in a
93 function.  This function is called as follows
94
95 @funindex set-accidental-style
96 @example
97 #(set-accidental-style 'STYLE)
98 @end example
99
100 @c TODO: check the context stuff below
101 @c -does it *really* work?
102 @c -the default contexts as specified in
103 @c  scm/music-function.scm seem to be different -vv
104
105 Optionally, the function can take two arguments: the name of the
106 accidental style, and an optional argument that denotes the context that
107 should be changed:
108
109 @example
110 #(set-accidental-style 'STYLE #('CONTEXT#))
111 @end example
112
113 If no context name is supplied, @code{Staff} is the default,
114 but you may wish to apply the accidental style to a single @code{Voice}
115 instead.
116
117 The following accidental styles are supported:
118
119 @table @code
120 @item default
121 This is the default typesetting behavior.  It corresponds
122 to 18th century common practice: Accidentals are
123 remembered to the end of the measure in which they occur and
124 only on their own octave.
125
126 @lilypond[quote,ragged-right]
127 musicA = {  << \relative {  cis'8 fis, d'4 <a cis>8 f bis4 | cis2. <c, g'>4 | } \\
128        \relative { ais'2 cis, | fis8 b a4 cis2 | } >> }
129
130 musicB = { \clef bass  \new Voice { \voiceTwo \relative { < fis, a cis>4 
131         \change Staff = up cis' \change Staff = down <fis, a>  
132         \change Staff = up dis' | \change Staff = down <fis, a cis>4 gis 
133         <f a d>2 |  } }}
134
135 \score { 
136         \new PianoStaff {
137        << \context Staff = "up" {
138                %#(set-accidental-style 'default) 
139        \musicA }
140        \context Staff = "down"{
141                %#(set-accidental-style 'default)
142        \musicB } >> }
143        \header { piece = \markup {\fill-line { \fontsize #3  "'default" }}}
144 }
145 @end lilypond
146
147 @item voice
148 The normal behavior is to remember the accidentals on
149 Staff-level.  This variable, however, typesets accidentals
150 individually for each voice.  Apart from that, the rule is similar to
151 @code{default}.
152
153 @example
154  \new Staff <<
155         #(set-accidental-style 'voice)
156         @{ @dots{} @}
157         >>
158 @end example
159
160 As a result, accidentals from one voice do not get canceled in other
161 voices, which is often an unwanted result: in the following example, it
162 is hard to determine whether the second @samp{a} should be played
163 natural or sharp.
164
165 @lilypond[quote,ragged-right]
166 musicA = {  << \relative {  cis'8 fis, d'4 <a cis>8 f bis4 | cis2. <c, g'>4 | } \\
167        \relative { ais'2 cis, | fis8 b a4 cis2 | } >> }
168
169 musicB = { \clef bass  \new Voice { \voiceTwo \relative { < fis, a cis>4 
170         \change Staff = up cis' \change Staff = down <fis, a>  
171         \change Staff = up dis' | \change Staff = down <fis, a cis>4 gis 
172         <f a d>2 |  } }}
173
174 \score { 
175         \new PianoStaff {
176        << \context Staff = "up" {
177                #(set-accidental-style 'voice) 
178        \musicA }
179        \context Staff = "down"{
180                #(set-accidental-style 'voice)
181        \musicB } >> }
182        \header { piece = \markup {\fill-line { \fontsize #3  "'voice" }}}
183 }
184 @end lilypond
185
186 The @code{voice} option should be used if the voices
187 are to be read solely by individual musicians.  If the staff is to be
188 used by one musician (e.g., a conductor) then
189 @code{modern} or @code{modern-cautionary}
190 should be used instead.
191
192 @item modern
193 @funindex modern style accidentals
194 This rule corresponds to the common practice in the 20th century.  This rule
195 prints the same accidentals as @code{default}, but temporary
196 accidentals also are canceled in other octaves.  Furthermore,
197 in the same octave, they also get canceled in the following
198 measure: in the following example, notice the two natural signs which appear
199 in the second bar of the upper staff.
200
201 @lilypond[quote,ragged-right]
202 musicA = {  << \relative {  cis'8 fis, d'4 <a cis>8 f bis4 | cis2. <c, g'>4 | } \\
203        \relative { ais'2 cis, | fis8 b a4 cis2 | } >> }
204
205 musicB = { \clef bass  \new Voice { \voiceTwo \relative { < fis, a cis>4 
206         \change Staff = up cis' \change Staff = down <fis, a>  
207         \change Staff = up dis' | \change Staff = down <fis, a cis>4 gis 
208         <f a d>2 |  } }}
209
210 \score { 
211         \new PianoStaff {
212        << \context Staff = "up" {
213                #(set-accidental-style 'modern) 
214        \musicA }
215        \context Staff = "down"{
216                #(set-accidental-style 'modern)
217        \musicB } >> }
218        \header { piece = \markup {\fill-line { \fontsize #3  "'modern" }}}
219 }
220 @end lilypond
221
222 @item @code{modern-cautionary}
223 @funindex modern-cautionary
224 This rule is similar to @code{modern}, but the @q{extra} accidentals
225 (the ones not typeset by @code{default}) are typeset as cautionary
226 accidentals.  They are printed in reduced size or (by default)
227 with parentheses -- this can be set by definig the @code{cautionary-style}
228 property of the @internalsref{AccidentalSuggestion} object.
229
230 @lilypond[quote,ragged-right]
231 musicA = {  << \relative {  cis'8 fis, d'4 <a cis>8 f bis4 | cis2. <c, g'>4 | } \\
232        \relative { ais'2 cis, | fis8 b a4 cis2 | } >> }
233
234 musicB = { \clef bass  \new Voice { \voiceTwo \relative { < fis, a cis>4 
235         \change Staff = up cis' \change Staff = down <fis, a>  
236         \change Staff = up dis' | \change Staff = down <fis, a cis>4 gis 
237         <f a d>2 |  } }}
238
239 \score { 
240         \new PianoStaff {
241        << \context Staff = "up" {
242                #(set-accidental-style 'modern-cautionary) 
243        \musicA }
244        \context Staff = "down"{
245                #(set-accidental-style 'modern-cautionary)
246        \musicB } >> }
247        \header { piece = \markup {\fill-line { \fontsize #3  "'modern-cautionary" }}}
248 }
249 @end lilypond
250
251 @funindex modern-voice
252 @item modern-voice
253 This rule is used for multivoice accidentals to be read both by musicians
254 playing one voice and musicians playing all voices.  Accidentals are
255 typeset for each voice, but they @emph{are} canceled across voices in
256 the same @internalsref{Staff}.
257
258 @funindex modern-voice-cautionary
259 @item modern-voice-cautionary
260 This rule is the same as @code{modern-voice}, but with the extra
261 accidentals (the ones not typeset by @code{voice}) typeset
262 as cautionaries.  Even though all accidentals typeset by
263 @code{default} @emph{are} typeset by this variable,
264 some of them are typeset as cautionaries.
265
266 @item piano
267 @funindex piano accidentals
268 This rule reflects 20th century practice for piano notation.  Very similar to
269 @code{modern} but accidentals also get canceled
270 across the staves in the same @internalsref{GrandStaff} or
271 @internalsref{PianoStaff}.
272
273 @item piano-cautionary
274 @funindex #(set-accidental-style 'piano-cautionary)
275 Same as @code{#(set-accidental-style 'piano)} but with the extra
276 accidentals typeset as cautionaries.
277
278 @item no-reset
279 @funindex no-reset accidental style
280 This is the same as @code{default} but with accidentals lasting
281 @q{forever} and not only until the next measure
282 @lilypond[quote,ragged-right,verbatim,relative=1]
283 #(set-accidental-style 'no-reset)
284 c1 cis cis c
285 @end lilypond
286
287 @item forget
288 This is sort of the opposite of @code{no-reset}: Accidentals
289 are not remembered at all -- and hence all accidentals are
290 typeset relative to the key signature, regardless of what was
291 before in the music
292
293 @lilypond[quote,ragged-right,verbatim,relative=1]
294 #(set-accidental-style 'forget)
295 \key d\major c4 c cis cis d d dis dis
296 @end lilypond
297 @end table
298
299
300 @seealso
301
302 Program reference: @internalsref{Accidental_engraver},
303 @internalsref{Accidental}, @internalsref{AccidentalSuggestion} and @internalsref{AccidentalPlacement}.
304
305
306 @refbugs
307
308 Simultaneous notes are considered to be entered in sequential
309 mode.  This means that in a chord the accidentals are typeset as if the
310 notes in the chord happen one at a time, in the order in which
311 they appear in the input file.  This is a problem when accidentals
312 in a chord depend on each other,
313 which does not happen for the default accidental style.  The problem
314 can be solved by manually inserting @code{!} and @code{?} for the
315 problematic notes.
316
317
318 @node Setting automatic beam behavior
319 @subsection Setting automatic beam behavior
320
321 @funindex autoBeamSettings
322 @funindex (end * * * *)
323 @funindex (begin * * * *)
324 @cindex automatic beams, tuning
325 @cindex tuning automatic beaming
326
327 @c [TODO: use \applyContext]
328
329 In normal time signatures, automatic beams can start on any note but can
330 only end in a few positions within the measure: beams can end on a beat,
331 or at durations specified by the properties in
332 @code{autoBeamSettings}.  The properties in @code{autoBeamSettings}
333 consist of a list of rules for where beams can begin and end.  The
334 default @code{autoBeamSettings} rules are defined in
335 @file{scm/@/auto@/-beam@/.scm}.
336
337 In order to add a rule to the list, use
338 @example
339 #(override-auto-beam-setting '(be p q n m) a b [context])
340 @end example
341
342 @itemize @bullet
343
344 @item @code{be} is either "begin" or "end".
345
346 @item @code{p/q} is the duration of the note for which you want
347 to add a rule.  A beam is considered to have the duration of its
348 shortest note.  Set @code{p} and @code{q} to @code{'*'} to
349 have this apply to any beam.
350
351 @item @code{n/m} is the time signature to which
352 this rule should apply.  Set @code{n} and @code{m} to @code{'*'}
353 to have this apply in any time signature.
354
355 @item @code{a/b} is the position in the bar at which the beam should
356 begin/end.
357
358 @item @code{context} is optional, and it specifies the context at which
359 the change should be made.  The default is @code{'Voice}.
360 @code{#(score-override-auto-beam-setting '(A B C D) E F)} is equivalent to
361 @code{#(override-auto-beam-setting '(A B C D) E F 'Score)}.
362
363 @end itemize
364
365 For example, if automatic beams should always end on the first quarter
366 note, use
367
368 @example
369 #(override-auto-beam-setting '(end * * * *) 1 4)
370 @end example
371
372 You can force the beam settings to only take effect on beams whose shortest
373 note is a certain duration
374
375 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
376 \time 2/4
377 #(override-auto-beam-setting '(end 1 16 * *) 1 16)
378 a16 a a a a a a a |
379 a32 a a a a16 a a a a a |
380 #(override-auto-beam-setting '(end 1 32 * *) 1 16)
381 a32 a a a a16 a a a a a |
382 @end lilypond
383
384 You can force the beam settings to only take effect in certain time
385 signatures
386
387 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
388 \time 5/8
389 #(override-auto-beam-setting '(end * * 5 8) 2 8)
390 c8 c d d d
391 \time 4/4
392 e8 e f f e e d d
393 \time 5/8
394 c8 c d d d
395 @end lilypond
396
397 You can also remove a previously set beam-ending rule by using
398
399 @example
400 #(revert-auto-beam-setting '(be p q n m) a b [context])
401 @end example
402
403 @noindent
404 be, p, q, n, m, a, b and context are the same as above.  Note that the
405 default rules are specified in @file{scm/@/auto@/-beam@/.scm},
406 so you can revert rules that you did not explicitly create.
407
408 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
409 \time 4/4
410 a16 a a a a a a a a a a a a a a a
411 #(revert-auto-beam-setting '(end 1 16 4 4) 1 4)
412 a16 a a a a a a a a a a a a a a a
413 @end lilypond
414
415 The rule in a revert-auto-beam-setting statement must exactly match the
416 original rule.  That is, no wildcard expansion is taken into account.
417
418 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
419 \time 1/4
420 #(override-auto-beam-setting '(end 1 16 1 4) 1 8)
421 a16 a a a
422 #(revert-auto-beam-setting '(end 1 16 * *) 1 8) % this won't revert it!
423 a a a a
424 #(revert-auto-beam-setting '(end 1 16 1 4) 1 8) % this will
425 a a a a
426 @end lilypond
427
428
429
430 @c TODO:  old material -- not covered by above stuff, I think.
431 If automatic beams should end on every quarter in 5/4 time, specify
432 all endings
433 @example
434 #(override-auto-beam-setting '(end * * * *) 1 4 'Staff)
435 #(override-auto-beam-setting '(end * * * *) 1 2 'Staff)
436 #(override-auto-beam-setting '(end * * * *) 3 4 'Staff)
437 #(override-auto-beam-setting '(end * * * *) 5 4 'Staff)
438 @dots{}
439 @end example
440
441 The same syntax can be used to specify beam starting points.  In this
442 example, automatic beams can only end on a dotted quarter note
443 @example
444 #(override-auto-beam-setting '(end * * * *) 3 8)
445 #(override-auto-beam-setting '(end * * * *) 1 2)
446 #(override-auto-beam-setting '(end * * * *) 7 8)
447 @end example
448 In 4/4 time signature, this means that automatic beams could end only on
449 3/8 and on the fourth beat of the measure (after 3/4, that is 2 times
450 3/8, has passed within the measure).
451
452 If any unexpected beam behaviour occurs, check the default automatic beam
453 settings in @file{scm/@/auto@/-beam@/.scm}
454 for possible interference, because the beam
455 endings defined there will still apply on top of your own overrides. Any
456 unwanted endings in the default vales must be reverted for your time
457 signature(s).
458
459 For example, to typeset @code{(3 4 3 2)}-beam endings in 12/8, begin
460 with
461
462 @example
463 %%% revert default values in scm/auto-beam.scm regarding 12/8 time
464 #(revert-auto-beam-setting '(end * * 12 8) 3 8)
465 #(revert-auto-beam-setting '(end * * 12 8) 3 4)
466 #(revert-auto-beam-setting '(end * * 12 8) 9 8)
467
468 %%% your new values
469 #(override-auto-beam-setting '(end 1 8 12 8) 3 8)
470 #(override-auto-beam-setting '(end 1 8 12 8) 7 8)
471 #(override-auto-beam-setting '(end 1 8 12 8) 10 8)
472 @end example
473
474 @cindex automatic beam generation
475 @cindex autobeam
476 @funindex autoBeaming
477 @cindex lyrics
478
479 If beams are used to indicate melismata in songs, then automatic
480 beaming should be switched off with @code{\autoBeamOff}.
481
482
483 @refcommands
484
485 @funindex \autoBeamOff
486 @code{\autoBeamOff},
487 @funindex \autoBeamOn
488 @code{\autoBeamOn}.
489
490 @commonprop
491
492 Beaming patterns may be altered with the @code{beatGrouping} property,
493
494 @lilypond[quote,verbatim,relative=2,fragment,ragged-right]
495 \time 5/16
496 \set beatGrouping = #'(2 3)
497 c8[^"(2+3)" c16 c8]
498 \set beatGrouping = #'(3 2)
499 c8[^"(3+2)" c16 c8]
500 @end lilypond
501
502
503 @refbugs
504
505 If a score ends while an automatic beam has not been ended and is
506 still accepting notes, this last beam will not be typeset at all.  The
507 same holds polyphonic voices, entered with @code{<< @dots{} \\ @dots{}
508 >>}.  If a polyphonic voice ends while an automatic beam is still
509 accepting notes, it is not typeset.
510
511
512 @node Interpretation contexts
513 @section Interpretation contexts
514
515 This section describes what contexts are, and how to modify them.
516
517 @menu
518 * Contexts explained::          
519 * Creating contexts::           
520 * Changing context properties on the fly::  
521 * Modifying context plug-ins::  
522 * Layout tunings within contexts::  
523 * Changing context default settings::  
524 * Defining new contexts::       
525 * Aligning contexts::           
526 * Vertical grouping of grobs::  
527 @end menu
528
529
530 @node Contexts explained
531 @subsection Contexts explained
532
533 When music is printed, a lot of notational elements must be added to the
534 output.  For example, compare the input and output of the following example:
535
536 @lilypond[quote,verbatim,relative=2,fragment]
537 cis4 cis2. g4
538 @end lilypond
539
540 The input is rather sparse, but in the output, bar lines, accidentals,
541 clef, and time signature are added.  LilyPond @emph{interprets} the
542 input.  During this step, the musical information is inspected in time
543 order, similar to reading a score from left to right.  While reading
544 the input, the program remembers where measure boundaries are, and which
545 pitches require explicit accidentals.  This information can be presented on
546 several levels.  For example, the effect of an accidental is limited
547 to a single staff, while a bar line must be synchronized across the
548 entire score.
549
550 Within LilyPond, these rules and bits of information are grouped in
551 @emph{Contexts}.  Some examples of contexts are @context{Voice},
552 @context{Staff}, and @context{Score}.  They are hierarchical, for
553 example: a @context{Staff} can contain many @context{Voice}s, and a
554 @context{Score} can contain many @context{Staff} contexts.
555
556 @quotation
557 @image{context-example,5cm,,}
558 @end quotation
559
560 Each context has the responsibility for enforcing some notation rules,
561 creating some notation objects and maintaining the associated
562 properties.  For example, the @context{Voice} context may introduce an
563 accidental and then the @context{Staff} context maintains the rule to
564 show or suppress the accidental for the remainder of the measure.  The
565 synchronization of bar lines is handled at @context{Score} context.
566
567 However, in some music we may not want the bar lines to be
568 synchronized -- consider a polymetric score in 4/4 and 3/4 time.  In
569 such cases, we must modify the default settings of the @context{Score}
570 and @context{Staff} contexts.
571
572 For very simple scores, contexts are created implicitly, and you need
573 not be aware of them.  For larger pieces, such as anything with more
574 than one staff, they must be
575 created explicitly to make sure that you get as many staves as you
576 need, and that they are in the correct order.  For typesetting pieces
577 with specialized notation, it can be useful to modify existing or
578 to define new contexts.
579
580
581 A complete description of all available contexts is in the program
582 reference, see
583 @ifhtml
584 @internalsref{Contexts}.
585 @end ifhtml
586 @ifnothtml
587 Translation @arrow{} Context.
588 @end ifnothtml
589
590 @c [TODO: describe propagation]
591
592
593 @node Creating contexts
594 @subsection Creating contexts
595
596 For scores with only one voice and one staff, contexts are
597 created automatically.  For more complex scores, it is necessary to
598 create them by hand.  There are three commands that do this.
599
600 @itemize @bullet
601
602 @item
603 The easiest command is @code{\new}, and it also the quickest to type.
604 It is prepended to a music expression, for example
605
606 @funindex \new
607 @cindex new contexts
608 @cindex Context, creating
609
610 @example
611 \new @var{type} @var{music expression}
612 @end example
613
614 @noindent
615 where @var{type} is a context name (like @code{Staff} or
616 @code{Voice}).  This command creates a new context, and starts
617 interpreting the @var{music expression} with that.
618
619 A practical application of @code{\new} is a score with many
620 staves.  Each part that should be on its own staff, is preceded with
621 @code{\new Staff}.
622
623 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
624 <<
625   \new Staff { c4 c }
626   \new Staff { d4 d }
627 >>
628 @end lilypond
629
630 The @code{\new} command may also give a name to the context,
631
632 @example
633 \new @var{type} = @var{id} @var{music}
634 @end example
635 However, this user specified name is only used if there is no other
636 context already earlier with the same name.
637
638
639 @funindex \context
640
641 @item
642 Like @code{\new}, the @code{\context} command also directs a music
643 expression to a context object, but gives the context an explicit name.  The
644 syntax is
645
646 @example
647 \context @var{type} = @var{id} @var{music}
648 @end example
649
650 This form will search for an existing context of type @var{type}
651 called @var{id}.  If that context does not exist yet, a new
652 context with the specified name is created.  This is useful if
653 the context is referred to later on.  For example, when
654 setting lyrics the melody is in a named context
655
656 @example
657 \context Voice = "@b{tenor}" @var{music}
658 @end example
659
660 @noindent
661 so the texts can be properly aligned to its notes,
662
663 @example
664 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
665 @end example
666
667 @noindent
668
669 Another possible use of named contexts is funneling two different
670 music expressions into one context.  In the following example,
671 articulations and notes are entered separately,
672
673 @example
674 music = @{ c4 c4 @}
675 arts = @{ s4-. s4-> @}
676 @end example
677
678 They are combined by sending both to the same @context{Voice} context,
679
680 @example
681 <<
682   \new Staff \context Voice = "A" \music
683   \context Voice = "A" \arts
684 >>
685 @end example
686 @lilypond[quote,ragged-right]
687 music = { c4 c4 }
688 arts = { s4-. s4-> }
689 \relative c'' <<
690   \new Staff \context Voice = "A" \music
691   \context Voice = "A" \arts
692 >>
693 @end lilypond
694
695 With this mechanism, it is possible to define an Urtext (original
696 edition), with the option to put several distinct articulations on the
697 same notes.
698
699 @cindex creating contexts
700
701 @item
702 The third command for creating contexts is
703 @example
704 \context @var{type} @var{music}
705 @end example
706
707
708 @noindent
709 This is similar to @code{\context} with @code{= @var{id}}, but matches
710 any context of type @var{type}, regardless of its given name.
711
712 This variant is used with music expressions that can be interpreted at
713 several levels.  For example, the @code{\applyOutput} command (see
714 @ref{Running a function on all layout objects}).  Without an explicit
715 @code{\context}, it is usually applied to @context{Voice}
716
717 @example
718 \applyOutput #'@var{context} #@var{function}   % apply to Voice
719 @end example
720
721 To have it interpreted at the @context{Score} or @context{Staff} level use
722 these forms
723
724 @example
725 \applyOutput #'Score #@var{function}
726 \applyOutput #'Staff #@var{function}
727 @end example
728
729 @end itemize
730
731
732 @node Changing context properties on the fly
733 @subsection Changing context properties on the fly
734
735 @cindex properties
736 @funindex \set
737 @cindex changing properties
738
739 Each context can have different @emph{properties}, variables contained
740 in that context.  They can be changed during the interpretation step.
741 This is achieved by inserting the @code{\set} command in the music,
742
743 @example
744 \set @var{context}.@var{prop} = #@var{value}
745 @end example
746
747 For example,
748 @lilypond[quote,verbatim,relative=2,fragment]
749 R1*2
750 \set Score.skipBars = ##t
751 R1*2
752 @end lilypond
753
754 This command skips measures that have no notes.  The result is that
755 multi-rests are condensed.  The value assigned is a Scheme object.  In
756 this case, it is @code{#t}, the boolean True value.
757
758 If the @var{context} argument is left out, then the current bottom-most
759 context (typically @context{ChordNames}, @context{Voice}, or
760 @context{Lyrics}) is used.  In this example,
761
762 @lilypond[quote,verbatim,relative=2,fragment]
763 c8 c c c
764 \set autoBeaming = ##f
765 c8 c c c
766 @end lilypond
767
768 @noindent
769 the @var{context} argument to @code{\set} is left out, so automatic
770 beaming is switched off in the current @internalsref{Voice}.  Note that
771 the bottom-most context does not always contain the property that you
772 wish to change -- for example, attempting to set the @code{skipBars}
773 property (of the bottom-most context, in this case @code{Voice}) will
774 have no effect.
775
776 @lilypond[quote,verbatim,relative=2,fragment]
777 R1*2
778 \set skipBars = ##t
779 R1*2
780 @end lilypond
781
782 Contexts are hierarchical, so if a bigger context was specified, for
783 example @context{Staff}, then the change would also apply to all
784 @context{Voice}s in the current stave.  The change is applied
785 @q{on-the-fly}, during the music, so that the setting only affects the
786 second group of eighth notes.
787
788 @funindex \unset
789
790 There is also an @code{\unset} command,
791 @example
792 \unset @var{context}.@var{prop}
793 @end example
794
795 @noindent
796 which removes the definition of @var{prop}.  This command removes
797 the definition only if it is set in @var{context}, so
798
799 @example
800 \set Staff.autoBeaming = ##f
801 @end example
802
803 @noindent
804 introduces a property setting at @code{Staff} level.  The setting also
805 applies to the current @code{Voice}.  However,
806
807 @example
808 \unset Voice.autoBeaming
809 @end example
810
811 @noindent
812 does not have any effect.  To cancel this setting, the @code{\unset}
813 must be specified on the same level as the original @code{\set}.  In
814 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
815 requires
816 @example
817 \unset Staff.autoBeaming
818 @end example
819
820 Like @code{\set}, the @var{context} argument does not have to be
821 specified for a bottom context, so the two statements
822
823 @example
824 \set Voice.autoBeaming = ##t
825 \set autoBeaming = ##t
826 @end example
827
828 @noindent
829 are equivalent.
830
831
832 @cindex \once
833 Settings that should only apply to a single time-step can be entered
834 with @code{\once}, for example in
835
836 @lilypond[quote,verbatim,relative=2,fragment]
837 c4
838 \once \set fontSize = #4.7
839 c4
840 c4
841 @end lilypond
842
843 the property @code{fontSize} is unset automatically after the second
844 note.
845
846 A full description of all available context properties is in the
847 program reference, see
848 @ifhtml
849 @internalsref{Tunable context properties}.
850 @end ifhtml
851 @ifnothtml
852 Translation @arrow{} Tunable context properties.
853 @end ifnothtml
854
855
856 @node Modifying context plug-ins
857 @subsection Modifying context plug-ins
858
859 Notation contexts (like @code{Score} and @code{Staff}) not only
860 store properties,
861 they also contain plug-ins called @q{engravers} that create notation
862 elements.  For example, the @code{Voice} context contains a
863 @code{Note_head_engraver} and the @code{Staff} context contains a
864 @code{Key_signature_engraver}.
865
866 For a full a description of each plug-in, see
867 @ifhtml
868 @internalsref{Engravers}.
869 @end ifhtml
870 @ifnothtml
871 Program reference @arrow Translation @arrow{} Engravers.
872 @end ifnothtml
873 Every context described in
874 @ifhtml
875 @internalsref{Contexts}
876 @end ifhtml
877 @ifnothtml
878 Program reference @arrow Translation @arrow{} Context.
879 @end ifnothtml
880 lists the engravers used for that context.
881
882
883 It can be useful to shuffle around these plug-ins.  This is done by
884 starting a new context with @code{\new} or @code{\context}, and
885 modifying it,
886
887 @funindex \with
888
889 @example
890 \new @var{context} \with @{
891   \consists @dots{}
892   \consists @dots{}
893   \remove @dots{}
894   \remove @dots{}
895   @emph{etc.}
896 @}
897 @{
898   @emph{..music..}
899 @}
900 @end example
901
902 @noindent
903 where the @dots{} should be the name of an engraver.  Here is a simple
904 example which removes @code{Time_signature_engraver} and
905 @code{Clef_engraver} from a @code{Staff} context,
906
907 @lilypond[quote,relative=1,verbatim,fragment]
908 <<
909   \new Staff {
910     f2 g
911   }
912   \new Staff \with {
913      \remove "Time_signature_engraver"
914      \remove "Clef_engraver"
915   } {
916     f2 g2
917   }
918 >>
919 @end lilypond
920
921 In the second staff there are no time signature or clef symbols.  This
922 is a rather crude method of making objects disappear since it will affect
923 the entire staff.  This method also influences the spacing, which may or
924 may not be desirable.  A more
925 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
926
927 The next example shows a practical application.  Bar lines and time
928 signatures are normally synchronized across the score.  This is done
929 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
930 This plug-in keeps an administration of time signature, location
931 within the measure, etc.  By moving thes engraver from @code{Score} to
932 @code{Staff} context, we can have a score where each staff has its own
933 time signature.
934
935 @cindex polymetric scores
936 @cindex Time signatures, multiple
937
938 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
939 \new Score \with {
940   \remove "Timing_translator"
941   \remove "Default_bar_line_engraver"
942 } <<
943   \new Staff \with {
944     \consists "Timing_translator"
945     \consists "Default_bar_line_engraver"
946   } {
947       \time 3/4
948       c4 c c c c c
949   }
950   \new Staff \with {
951     \consists "Timing_translator"
952     \consists "Default_bar_line_engraver"
953   } {
954        \time 2/4
955        c4 c c c c c
956   }
957 >>
958 @end lilypond
959
960
961 @node Layout tunings within contexts
962 @subsection Layout tunings within contexts
963
964 Each context is responsible for creating certain types of graphical
965 objects.  The settings used for printing these objects are also stored by
966 context.  By changing these settings, the appearance of objects can be
967 altered.
968
969 The syntax for this is
970
971 @example
972 \override @var{context}.@var{name} #'@var{property} = #@var{value}
973 @end example
974
975 Here @var{name} is the name of a graphical object, like @code{Stem} or
976 @code{NoteHead}, and @var{property} is an internal variable of the
977 formatting system (@q{grob property} or @q{layout property}).  The latter is a
978 symbol, so it must be quoted.  The subsection @ref{Constructing a
979 tweak}, explains what to fill in for @var{name}, @var{property}, and
980 @var{value}.  Here we only discuss the functionality of this command.
981
982 The command
983
984 @verbatim
985 \override Staff.Stem #'thickness = #4.0
986 @end verbatim
987
988 @noindent
989 makes stems thicker (the default is 1.3, with staff line thickness as a
990 unit).  Since the command specifies @context{Staff} as context, it only
991 applies to the current staff.  Other staves will keep their normal
992 appearance.  Here we see the command in action:
993
994 @lilypond[quote,verbatim,relative=2,fragment]
995 c4
996 \override Staff.Stem #'thickness = #4.0
997 c4
998 c4
999 c4
1000 @end lilypond
1001
1002 The @code{\override} command changes the definition of the @code{Stem}
1003 within the current @context{Staff}.  After the command is interpreted
1004 all stems are thickened.
1005
1006 Analogous to @code{\set}, the @var{context} argument may be left out,
1007 causing the default context @context{Voice} to be used.  Adding
1008 @code{\once} applies the change during one timestep only.
1009
1010 @lilypond[quote,fragment,verbatim,relative=2]
1011 c4
1012 \once \override Stem #'thickness = #4.0
1013 c4
1014 c4
1015 @end lilypond
1016
1017 The @code{\override} must be done before the object is
1018 started.  Therefore, when altering @emph{Spanner} objects such as slurs
1019 or beams, the @code{\override} command must be executed at the moment
1020 when the object is created.  In this example,
1021
1022 @lilypond[quote,fragment,verbatim,relative=2]
1023 \override Slur #'thickness = #3.0
1024 c8[( c
1025 \override Beam #'thickness = #0.6
1026 c8 c])
1027 @end lilypond
1028
1029 @noindent
1030 the slur is fatter but the beam is not.  This is because the command for
1031 @code{Beam} comes after the Beam is started, so it has no effect.
1032
1033 Analogous to @code{\unset}, the @code{\revert} command for a context
1034 undoes an @code{\override} command; like with @code{\unset}, it only
1035 affects settings that were made in the same context.  In other words, the
1036 @code{\revert} in the next example does not do anything.
1037
1038 @example
1039 \override Voice.Stem #'thickness = #4.0
1040 \revert Staff.Stem #'thickness
1041 @end example
1042
1043 Some tweakable options are called @q{subproperties} and reside inside
1044 properties.  To tweak those, use commands of the form
1045
1046 @c leave this as a long long
1047 @example
1048 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
1049 @end example
1050
1051 @noindent
1052 such as
1053
1054 @example
1055 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1056 @end example
1057
1058
1059 @seealso
1060
1061 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
1062 @internalsref{PropertySet}, @internalsref{Backend}, and
1063 @internalsref{All layout objects}.
1064
1065
1066 @refbugs
1067
1068 The back-end is not very strict in type-checking object properties.
1069 Cyclic references in Scheme values for properties can cause hangs
1070 or crashes, or both.
1071
1072
1073 @node Changing context default settings
1074 @subsection Changing context default settings
1075
1076 The adjustments of the previous subsections (@ref{Changing context
1077 properties on the fly}, @ref{Modifying context plug-ins}, and
1078 @ref{Layout tunings within contexts}) can also be entered separately
1079 from the music in the @code{\layout} block,
1080
1081 @example
1082 \layout @{
1083   @dots{}
1084   \context @{
1085     \Staff
1086
1087     \set fontSize = #-2
1088     \override Stem #'thickness = #4.0
1089     \remove "Time_signature_engraver"
1090   @}
1091 @}
1092 @end example
1093
1094 The @code{\Staff} command brings in the existing definition of the
1095 staff context so that it can be modified.
1096
1097 The statements
1098 @example
1099 \set fontSize = #-2
1100 \override Stem #'thickness = #4.0
1101 \remove "Time_signature_engraver"
1102 @end example
1103
1104 @noindent
1105 affect all staves in the score.  Other contexts can be modified
1106 analogously.
1107
1108 The @code{\set} keyword is optional within the @code{\layout} block, so
1109
1110 @example
1111 \context @{
1112   @dots{}
1113   fontSize = #-2
1114 @}
1115 @end example
1116
1117 @noindent
1118 will also work.
1119
1120
1121
1122 @refbugs
1123
1124 It is not possible to collect context changes in a variable and apply
1125 them to a @code{\context} definition by referring to that variable.
1126
1127 The @code{\RemoveEmptyStaffContext} will overwrite your current
1128 @code{\Staff} settings.  If you wish to change the defaults for a
1129 staff which uses @code{\RemoveEmptyStaffContext}, you must do so
1130 after calling @code{\RemoveemptyStaffContext}, ie
1131
1132 @example
1133 \layout @{
1134   \context @{
1135     \RemoveEmptyStaffContext
1136
1137     \override Stem #'thickness = #4.0
1138   @}
1139 @}
1140 @end example
1141
1142
1143 @node Defining new contexts
1144 @subsection Defining new contexts
1145
1146 Specific contexts, like @context{Staff} and @code{Voice}, are made of
1147 simple building blocks.  It is possible to create new types of
1148 contexts with different combinations of engraver plug-ins.
1149
1150 The next example shows how to build a different type of
1151 @context{Voice} context from scratch.  It will be similar to
1152 @code{Voice}, but only prints centered slash noteheads.  It can be used
1153 to indicate improvisation in jazz pieces,
1154
1155 @lilypond[quote,ragged-right]
1156 \layout { \context {
1157   \name ImproVoice
1158   \type "Engraver_group"
1159   \consists "Note_heads_engraver"
1160   \consists "Text_engraver"
1161   \consists Pitch_squash_engraver
1162   squashedPosition = #0
1163   \override NoteHead #'style = #'slash
1164   \override Stem #'transparent = ##t
1165   \alias Voice
1166 }
1167 \context { \Staff
1168   \accepts "ImproVoice"
1169 }}
1170
1171 \relative c'' {
1172   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
1173    c4 c^"undress" c_"while playing :)" c }
1174   a1
1175 }
1176 @end lilypond
1177
1178
1179 These settings are defined within a @code{\context} block inside a
1180 @code{\layout} block,
1181
1182 @example
1183 \layout @{
1184   \context @{
1185     @dots{}
1186   @}
1187 @}
1188 @end example
1189
1190 In the following discussion, the example input shown should go in place
1191 of the @dots{} in the previous fragment.
1192
1193 First it is necessary to define a name for the new context:
1194
1195 @example
1196 \name ImproVoice
1197 @end example
1198
1199 Since it is similar to the @context{Voice}, we want commands that work
1200 on (existing) @context{Voice}s to remain working.  This is achieved by
1201 giving the new context an alias @context{Voice},
1202
1203 @example
1204 \alias Voice
1205 @end example
1206
1207 The context will print notes and instructive texts, so we need to add
1208 the engravers which provide this functionality,
1209
1210 @example
1211 \consists Note_heads_engraver
1212 \consists Text_engraver
1213 @end example
1214
1215 but we only need this on the center line,
1216
1217 @example
1218 \consists Pitch_squash_engraver
1219 squashedPosition = #0
1220 @end example
1221
1222 The @internalsref{Pitch_squash_engraver} modifies note heads (created
1223 by @internalsref{Note_heads_engraver}) and sets their vertical
1224 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
1225 the center line.
1226
1227 The notes look like a slash, and have no stem,
1228
1229 @example
1230 \override NoteHead #'style = #'slash
1231 \override Stem #'transparent = ##t
1232 @end example
1233
1234 All these plug-ins have to cooperate, and this is achieved with a
1235 special plug-in, which must be marked with the keyword @code{\type}.
1236 This should always be @internalsref{Engraver_group},
1237
1238 @example
1239 \type "Engraver_group"
1240 @end example
1241
1242 Put together, we get
1243
1244 @example
1245 \context @{
1246   \name ImproVoice
1247   \type "Engraver_group"
1248   \consists "Note_heads_engraver"
1249   \consists "Text_engraver"
1250   \consists Pitch_squash_engraver
1251   squashedPosition = #0
1252   \override NoteHead #'style = #'slash
1253   \override Stem #'transparent = ##t
1254   \alias Voice
1255 @}
1256 @end example
1257
1258 @funindex \accepts
1259 Contexts form hierarchies.  We want to hang the @context{ImproVoice}
1260 under @context{Staff}, just like normal @code{Voice}s.  Therefore, we
1261 modify the @code{Staff} definition with the @code{\accepts}
1262 command,
1263
1264 @example
1265 \context @{
1266   \Staff
1267   \accepts ImproVoice
1268 @}
1269 @end example
1270
1271 @funindex \denies
1272 The opposite of @code{\accepts} is @code{\denies},
1273 which is sometimes needed when reusing existing context definitions.
1274
1275 Putting both into a @code{\layout} block, like
1276
1277 @example
1278 \layout @{
1279   \context @{
1280     \name ImproVoice
1281     @dots{}
1282   @}
1283   \context @{
1284     \Staff
1285     \accepts "ImproVoice"
1286   @}
1287 @}
1288 @end example
1289
1290 Then the output at the start of this subsection can be entered as
1291
1292 @example
1293 \relative c'' @{
1294   a4 d8 bes8
1295   \new ImproVoice @{
1296     c4^"ad lib" c
1297     c4 c^"undress"
1298     c c_"while playing :)"
1299   @}
1300   a1
1301 @}
1302 @end example
1303
1304
1305 @node Aligning contexts
1306 @subsection Aligning contexts
1307
1308 New contexts may be aligned above or below exisiting contexts.  This
1309 could be useful in setting up a vocal staff (@ref{Vocal ensembles}) and
1310 in ossia,
1311
1312 @cindex ossia
1313 @findex alignAboveContext
1314 @findex alignBelowContext
1315
1316 @lilypond[quote,ragged-right]
1317 ossia = { f4 f f f }
1318 \score{
1319   \relative c' \new Staff = "main" {
1320     c4 c c c
1321     <<
1322       \new Staff \with {alignAboveContext=main} \ossia
1323       { d8 f d f d f d f }
1324     >>
1325   }
1326 }
1327 @end lilypond
1328
1329
1330 @node Vertical grouping of grobs
1331 @subsection Vertical grouping of grobs
1332
1333 The VerticalAlignment and VerticalAxisGroup grobs work together.
1334 VerticalAxisGroup groups together different grobs like Staff, Lyrics,
1335 etc. VerticalAlignment then vertically aligns the different grobs
1336 grouped together by VerticalAxisGroup. There is usually only one
1337 VerticalAlignment per score but every Staff, Lyrics, etc. has its own
1338 VerticalAxisGroup. 
1339
1340
1341 @node The \override command
1342 @section The @code{\override} command
1343
1344 In the previous section, we have already touched on a command that
1345 changes layout details: the @code{\override} command.  In this section,
1346 we will look in more detail at how to use the command in practice.  The
1347 general syntax of this command is:
1348
1349 @example
1350 \override @var{context}.@var{layout_object} #'@var{layout_property} = #@var{value}
1351 @end example
1352
1353 This will set the @var{layout_property} of the specified @var{layout_object},
1354 which is a member of the @var{context}, to the @var{value}.
1355
1356 @menu
1357 * Constructing a tweak::        
1358 * Navigating the program reference::  
1359 * Layout interfaces::           
1360 * Determining the grob property::  
1361 * Objects connected to the input::  
1362 * Using Scheme code instead of \tweak::  
1363 * \set versus \override::       
1364 * Difficult tweaks::            
1365 @end menu
1366
1367
1368
1369 @node Constructing a tweak
1370 @subsection Constructing a tweak
1371
1372 Commands which change output generally look like
1373
1374 @example
1375 \override Voice.Stem #'thickness = #3.0
1376 @end example
1377
1378 @noindent
1379 To construct this tweak we must determine these bits of information:
1380
1381 @itemize
1382 @item the context: here @context{Voice}.
1383 @item the layout object: here @code{Stem}.
1384 @item the layout property: here @code{thickness}.
1385 @item a sensible value: here @code{3.0}.
1386 @end itemize
1387
1388 Some tweakable options are called @q{subproperties} and reside inside
1389 properties.  To tweak those, use commands in the form
1390
1391 @example
1392 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1393 @end example
1394
1395 @cindex internal documentation
1396 @cindex finding graphical objects
1397 @cindex graphical object descriptions
1398 @cindex tweaking
1399 @funindex \override
1400 @cindex internal documentation
1401
1402 For many properties, regardless of the data type of the property, setting the
1403 property to false ( @code{##f} ) will result in turning it off, causing
1404 Lilypond to ignore that property entirely.  This is particularly useful for
1405 turning off grob properties which may otherwise be causing problems.
1406
1407 We demonstrate how to glean this information from the notation manual
1408 and the program reference.
1409
1410
1411
1412
1413 @node Navigating the program reference
1414 @subsection Navigating the program reference
1415
1416 Suppose we want to move the fingering indication in the fragment
1417 below:
1418
1419 @lilypond[quote,fragment,relative=2,verbatim]
1420 c-2
1421 \stemUp
1422 f
1423 @end lilypond
1424
1425 If you visit the documentation on fingering instructions (in
1426 @ref{Fingering instructions}), you will notice:
1427
1428 @quotation
1429 @seealso
1430
1431 Program reference: @internalsref{Fingering}.
1432
1433 @end quotation
1434
1435
1436 @c  outdated info; probably will delete.
1437 @ignore
1438 This fragment points to two parts of the program reference: a page
1439 on @code{FingerEvent} and one on @code{Fingering}.
1440
1441 The page on @code{FingerEvent} describes the properties of the music
1442 expression for the input @code{-2}.  The page contains many links
1443 forward.  For example, it says
1444
1445 @quotation
1446 Accepted by: @internalsref{Fingering_engraver},
1447 @end quotation
1448
1449 @noindent
1450 That link brings us to the documentation for the Engraver, the
1451 plug-in, which says
1452
1453 @quotation
1454 This engraver creates the following layout objects: @internalsref{Fingering}.
1455 @end quotation
1456
1457 In other words, once the @code{FingerEvent}s are interpreted, the
1458 @code{Fingering_engraver} plug-in will process them.
1459 @end ignore
1460
1461 @ignore
1462 @c  I can't figure out what this is supposed to mean.  -gp
1463
1464 The @code{Fingering_engraver} is also listed to create
1465 @internalsref{Fingering} objects,
1466
1467 @c  old info?  it doesn't make any sense to me with our current docs.
1468 This is also the
1469 second bit of information listed under @b{See also} in the Notation
1470 manual.
1471 @end ignore
1472
1473 @ifnothtml
1474 The programmer's reference is available as an HTML document.  It is
1475 highly recommended that you read it in HTML form, either online or
1476 by downloading the HTML documentation.  This section will be much more
1477 difficult to understand if you are using the 
1478 PDF manual.
1479 @end ifnothtml
1480
1481 Follow the link to @internalsref{Fingering}.  At the top of the
1482 page, you will see
1483
1484 @quotation
1485 Fingering objects are created by: @internalsref{Fingering_engraver} and
1486 @internalsref{New_fingering_engraver}.
1487 @end quotation
1488
1489 By following related links inside the program reference, we can follow the
1490 flow of information within the program:
1491
1492 @itemize @bullet
1493
1494 @item @internalsref{Fingering}:
1495 @internalsref{Fingering} objects are created by:
1496 @internalsref{Fingering_engraver}
1497
1498 @item @internalsref{Fingering_engraver}:
1499 Music types accepted: @internalsref{fingering-event}
1500
1501 @item @internalsref{fingering-event}:
1502 Music event type @code{fingering-event} is in Music expressions named
1503 @internalsref{FingerEvent}
1504 @end itemize
1505
1506 This path goes against the flow of information in the program: it
1507 starts from the output, and ends at the input event.  You could
1508 also start at an input event, and read with the flow of
1509 information, eventually ending up at the output object(s).
1510
1511 The program reference can also be browsed like a normal document.  It
1512 contains chapters on
1513 @ifhtml
1514 @internalsref{Music definitions},
1515 @end ifhtml
1516 @ifnothtml
1517 @code{Music definitions}
1518 @end ifnothtml
1519 on @internalsref{Translation}, and the @internalsref{Backend}.  Every
1520 chapter lists all the definitions used and all properties that may be
1521 tuned.
1522
1523
1524 @node Layout interfaces
1525 @subsection Layout interfaces
1526
1527 @cindex interface, layout
1528 @cindex layout interface
1529 @cindex grob
1530
1531 The HTML page that we found in the previous section describes the
1532 layout object called @internalsref{Fingering}.  Such an object is a
1533 symbol within the score.  It has properties that store numbers (like
1534 thicknesses and directions), but also pointers to related objects.  A
1535 layout object is also called a @emph{Grob}, which is short for Graphical
1536 Object.  For more details about Grobs, see @internalsref{grob-interface}.
1537
1538 The page for @code{Fingering} lists the definitions for the
1539 @code{Fingering} object.  For example, the page says
1540
1541 @quotation
1542 @code{padding} (dimension, in staff space):
1543
1544 @code{0.5}
1545 @end quotation
1546
1547 @noindent
1548 which means that the number will be kept at a distance of at least 0.5
1549 of the note head.
1550
1551
1552 Each layout object may have several functions as a notational or
1553 typographical element.  For example, the Fingering object
1554 has the following aspects
1555
1556 @itemize @bullet
1557 @item
1558 Its size is independent of the horizontal spacing, unlike slurs or beams.
1559
1560 @item
1561 It is a piece of text.  Granted, it is usually a very short text.
1562
1563 @item
1564 That piece of text is typeset with a font, unlike slurs or beams.
1565
1566 @item
1567 Horizontally, the center of the symbol should be aligned to the
1568 center of the notehead.
1569
1570 @item
1571 Vertically, the symbol is placed next to the note and the staff.
1572
1573 @item
1574 The vertical position is also coordinated with other superscript
1575 and subscript symbols.
1576 @end itemize
1577
1578 Each of these aspects is captured in so-called @emph{interface}s,
1579 which are listed on the @internalsref{Fingering} page at the bottom
1580
1581 @quotation
1582 This object supports the following interfaces:
1583 @internalsref{item-interface},
1584 @internalsref{self-alignment-interface},
1585 @internalsref{side-position-interface}, @internalsref{text-interface},
1586 @internalsref{text-script-interface}, @internalsref{font-interface},
1587 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1588 @end quotation
1589
1590 Clicking any of the links will take you to the page of the respective
1591 object interface.  Each interface has a number of properties.  Some of
1592 them are not user-serviceable (@q{Internal properties}), but others
1593 can be modified.
1594
1595 We have been talking of @emph{the} @code{Fingering} object, but actually it
1596 does not amount to much.  The initialization file (see
1597 @ref{Default files})
1598 @file{scm/@/define@/-grobs@/.scm} shows the soul of the @q{object},
1599
1600 @example
1601 (Fingering
1602   . ((padding . 0.5)
1603      (avoid-slur . around)
1604      (slur-padding . 0.2)
1605      (staff-padding . 0.5)
1606      (self-alignment-X . 0)
1607      (self-alignment-Y . 0)
1608      (script-priority . 100)
1609      (stencil . ,ly:text-interface::print)
1610      (direction . ,ly:script-interface::calc-direction)
1611      (font-encoding . fetaNumber)
1612      (font-size . -5)           ; don't overlap when next to heads.
1613      (meta . ((class . Item)
1614      (interfaces . (finger-interface
1615                     font-interface
1616                     text-script-interface
1617                     text-interface
1618                     side-position-interface
1619                     self-alignment-interface
1620                     item-interface))))))
1621 @end example
1622
1623 @noindent
1624 As you can see, the @code{Fingering} object is nothing more than a
1625 bunch of variable settings, and the webpage in the Program Reference
1626 is directly generated from this definition.
1627
1628
1629 @node Determining the grob property
1630 @subsection Determining the grob property
1631
1632 Recall that we wanted to change the position of the @b{2} in
1633
1634 @lilypond[quote,fragment,relative=2,verbatim]
1635 c-2
1636 \stemUp
1637 f
1638 @end lilypond
1639
1640 Since the @b{2} is vertically positioned next to its note, we have to
1641 meddle with the interface associated with this positioning.  This is
1642 done using @code{side-position-interface}.  The page for this interface
1643 says
1644
1645 @quotation
1646 @code{side-position-interface}
1647
1648 Position a victim object (this one) next to other objects (the
1649 support).  The property @code{direction} signifies where to put the
1650 victim object relative to the support (left or right, up or down?)
1651 @end quotation
1652
1653 @cindex padding
1654 @noindent
1655 Below this description, the variable @code{padding} is described as
1656
1657 @quotation
1658 @table @code
1659 @item padding
1660 (dimension, in staff space)
1661
1662 Add this much extra space between objects that are next to each other.
1663 @end table
1664 @end quotation
1665
1666 By increasing the value of @code{padding}, we can move the
1667 fingering away from the notehead.  The following command inserts
1668 3 staff spaces of white
1669 between the note and the fingering:
1670 @example
1671 \once \override Voice.Fingering #'padding = #3
1672 @end example
1673
1674 Inserting this command before the Fingering object is created,
1675 i.e., before @code{c2}, yields the following result:
1676
1677 @lilypond[quote,relative=2,fragment,verbatim]
1678 \once \override Voice.Fingering #'padding = #3
1679 c-2
1680 \stemUp
1681 f
1682 @end lilypond
1683
1684
1685 In this case, the context for this tweak is @context{Voice}.  This
1686 fact can also be deduced from the program reference, for the page for
1687 the @internalsref{Fingering_engraver} plug-in says
1688
1689 @quotation
1690 Fingering_engraver is part of contexts: @dots{} @internalsref{Voice}
1691 @end quotation
1692
1693
1694 @node Objects connected to the input
1695 @subsection Objects connected to the input
1696
1697 @funindex \tweak
1698
1699 In some cases, it is possible to take a short-cut for tuning graphical
1700 objects.  For objects that result directly from a piece of the input,
1701 you can use the @code{\tweak} function, for example
1702
1703 @lilypond[relative=2,fragment,verbatim,ragged-right]
1704 <
1705   c
1706   \tweak #'color #red d
1707   g
1708   \tweak #'duration-log #1  a
1709 >4-\tweak #'padding #10 -.
1710 @end lilypond
1711
1712 As you can see, properties are set in the objects directly,
1713 without mentioning the grob name or context where this should be
1714 applied.
1715
1716 This technique only works for objects that are directly connected to
1717 an @internalsref{event} from the input, for example
1718
1719 @itemize @bullet
1720 @item note heads, caused by chord-pitch (i.e., notes inside a chord)
1721 @item articulation signs, caused by articulation instructions
1722 @end itemize
1723
1724 It notably does not work for stems and accidentals (these are caused
1725 by note heads, not by music events) or clefs (these are not caused by
1726 music inputs, but rather by the change of a property value).
1727
1728 There are very few objects which are @emph{directly} connected to
1729 output.  A normal note (like @code{c4}) is not directly connected
1730 to output, so
1731
1732 @example
1733 \tweak #'color #red c4
1734 @end example
1735
1736 @noindent
1737 does not change color.  See @ref{Displaying music expressions}, for
1738 details.
1739
1740
1741 @node Using Scheme code instead of \tweak
1742 @subsection Using Scheme code instead of @code{\tweak}
1743
1744 The main disadvantage of @code{\tweak} is its syntactical
1745 inflexibility.  For example, the following produces a syntax error.
1746
1747 @example
1748 F = \tweak #'font-size #-3 -\flageolet
1749
1750 \relative c'' @{
1751   c4^\F c4_\F
1752 @}
1753 @end example
1754
1755 @noindent
1756 With other words, @code{\tweak} doesn't behave like an articulation
1757 regarding the syntax; in particular, it can't be attached with
1758 @samp{^} and @samp{_}.
1759
1760 Using Scheme, this problem can be circumvented.  The route to the
1761 result is given in @ref{Adding articulation to notes (example)},
1762 especially how to use @code{\displayMusic} as a helping guide.
1763
1764 @example
1765 F = #(let ((m (make-music 'ArticulationEvent
1766                           'articulation-type "flageolet")))
1767        (set! (ly:music-property m 'tweaks)
1768              (acons 'font-size -3
1769                     (ly:music-property m 'tweaks)))
1770        m)
1771  
1772 \relative c'' @{
1773   c4^\F c4_\F
1774 @}
1775 @end example
1776
1777 @noindent
1778 Here, the @code{tweaks} properties of the flageolet object
1779 @samp{m} (created with @code{make-music}) are extracted with
1780 @code{ly:music-property}, a new key-value pair to change the
1781 font size is prepended to the property list with the
1782 @code{acons} Scheme function, and the result is finally
1783 written back with @code{set!}.  The last element of the
1784 @code{let} block is the return value, @samp{m} itself.
1785
1786
1787 @node \set versus \override
1788 @subsection @code{\set} vs. @code{\override}
1789
1790 We have seen two methods of changing properties: @code{\set} and
1791 @code{\override}.  There are actually two different kinds of
1792 properties.
1793
1794 Contexts can have properties, which are usually named in
1795 @code{studlyCaps}.  They mostly control the translation from
1796 music to notatino, eg. @code{localKeySignature} (for determining
1797 whether to print accidentals), @code{measurePosition} (for
1798 determining when to print a barline).  Context properties can
1799 change value over time while interpreting a piece of music;
1800 @code{measurePosition} is an obvious example of
1801 this.  Context properties are modified with @code{\set}.
1802
1803 There is a special type of context property: the element
1804 description. These properties are named in @code{StudlyCaps}
1805 (starting with capital letters).  They contain the
1806 @q{default settings} for said graphical object as an
1807 association list.  See @file{scm/@/define@/-grobs@/.scm}
1808 to see what kind of settings there are.  Element descriptions
1809 may be modified with @code{\override}.
1810
1811 @code{\override} is actually a shorthand;
1812
1813 @example
1814 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1815 @end example
1816
1817 @noindent
1818 is more or less equivalent to
1819
1820 @c  leave this long line -gp
1821 @example
1822 \set @var{context}.@var{name} #'@var{property} = #(cons (cons '@var{property} @var{value}) <previous value of @var{context})
1823 @end example
1824
1825 The value of @code{context} (the alist) is used to initalize
1826 the properties of individual grobs.  Grobs also have
1827 properties, named in Scheme style, with
1828 @code{dashed-words}.  The values of grob properties change
1829 during the formatting process: formatting basically amounts
1830 to computing properties using callback functions.
1831
1832 @code{fontSize} is a special property: it is equivalent to
1833 entering @code{\override ... #'font-size} for all pertinent
1834 objects.  Since this is a common change, the special
1835 property (modified with @code{\set}) was created.
1836
1837
1838 @node Difficult tweaks
1839 @subsection Difficult tweaks
1840
1841 There are a few classes of difficult adjustments.
1842
1843 @itemize @bullet
1844
1845
1846 @item
1847 One type of difficult adjustment is the appearance of spanner objects,
1848 such as slur and tie.  Initially, only one of these objects is created,
1849 and they can be adjusted with the normal mechanism.  However, in some
1850 cases the spanners cross line breaks.  If this happens, these objects
1851 are cloned.  A separate object is created for every system that it is
1852 in.  These are clones of the original object and inherit all
1853 properties, including @code{\override}s.
1854
1855
1856 In other words, an @code{\override} always affects all pieces of a
1857 broken spanner.  To change only one part of a spanner at a line break,
1858 it is necessary to hook into the formatting process.  The
1859 @code{after-line-breaking} callback contains the Scheme procedure that
1860 is called after the line breaks have been determined, and layout
1861 objects have been split over different systems.
1862
1863 In the following example, we define a procedure
1864 @code{my-callback}.  This procedure
1865
1866 @itemize @bullet
1867 @item
1868 determines if we have been split across line breaks
1869 @item
1870 if yes, retrieves all the split objects
1871 @item
1872 checks if we are the last of the split objects
1873 @item
1874 if yes, it sets @code{extra-offset}.
1875 @end itemize
1876
1877 This procedure is installed into @internalsref{Tie}, so the last part
1878 of the broken tie is translated up.
1879
1880 @lilypond[quote,verbatim,ragged-right]
1881 #(define (my-callback grob)
1882   (let* (
1883          ; have we been split?
1884          (orig (ly:grob-original grob))
1885
1886          ; if yes, get the split pieces (our siblings)
1887          (siblings (if (ly:grob? orig)
1888                      (ly:spanner-broken-into orig) '() )))
1889
1890    (if (and (>= (length siblings) 2)
1891              (eq? (car (last-pair siblings)) grob))
1892      (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1893
1894 \relative c'' {
1895   \override Tie #'after-line-breaking =
1896   #my-callback
1897   c1 ~ \break c2 ~ c
1898 }
1899 @end lilypond
1900
1901 @noindent
1902 When applying this trick, the new @code{after-line-breaking} callback
1903 should also call the old one @code{after-line-breaking}, if there is
1904 one.  For example, if using this with @code{Hairpin},
1905 @code{ly:hairpin::after-line-breaking} should also be called.
1906
1907
1908 @item Some objects cannot be changed with @code{\override} for
1909 technical reasons.  Examples of those are @code{NonMusicalPaperColumn}
1910 and @code{PaperColumn}.  They can be changed with the
1911 @code{\overrideProperty} function, which works similar to @code{\once
1912 \override}, but uses a different syntax.
1913
1914 @example
1915 \overrideProperty
1916 #"Score.NonMusicalPaperColumn"  % Grob name
1917 #'line-break-system-details     % Property name
1918 #'((next-padding . 20))         % Value
1919 @end example
1920
1921 Note, however, that @code{\override}, applied to
1922 @code{NoteMusicalPaperColumn} and @code{PaperColumn}, still works as
1923 expected within @code{\context} blocks.
1924
1925 @end itemize