lilypond-user
[Top][All Lists]
Advanced

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

Re: Accessing context properties (e.g. the current key) from a music fun


From: Leah Velleman
Subject: Re: Accessing context properties (e.g. the current key) from a music function?
Date: Thu, 30 Apr 2015 20:28:53 -0400

To do something like you want, you really would need access to context properties....

Ok — good to know I haven't missed some simple solution. 

It seems like there ought to be some way of smuggling information out of an \applyContext. But I guess there's a variable scope issue that keeps you from doing it straightforwardly:

k = "OOPS"                                                                  
text = #(define-music-function (parser location music) (ly:music?)                   #{                                                                                                                       \applyContext                                                                                                 #(lambda (context)                                                                                           (set! k  (ly:context-property context 'tonic))
      (display k)
    )     
    \transpose #(ly:make-pitch 0 0) #k #music      
  #}                                                      
)                                                                                                                       \score {                                                                                                             \new Staff {                                                                                                       \key a \major                                                                                                   \test { Fa So La fa so }                                                                                 }                                                                                                                     }  

In that code, the (display k) works fine, displaying #<Pitch a>. But then the \transpose #(ly:make-pitch 0 0) #k #music gets ahold of the global definition of #k rather than the local one and so you end up with a type error: expecting pitch, found "OOPS".

So maybe the question is, does Lilypond Scheme have anything like global variables?

reply via email to

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