lilypond-user
[Top][All Lists]
Advanced

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

Re: Set a temporary tempo change


From: Aaron Hill
Subject: Re: Set a temporary tempo change
Date: Mon, 18 Nov 2019 16:18:32 -0800
User-agent: Roundcube Webmail/1.3.8

On 2019-11-18 1:44 pm, Thomas Morley wrote:
why wrap it into a music-function?
Only advantage seems to avoid a toplevel-definiton. Is it really an advantage?

It's an advantage for \popTempo as it means *location* is properly set to the use of \popTempo and not its definition.

Mind you, \pushTempo need not be a function.

You omitted throwing the error about redefining existing ones...
Feels safer to have it, but that's just me.

Certainly, there should be safer handling.  How's this:

%%%%
\version "2.19.83"

registerContextProperty = #(define-void-function
  (symbol type? description)
  (symbol? procedure? string?)
  (if (not (equal? #f (object-property symbol 'translation-doc)))
    (ly:error (_ "symbol ~S redefined") symbol))
  (set-object-property! symbol 'translation-type? type?)
  (set-object-property! symbol 'translation-doc description)
(set! all-translation-properties (cons symbol all-translation-properties))
  symbol)

#(define (false-or-moment? x) (or (equal? #f x) (ly:moment? x)))
#(define (false-or-moment-list? x) (and (list? x) (every false-or-moment? x)))

\registerContextProperty tempoStack #false-or-moment-list?
  "A stack to keep track of tempi."

pushTempo = { \context Score \applyContext #(lambda (ctx)
  (let ((tempoStack (ly:context-property ctx 'tempoStack))
        (tempo (ly:context-property ctx 'tempoWholesPerMinute #f)))
(ly:context-set-property! ctx 'tempoStack (cons tempo tempoStack)))) }

popTempo = #(define-music-function () ()
  #{ \context Score \applyContext #(lambda (ctx)
    (let ((tempoStack (ly:context-property ctx 'tempoStack)))
      (if (null? tempoStack)
        (ly:input-warning (*location*)
          (_ "Tempo stack is empty. Did you forget to \\pushTempo?"))
        (let ((tempo (car tempoStack)))
          (ly:context-set-property! ctx 'tempoStack (cdr tempoStack))
          (if (equal? #f tempo)
            (ly:context-unset-property ctx 'tempoWholesPerMinute)
(ly:context-set-property! ctx 'tempoWholesPerMinute tempo)))))) #})

\score {
  {
    \markLengthOn
    \tempo "I. Default"
    { b'4 4 4 4 } \bar "||"
    \pushTempo \tempo "II. Andante" 4=90
    { b'4 4 4 4 } \bar "||"
    \pushTempo \tempo "III. Allegro" 4=140
    { b'4 4 4 4 } \bar "||"
    \popTempo \tempo "Tempo II"
    { b'4 4 4 4 } \bar "||"
    \popTempo \tempo "Tempo I"
    { b'4 4 4 4 } \bar "|."
  }
  \layout {} \midi {}
}
%%%%


-- Aaron Hill



reply via email to

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