lilypond-devel
[Top][All Lists]
Advanced

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

Re: change clef inside a grob-callback?


From: Joe Neeman
Subject: Re: change clef inside a grob-callback?
Date: Fri, 17 Jul 2009 08:13:18 -0700

On Thu, 2009-07-16 at 23:06 -0700, Mark Polesky wrote:
> Joe Neeman wrote:
> > > Is there a way to change the clef from within a grob callback?
> > 
> > Not really. You can change the clef's glyph, but you can't really change
> > the clef's influence on the following notes. 
> 
> I presume you mean I can change the clef stencil, or do you mean that
> it's possible to change the clefGlyph context property? If that were
> the case, then couldn't I change clefPosition and middleCPosition and
> do it that way?

I mean that you can change the clef stencil. Context properties are used
when creating grobs, but they disappear before any grob callback is
likely to be called.

> 
> > ...Reason being, the NoteHead
> > grobs are created around the same time as the Clef grob and their
> > positions are fixed at that time, so unless you want to somehow iterate
> > over and modify all the NoteHeads, it isn't really going to work.
> > 
> > I'd suggest a music function rather than a grob override.
> 
> How? I was using a music function before, but I couldn't find a way to
> get NoteHead staff-positions without a callback. And I get stuck with a 
> music-function because I don't know how to test if I'm in a \relative
> block or not. 
> 
> I guess the algorithmic idea would be:
> 
> *Before* staff-positions are concretely determined...
> 1. what would the staff-positions be if we stayed in this clef?
> 2. if they're within this clef's "staff-range", do nothing.
> 3. if another clef is better (according to user), change the clef.
> 4. determine actual staff-positions with the updated clef info.
> 
> I just don't know how to catch the process before the staff-positions
> are determined, if all I have is a context and a EventChord. I thought
> that if I could at least know whether I'm in a \relative block, I could
> then look at the current clef, and figure it out the long way (not that
> I'd want to). But I imagine there must be an easier way in. And I can't
> test for \relative-ness as far as I can tell anyway.
> 
> Do you have any other (slightly more specific) suggestions? (:

I don't know how to deal with \relative, but it's easy to calculate the
staff-position of an absolute note in a music function:
(+ (ly:pitch-steps pitch-of-the-note) middle-C-position)

If you look at note-heads-engraver.cc, you'll see that the
"staff-position" property is set there using the pitch of the NoteEvent
and the middleCPosition property. So you step 4 of your algorithm above
will be handled by note-heads-engraver, but only if you can figure out
the new clef using only the context and the EventChord. Perhaps a music
function guru can help out with the relative problem?

Joe






reply via email to

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