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 11:32:03 +0100



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

> On 27 November 2017 at 09:32, David Kastrup <address@hidden> wrote:
>
>> Gianmaria Lari <address@hidden> writes:
>> >
>> > Another question. It would be also useful to have a function that
>> > increase the tempo by a certain quantity (instead of a certain
>> > factor).
>> >
>> > I tried to modify the previous code in many ways using moment-add and
>> > make-moment but without success. This is an example that does not work:
>> >
>> > (ly:moment-add (ly:context-property c 'tempoWholesPerMinute) value)
>> >
>> >
>> > Any suggestion?
>>
>> Scheme has no types known as "quantity".  Neither has LilyPond.  You
>> don't show how you get at `value'.
>>
>> <URL:http://lilypond.org/tiny-examples.html>
>>
>
> For example:
>
> \version "2.19.80"
> increaseTempo =
> #(define-music-function (value)(number?) #{
>   \context Timing \applyContext
>   #(lambda (c)
>      (set! (ly:context-property c 'tempoWholesPerMinute)
>            (ly:moment-add (ly:context-property c 'tempoWholesPerMinute)
> value)
>            ))
>    #} )
>
>
> \score {
>   {
>     \tempo 4=100
>     a b \increaseTempo 50 c' d'
>   }
>   \layout {} \midi{}
> }

Any reason you don't take the previous working code, just replacing
ly:moment-mul with ly:moment-add (and factor with value if you want more
readable code, but for the first attempt you can skip this)?

Ahem..... you're right! I was thinking that 

  (rationalize (inexact->exact factor) #e0.0001)

would not make any sense and I removed it. So, now this is the working code:

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

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

Now, I simplified

(ly:make-moment (rationalize (inexact->exact factor) #e0.0001)))))

to this

(ly:make-moment (rationalize factor #e0.0001)))))

and then to this:

(ly:make-moment factor ))))

Everything continues to compile and work. Great! Of course, I did something similar before, but I'm not used to so much brackets and the lilypond error are not very clear too. So I'm not able to say way it didn't work :(

I put here the complete code in case other need it.

\version "2.19.80"
increaseTempo = 
#(define-music-function (value)(number?) #{
  \context Timing \applyContext
  #(lambda (c)
       (set! (ly:context-property c 'tempoWholesPerMinute)
             (ly:moment-add (ly:context-property c 'tempoWholesPerMinute)
               (ly:make-moment value ))))
   #} )

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

Thanks a lot David for your kind help!
Gianmaria

reply via email to

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