Aaron Hill <lilyp...@hillvisions.com> writes:

> 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:

It isn't.  It maintains the "stack" in a global variable rather than
some context property, meaning that when several iterations interlock
(like with tempo being changed in several contexts or in polyrhythmic
situations), chaos will ensue.

>
> %%%%
> \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)
>     (let ((tempo (car tempoStack)))
>       (ly:context-set-property! ctx 'tempoWholesPerMinute tempo)
>       (set! tempoStack (cdr tempoStack))))
>   #{ \context Score \applyContext $popTempoHelper #})
>
> \score {
>   {
>     \markLengthOn
>     \bar "||" \tempo "Andante" 4=90
>     \repeat unfold 2 { b'4 4 4 4 }
>     \bar "||" \pushTempo \tempo "Allegro" 4=140
>     \repeat unfold 2 { b'4 4 4 4 }
>     \bar "||" \popTempo \tempo "a tempo"
>     \repeat unfold 2 { b'4 4 4 4 }
>   }
>   \layout {} \midi {}
> }
> %%%%
>
>
> -- Aaron Hill
>
>

-- 
David Kastrup

Reply via email to