Mark Polesky schrieb:
Marc Hohl wrote:

Thank you! At least I can play with this ...
The callback is a little trickier for me for the moment.
I'll get back to you.
Great. I am awaiting your response.

Man, this stuff is tricky. Here's the best I can do for right
now. I commented out the third line of myfunc; I wasn't sure
how it made sense. Note that a music-function must return
music. So you can only use ly:parser-define! *before* the
music block. I couldn't get the callback to talk with the
parser, so I made a callback that accepts the boolean value
from within the music block itself.
Thanks again for your help, Mark!
One caveat: whenever the value of a parser variable is
modified (anywhere), it affects everything below, and is
not confined to any local scope. You can \include a \score
from another directory entirely, and the included score
will use the modified value.

Will this work for you?
- Mark
Not yet, sorry. I played around a bit with your solution, but it doesn't fit
perfectly. But at least, I gain more and more insight in lily's internals...
(just a bit of comfort ;-)

I need a music-function which (aside from other tasks it fulfils) sets a boolean to #t; moreover, a customized stencil callback looks if this value is set to #t and performs a special action depending of the value, then the callback /itself/
has to set the boolean to #f.

Is this possible?

As I can see from now, giving mybool as an argument won't work in this case,
because any change won't be recognized until a next \override.

Marc


\version "2.13.4-1"

#(define mybool #f)

myfunc =
#(define-music-function (parser location note) (ly:music?)
  ;(ly:parser-define! parser 'mybool #t)
  (let* ((mybool (ly:parser-lookup parser 'mybool))
         (color  (if mybool red blue)))
    #{
      \once \override  NoteHead #'color = $color
      $note
    #}))

#(define-public (custom-callback mybool)
  (lambda (grob)
    (if mybool green yellow)))

\relative c'' {
  #(set! mybool #t)
  \myfunc c

  % ugh... dummy scheme object to cope with parser-lookahead.
  % Notice what happens when it's commented out.
  #0

  #(set! mybool #f)
  \myfunc c

  \override NoteHead #'color = #(custom-callback mybool)
    c c

  % if you change the parser variable, you have to call the \override
  % again - the callback arg doesn't get updated on-the-fly
  #(set! mybool #t)
  \override NoteHead #'color = #(custom-callback mybool)
    c c
}






_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to