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: Marc Hohl
Subject: Re: how to define a boolean?
Date: Sun, 09 Aug 2009 09:20:05 +0200
User-agent: Thunderbird 2.0.0.22 (X11/20090608)

Carl Sorensen schrieb:

On 8/8/09 2:20 PM, "Marc Hohl" <address@hidden> wrote:

Carl Sorensen schrieb:
[...]
For the music-function you can do this:

% you can also do:
% mybool = ##f
#(define mybool #f)
Why not just change this to

#(define-public mybool #f)

then  use mybool everywhere else?
I tried this first, but it seems that it doesn't work inside a
music-function.


This seems to work for me:

#(define-public myBool #t)

myMusicFunc =
#(define-music-function (parser location) ()
    (display "\nIn myMusicFunc\n")
    (display "myBool: ")(display myBool)(newline)
    (set! myBool #f)
    (display "myBool: ")(display myBool)(newline)
    (make-music 'SequentialMusic 'void #t))

\relative c'' {
c4 \myMusicFunc c c c }


Was there something else you were trying to do?
Yes, I have to change the value of myBool within a
stencil callback.

Like this:

\version "2.13.3"

#(define myBool #f)

myMusicFunc =
#(define-music-function (parser location) ()
   (display "\nIn myMusicFunc\n")
   (display "myBool: ")(display myBool)(newline)
   (set! myBool #t)
   (display "switched to myBool: ")(display myBool)(newline)
   (make-music 'SequentialMusic 'void #t))

#(define-public (slur::boolean grob)
 ;; just a test function to try and switch boolean values
   (display "\nWithin callback\n")
   (display "myBool: ")(display myBool)(newline)
   (if myBool
       (display "Actions for #t go here...")
       (display "Actions for #f go here..."))
   (set! myBool #f)
   (display "myBool: ")(display myBool)(newline)
   (ly:slur::print grob))

\layout {
 \context {
   \Voice
   \override Slur #'stencil = #slur::boolean
 }
}

\relative c'' {
   c4 ( c )
   \myMusicFunc
   c ( c )
   c ( c )
   \myMusicFunc
   c ( c )
}

From what I see on the console output, the calls of \myMusicFunc
are evaluated first, so myBool is #t  and the callbacks come in action
afterwards (the first slur claims #t, every other slur reads #f), so
apparently they don't influence each other the way I expected them to do.

Is there any workaround? Mark introduced ly:parser-lookup (earlier in this thread), but this doesn't work for the callback, and his proposal to hand over the boolean by using it as an additional argument for the callback has the disadvantage of having to override the callback again and again every time the boolean switches.

Any clues are appreciated!

Marc
Carl







reply via email to

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