lilypond-devel
[Top][All Lists]
Advanced

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

Re: Get context from a Grob


From: Thomas Morley
Subject: Re: Get context from a Grob
Date: Sat, 22 Oct 2016 10:55:08 +0200

2016-10-21 16:39 GMT+02:00 Carl Sorensen <address@hidden>:
> After way too much calendar time (I have very little time for working on 
> LilyPond -- either development or music) I have come up with an architecture 
> that I think will work well with the dot-column problem.
>
> I want to move the dot-column calculation to a Scheme procedure.  This will 
> facilitate users creating their own algorithm for allocating dots if they 
> don't like either of the two procedures I will provide (one is Gould, the 
> other is what was wanted by the lists in our discussion about it).
>
> In order to do this, I need a property that holds the procedure used to 
> format the dot column.  When I did a similar thing with fretboards, I made a 
> context property and used that for the procedure.  I thought I could do this 
> here.
>
> However, when I'm formatting the dot column, I'm not in an engraver.  I'm in 
> a Scheme callback (Dot_column::calc_positioning_done).  As far as I can see, 
> I only have a Grob, not a Grob_info available.  So I don't see a way to get a 
> pointer to
> the context.
>
> Is there any way to get the context from a Grob in C++?
>
> If there isn't a way to do this, I can create a grob property, and use that.  
> But I think it would be cleaner to use a context property.
>
> Thanks in advance for any help.
>
> Carl



Hi Carl,

I don't know C++, so it may not help you, though I thought I should
share same thoughts doing things from scheme:

foo =
\context Staff
\applyContext
  #(lambda (ctx)
    (format #t "\ncontext where foo applied: ~a" ctx)
    (ly:context-pushpop-property ctx 'DotColumn 'before-line-breaking
      (lambda (grob)
        (ly:grob-set-property! grob 'positioning-done
          (lambda (grob)
            (ly:dot-column::calc-positioning-done grob)
            (ly:grob-translate-axis! grob 15 X)
            #t))
        (ly:grob-set-property!
          (ly:grob-array-ref (ly:grob-object grob 'dots) 1)
          'color
          red))))

undoFoo =
\context Staff
\applyContext
  #(lambda (ctx)
    (ly:context-pushpop-property ctx 'DotColumn 'before-line-breaking))

{
    \foo
    <c' d' e'>2. d'4
    \undoFoo
    <c' d' e'>2. d'4
}

buzz =
\applyOutput Staff.DotColumn
  #(lambda (grob ctx c)
    (format #t "\ngrob: ~a" grob)
    (format #t "\nctx: ~a" ctx)
    (format #t "\nc: ~a" c)
    (ly:grob-set-property! grob
      'before-line-breaking
      (lambda (grob)
        (ly:grob-set-property! grob 'positioning-done
          (lambda (grob)
            (ly:dot-column::calc-positioning-done grob)
            (ly:grob-translate-axis! grob 15 X)
            #t))
        (ly:grob-set-property!
          (ly:grob-array-ref (ly:grob-object grob 'dots) 1)
          'color
          cyan))))


\new Score {
    \buzz
    <c' d' e'>2. d'4
    \undo \buzz
    <c' d' e'>2. d'4
}

Cheers,
  Harm



reply via email to

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