lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unexpected behaviour of script-stencil-hack


From: David Nalesnik
Subject: Re: Unexpected behaviour of script-stencil-hack
Date: Tue, 14 Oct 2014 19:00:14 -0500

Hi Harm,

On Tue, Oct 14, 2014 at 6:15 PM, Thomas Morley <address@hidden> wrote:
Hi David,

2014-10-15 0:54 GMT+02:00 David Nalesnik <address@hidden>:
> Hi Harm,
>
> On Tue, Oct 14, 2014 at 5:38 PM, Thomas Morley <address@hidden>
> wrote:
>>
>> Hi folks,
>>
>> consider the following code.
>>
>>
>>
>> \version "2.19.13"
>> %\version "2.16.0"
>>
>> add-to-script =
>> #(define-event-function (parser location mrkp music)(markup? ly:music?)
>>   #{
>>     \tweak #'stencil
>>       #(lambda (grob)
>>          (let (
>>                ;(X-offset (ly:grob-property grob 'X-offset))
>>                )
>>            (ly:stencil-combine-at-edge
>>              (ly:script-interface::print grob)
>>              X
>>              RIGHT
>>              (grob-interpret-markup grob (markup #:normal-text mrkp))
>>              0)))
>>     $music
>>   #})
>>
>> { c''1 \add-to-script \markup "xxxxxxxxxxxxx" \trill }
>>
>>
>>
>> Hacking Script 'stencil I add markup to the default-stencil. Works as
>> expected.
>>
>> Though, regard the local binding for X-offset.
>> With 2.19.13:
>> Commenting it will center the whole new Script-stencil above the parent.
>> Uncomment it and you see the default Script-glyph in unchanged
>> position and the additions right to it.
>>
>> That's unexpected, at least for me and doesn't happen with 2.16 (don't
>> have 2.18 on this machine)
>>
>> Why does this happen? X-offset is _never_ called in the body!
>> Shouldn't be the new stencil always be centered, because self-alignment-X
>> is 0?
>> I would expect a different alignment only, if I change the values for
>> X-offset and/or self-alignment-X myself.
>
>
> The function ly:grob-property evaluates callbacks.

Partly understood.
Yes, I do want the data.
Though why does it makes a difference?

Seems there _is_ a difference, I don't fully understand, between
getting the calculated data (via ly:grob-property-data as you describe
below) and evaluating the callback.

Try this:

 add-to-script =
#(define-event-function (parser location mrkp music)(markup? ly:music?)
   #{
     \tweak #'stencil
     #(lambda (grob)
        (let (
               (X-offset-data (ly:grob-property-data grob 'X-offset))
               (X-offset (ly:grob-property grob 'X-offset))
               )
          (format #t "property-data: ~a~% grob-property: ~a~%"
            X-offset-data X-offset)
          (ly:stencil-combine-at-edge
           (ly:script-interface::print grob)
           X
           RIGHT
           (grob-interpret-markup grob (markup #:normal-text mrkp))
           0)))
     $music
   #})

{ c''1 \add-to-script \markup "xxxxxxxxxxxxx" \trill }

grob-property-data returns what Script.X-offset is set to in the immutable property alist (what you see listed in scm/define-grobs, namely, script-interface::calc-X-offset ).  ly:grob-property actually runs script-interface::calc-X-offset on the grob.

If you assign X-offset-data _after_ X-offset, both will return the calculated value, because ly:grob-property-data checks the mutable properties alist first for X-offset, where the results of the calculation are now stored.

You can see what's going on in lily/grob-property.cc.

And why it does not happen with 2.16?

Don't know why there's a difference.  I wonder if Janek's work relates to this.
 

> If you define X-offset
> using ly:grob-property-data you'll see no change.

Thanks for the hint!
I'll need to dig in deeper ...

>
> I actually have a patch to add to the docstring of ly:grob-property
> something about this.  I was wondering--too obscure?  No, I don't think so!

+1

It's not much (in keeping with the brevity there), but I think the "callbacks are processed" should be mentioned.

Hope this is helpful!

--David

reply via email to

[Prev in Thread] Current Thread [Next in Thread]