lilypond-user
[Top][All Lists]
Advanced

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

Re: Scheme global variables in Lilypond


From: Nick Payne
Subject: Re: Scheme global variables in Lilypond
Date: Wed, 02 Jan 2013 06:08:13 +1100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

On 01/01/13 20:21, David Kastrup wrote:
Nick Payne <address@hidden> writes:

In the following lilypond code, why is the value of the scheme
variable dirn not being changed by the set! command in the updown
function? The updown function is called on the first line of
beginStringNum,
No, it isn't.

beginStringNum = #(define-event-function (parser location strng)
   (number?)
   #{
     \tweak direction #updown
It is _referenced_ on the first line of beginStringNum, and the function
reference is put into the direction field of the grob eventually created
by the event created by \startTextSpan, and when this direction field
gets _referenced_ eventually, updown is finally called.

[...]

     \startTextSpan
   #}

When I add \displayLilyMusic to some simplified code

%==============
\version "2.17.6"

#(define dirn 1)

#(define (updown grob)
  (let ((ud (ly:event-property (event-cause grob) 'direction)))
    (if (eq? -1 ud)
      (begin
        (set! dirn DOWN)
        DOWN)
      UP)))

beginStringNum = #(define-event-function (parser location strng)
  (number?)
  #{
    \tweak direction #updown
    \tweak bound-details.right.text \markup {
      \draw-line #(cons 0 (/ dirn -2)) }
    \startTextSpan
  #}
)
endStringNum = \stopTextSpan

\relative c' {
  \displayLilyMusic { c4_\beginStringNum 5 c c c\endStringNum }
}
%==============

I get this shown on the console:

{ c-\tweak direction #updown -\tweak #t.(bound-details right text) #'(#<procedure line-markup (layout props args)> ((#<procedure draw-line-markup (layout props dest)> (0 . -1/2)))) _\startTextSpan c c c\stopTextSpan }

Does that mean that the hardcoded initial value of the dirn variable is being substituted in the second tweak before the updown function is called? That would explain what I'm seeing.



reply via email to

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