lilypond-user
[Top][All Lists]
Advanced

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

Re: ly:grob-basic-properties confusion (bug?)


From: Patrick McCarty
Subject: Re: ly:grob-basic-properties confusion (bug?)
Date: Thu, 9 Apr 2009 21:24:48 -0700
User-agent: Mutt/1.5.18 (2008-05-17)

On Thu, Apr 09, 2009 at 12:06:14AM -0700, Mark Polesky wrote:
> 
> I was trying to see if I could access a grob's stencil from within a 
> callback without actually knowing what the grob is. I know it sounds
> pointless, but there's a good reason. Anyway, my approach was:
> 
> 1) get the grob's immutable properties with ly:grob-basic-properties.
> 2) from that alist, access the 'stencil property (which I assumed would
>     be a #<primitive-procedure>) using ly:assoc-get.
> 3) call the retrieved function with grob to return its stencil.
> 
> Just to be clear, the expected result of the following code was 
> *nothing*. Just trying to set a stencil to itself:
> 
> \relative c'' {
>   \override Staff.Clef #'stencil =
>     #(lambda (grob)
>       (let ((f (ly:assoc-get 'stencil (ly:grob-basic-properties grob))))
>        (f grob)))
>      c
> }
> 
> Well, that didn't work (LP nearly froze), so I debugged with display:
> 
> \relative c'' {
>   \override Staff.Clef #'stencil =
>     #(lambda (grob)
>       (let ((f (ly:assoc-get 'stencil (ly:grob-basic-properties grob))))
>        (display f)
>        (ly:clef::print grob)))
>      c
> }
> 
> Of course this works. But interestingly (display f) returns:
> 
> #<procedure #f (grob)>#<procedure #f (grob)>
>   
> No idea what's going on. I looked at ly_assoc_get in general-scheme.cc,
> but I wouldn't know a C++ bug if it flew in my eye. So then I tried:
> 
> #(use-modules (ice-9 pretty-print))
> 
> \relative c'' {
>   \override Staff.Clef #'stencil =
>     #(lambda (grob)
>       (let ((basic-props (ly:grob-basic-properties grob)))
>        (pretty-print basic-props)
>        (ly:clef::print grob)))
>      c
> }
> 
> Here the alist is displayed twice, but even stranger (to me), there are 
> two entries for stencil...
> 
> ((glyph . "clefs.G")
>  (stencil . #<procedure #f (grob)>)
>  (stencil . #<primitive-procedure ly:clef::print>)
>  etc.
> 
> All of the other grobs I tested had the same issue. So when I retrieve
> 'stencil with ly:assoc-get, it gets the first one, but obviously I want
> the ly:<grob>::print one.
> 
> What's going on? And how can I safely get the entry I mean to get?

The moment you do a

#(lambda (grob) ...)

a new anonymous procedure is created, which is what the
#<procedure #f (grob)> line means.

After analyzing the pretty-print output, it looks like user \overrides
are pushed to the front of the alist, so that's why the
#<primitive-procedure ly:clef::print> line is still there, *after* the
user override.

As a side note, (glyph . "clefs.G") is not in the list at first, but
it is added later by the Clef_engraver (lily/clef-engraver.cc).

I don't think that the alist being printed twice is an issue.  Maybe
the 'stencil properties are read twice?

I'm not sure how to achieve what you're after, but hopefully this
helps a little.


-Patrick




reply via email to

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