There are two classes of difficult adjustments. First, when there are several of the same objects at one point, and you want to adjust only one. For example, if you want to change only one note head in a chord.
In this case, the \applyoutput
function must be used. The
next example defines a Scheme function set-position-font-size
that sets the font-size
property, but only
on objects that have
note-head-interface (lilypond-internals)
and are at the
right Y-position.
#(define ((set-position-font-size pos size) grob origin current) (let* ((interfaces (ly:grob-property grob 'interfaces)) (position (ly:grob-property grob 'staff-position))) (if (and ; is this a note head? (memq 'note-head-interface interfaces) ; is the Y coordinate right? (= pos position)) ; then do it. (set! (ly:grob-property grob 'font-size) size)))) \relative { c \applyoutput #(set-position-font-size -2 4) <c e g> }
A similar technique can be used for accidentals. In that case, the
function should check for accidental-interface
.
Another difficult adjustment is the appearance of spanner objects,
such as slur and tie. Initially, only one of these objects is created,
and they can be adjusted with the normal mechanism. However, in some
cases the spanners cross line breaks. If this happens, these objects
are cloned. A separate object is created for every system that it is
in. These are clones of the original object and inherit all
properties, including \override
s.
In other words, an \override
always affects all pieces of a
broken spanner. To change only one part of a spanner at a line break,
it is necessary to hook into the formatting process. The
after-line-breaking-callback
property contains the Scheme procedure
that is called after the line breaks have been determined, and layout
objects have been split over different systems.
In the following example, we define a procedure
my-callback
. This procedure
extra-offset
.
This procedure is installed into Tie (lilypond-internals) , so the last part of the broken tie is translated up.
#(define (my-callback grob) (let* ( ; have we been split? (orig (ly:grob-original grob)) ; if yes, get the split pieces (our siblings) (siblings (if (ly:grob? orig) (ly:spanner-broken-into orig) '() ))) (if (and (>= (length siblings) 2) (eq? (car (last-pair siblings)) grob)) (ly:grob-set-property! grob 'extra-offset '(-2 . 5))))) \relative c'' { \override Tie #'after-line-breaking-callback = #my-callback c1 ~ \break c2 ~ c }
When applying this trick, the new after-line-breaking-callback
should also call the old after-line-breaking-callback
, if there
is one. For example, if using this with Slur
,
Slur::after_line_breaking
should also be called.
This page is for LilyPond-2.5.11 (development-branch).