lilypond-user
[Top][All Lists]
Advanced

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

Re: tempo percentage


From: Gianmaria Lari
Subject: Re: tempo percentage
Date: Mon, 27 Nov 2017 07:39:46 +0100


On 27 November 2017 at 00:24, David Kastrup <address@hidden> wrote:
Gianmaria Lari <address@hidden> writes:

> On 8 November 2017 at 18:15, David Kastrup <address@hidden> wrote:
>
>> Gianmaria Lari <address@hidden> writes:
>>
>> > Talking about midi, is there any way to to reduce or increase the tempo
>> of
>> > some measures by a certain percentage instead of setting it to an
>> absolute
>> > value?
>> >
>> > For example instead of:
>> >
>> > \tempo 4=100 a b c d
>> > \tempo 4=110 e f g a
>> >
>> >
>> > something like
>> >
>> > \tempo 4=100 a b c d
>> > \tempo 4=currentTempo*1.1 e f g a
>> >
>>
>> Well, it's not pretty (but then one can try wrapping the prettiness into
>> a music function), but here goes:
>
> I tried to make it pretties. Here it is the code:
>
> \version "2.19.80"
> increaseTempo =
> #(define-music-function (factor)(number?) #{
>   \context Timing \applyContext
>   #(lambda (c)
>        (set! (ly:context-property c 'tempoWholesPerMinute)
>              (ly:moment-mul (ly:context-property c 'tempoWholesPerMinute)
>                (ly:make-moment factor))))
>
>    #} )
>
> \score {
>   {
>     \tempo 4=100
>     a b c' d'
>     \increaseTempo 3
>     e' f' g' a'
>   }
>   \midi {}
>   \layout {}
> }
>
> This works ok only when \increaseTempo argument is integer. If i try
> \increaseTempo 2.5 it doesn't work. How to fix it?

You need exact numbers.  So \increaseTempo ##e2.5 should work.  Which is
equivalent to \increaseTempo #5/2 .

Either that, or you write instead of factor something like
(rationalize (inexact->exact factor) #e0.0001)

--
David Kastrup

Dear David, thank you for your help. Both solution works perfectly. 

I checked online for the rationalize and inexact->exact and now this is clear. But why don't simply round or trunc the function argument? And what's about the other syntax #a/b?

I copy here the complete code so that others can take advantage of it.

%%%%% Increase tempo using a "fraction" argument
\version "2.19.80"
increaseTempo = 
#(define-music-function (factor)(number?) #{
  \context Timing \applyContext
  #(lambda (c)
       (set! (ly:context-property c 'tempoWholesPerMinute)
             (ly:moment-mul (ly:context-property c 'tempoWholesPerMinute)
               (ly:make-moment factor))))
   #} )

\score {
  {
    \tempo 4=100
    a b c' d'
    \increaseTempo ##e2.5 %equivalent to \increaseTempo #5/2
    e' f' g' a'
  }
  \midi {}
  \layout {}
}

%%%%% Increase tempo using 
increaseTempo = 
#(define-music-function (factor)(number?) #{
  \context Timing \applyContext
  #(lambda (c)
       (set! (ly:context-property c 'tempoWholesPerMinute)
             (ly:moment-mul (ly:context-property c 'tempoWholesPerMinute)
               (ly:make-moment (rationalize (inexact->exact factor) #e0.0001)))))
   #} )

\score {
  {
    \tempo 4=100
    a b c' d'
    \increaseTempo 2.5
    e' f' g' a'
  }
  \midi {}
  \layout {}
}

Thank again, g.

reply via email to

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