Previous: Contexts for programmers, Up: Interfaces for programmers
Properties (like thickness, direction, etc.) can be set at fixed values with \override, e.g.
\override Stem #'thickness = #2.0
Properties can also be set to a Scheme procedure,
\override Stem #'thickness = #(lambda (grob) (if (= UP (ly:grob-property grob 'direction)) 2.0 7.0)) c b a g b a g b
In this case, the procedure is executed as soon as the value of the property is requested during the formatting process.
Most of the typesetting engine is driven by such callbacks. Properties that typically use callbacks include
stencil
X-offset
X-extent
The procedure always takes a single argument, being the grob.
If routines with multiple arguments must be called, the current grob
can be inserted with a grob closure. Here is a setting from
AccidentalSuggestion
,
(X-offset . ,(ly:make-simple-closure `(,+ ,(ly:make-simple-closure (list ly:self-alignment-interface::centered-on-x-parent)) ,(ly:make-simple-closure (list ly:self-alignment-interface::x-aligned-on-self)))))
In this example, both ly:self-alignment-interface::x-aligned-on-self
and
ly:self-alignment-interface::centered-on-x-parent
are called
with the grob as argument. The results are added with the +
function. To ensure that this addition is properly executed, the whole
thing is enclosed in ly:make-simple-closure
.
In fact, using a single procedure as property value is equivalent to
(ly:make-simple-closure (ly:make-simple-closure (list proc)))
The inner ly:make-simple-closure
supplies the grob as argument
to proc, the outer ensures that result of the function is
returned, rather than the simple-closure
object.
Previous: Contexts for programmers, Up: Interfaces for programmers
This page is for LilyPond-2.10.33 (stable-branch).