lilypond-user
[Top][All Lists]
Advanced

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

Re: how to define a boolean?


From: Mark Polesky
Subject: Re: how to define a boolean?
Date: Sat, 8 Aug 2009 12:00:19 -0700 (PDT)

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.

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

\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
}



      




reply via email to

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