lilypond-user
[Top][All Lists]
Advanced

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

Re: Context question


From: Lukas-Fabian Moser
Subject: Re: Context question
Date: Sun, 11 Sep 2022 23:12:18 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

Hi Johan,

Am 11.09.22 um 23:01 schrieb John Schlomann:

Can someone please explain why the following won’t work. I want get the current moment at the end of the music _expression_. Is this not a valid thing to do? Or perhaps I don’t know how to specify the context. This code gives an unbound variable error.

 

\version "2.22.2"

 

\score {

  \relative c'' {

    \new Staff {

      a b c d

      #(display (ly:context-current-moment Staff))

    }

  }

}


Try:

\version "2.22.2"

\score {
  \relative c'' {
    \new Staff {
      a b c d
      \applyContext #(lambda (ctx)
                       (display (ly:context-current-moment ctx)))
    }
  }
}

There are better people than I on this list to explain _why_ it has to be done this way - I'm sure I'd get the explanation not 100% correct. Basically, if my mental image is somewhat correct, it has to do with the fact that at the point of time where LilyPond interprets your music, there is no context (yet) and no current moment. So we have to provide a _function_ that is evaluated later, depending on the (then current) context. That context will usually be a Voice context, as can be seen by adding a

(display (ly:context-name ctx))

command in your function. If you want to force your lambda function to be evaluated in another context (e.g. Staff), you can write \context Staff \applyContext ... - but this is rarely needed, since (again: in my understanding) contexts form a hierarchy, and you can access higher-level context properties also from your Voice context.

And now I'll get ready for a bunch of corrections from Jean, David K., Valentin and others :-).

Lukas


reply via email to

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