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: Sun, 17 Nov 2019 15:57:49 -0800
User-agent: Roundcube Webmail/1.3.8

On 2019-11-17 3:10 pm, Aaron Hill wrote:
On 2019-11-17 12:38 pm, Paolo Prete wrote:
Hello,
is it possible to revert a tempo change to the previous tempo setting,
without explicitly writing this previous one? 
Something like (pseudo-code):
\tempo 4 = 120  { ...some music .... } \temporaryTempo 4 = 160 { ...
some other music .... } \unset \temporaryTempo

Not sure if this is really the right way to do things:

Here's a version that is a little safer about unsetting the property as well as emitting a warning when the stack is empty:

%%%%
\version "2.19.83"

#(define tempoStack '())
pushTempo = #(define-music-function () ()
  (define (pushTempoHelper ctx)
    (let ((tempo (ly:context-property ctx 'tempoWholesPerMinute #f)))
      (set! tempoStack (cons tempo tempoStack))))
  #{ \context Score \applyContext $pushTempoHelper #})
popTempo = #(define-music-function () ()
  (define (popTempoHelper ctx)
    (if (null? tempoStack)
(ly:warning "Unable to pop a tempo. Did you forget to \\pushTempo?")
      (let ((tempo (car tempoStack)))
        (set! tempoStack (cdr tempoStack))
        (if tempo
          (ly:context-set-property! ctx 'tempoWholesPerMinute tempo)
          (ly:context-unset-property ctx 'tempoWholesPerMinute)))))
  #{ \context Score \applyContext $popTempoHelper #})

\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 "||"
    \popTempo \tempo "Tempo 0?!"
    { b'4 4 4 4 } \bar "|."
  }
  \layout {} \midi {}
}
%%%%

NOTE: The snippet above intentionally causes a warning to appear.

-- Aaron Hill



reply via email to

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