tempo percentage

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

tempo percentage

Gianmaria Lari
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

Thank you, g.

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

Mark Knoop-4
At 14:14 on 08 Nov 2017, Gianmaria Lari wrote:

>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


baseTempo = 100

\relative c' {
  \tempo 4 = #baseTempo
  a b c d
  \tempo 4 = #(inexact->exact (round (* baseTempo 1.1)))
  e f g a
}


--
Mark Knoop

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

David Kastrup
In reply to this post by Gianmaria Lari
Gianmaria Lari <[hidden email]> 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:


\score {
  {
    \tempo 4=100 a b c d
    \context Timing \applyContext
      #(lambda (c)
         (set! (ly:context-property c 'tempoWholesPerMinute)
               (ly:moment-mul (ly:context-property c 'tempoWholesPerMinute)
                              (ly:make-moment #e1.1))))
    e f g a
  }
  \midi {}
}



--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

Gianmaria Lari
Thank you David & Mark!

Mark's solutions looks simpler. Any disadvantages using it comparing to David'one?

Thank you, gianmaria

On 8 November 2017 at 18:15, David Kastrup <[hidden email]> wrote:
Gianmaria Lari <[hidden email]> 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:




--
David Kastrup



_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

David Kastrup
Gianmaria Lari <[hidden email]> writes:

> Thank you David & Mark!
>
> Mark's solutions looks simpler. Any disadvantages using it comparing to
> David'one?

It doesn't do what you asked for, namely setting the tempo in relation
to the _current_ tempo rather than some fixed tempo.

That makes it simpler because it does not need to reference the current
tempo.  If its operation better suits your purposes, that's fine.
However, you shouldn't be mixing both approaches since Mark's solution
_rounds_ the tempo (and \tempo will only accept integers, so using
\tempo basically requires this), so the resulting tempo is nothing you
should use as a reference for further changes.

In particular, you can alternatively multiply and divide
tempoWholesPerMinute by #e1.1 (an "exact" number) and arrive at the
original value.

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

Gianmaria Lari


On 9 November 2017 at 11:04, David Kastrup <[hidden email]> wrote:
Gianmaria Lari <[hidden email]> writes:

> Thank you David & Mark!
>
> Mark's solutions looks simpler. Any disadvantages using it comparing to
> David'one?

It doesn't do what you asked for, namely setting the tempo in relation
to the _current_ tempo rather than some fixed tempo.

:)
 
That makes it simpler because it does not need to reference the current
tempo.  If its operation better suits your purposes, that's fine.
However, you shouldn't be mixing both approaches since Mark's solution
_rounds_ the tempo (and \tempo will only accept integers, so using
\tempo basically requires this), so the resulting tempo is nothing you
should use as a reference for further changes.

In particular, you can alternatively multiply and divide
tempoWholesPerMinute by #e1.1 (an "exact" number) and arrive at the
original value.

Thank you David for the explanation. I understood the difference and now I know when to use your or Mark's one.

Best regards, g.



_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

Gianmaria Lari
In reply to this post by David Kastrup

On 8 November 2017 at 18:15, David Kastrup <[hidden email]> wrote:
Gianmaria Lari <[hidden email]> 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?

Thank you, g.

 

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

David Kastrup
Gianmaria Lari <[hidden email]> writes:

> On 8 November 2017 at 18:15, David Kastrup <[hidden email]> wrote:
>
>> Gianmaria Lari <[hidden email]> 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

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

Gianmaria Lari

On 27 November 2017 at 00:24, David Kastrup <[hidden email]> wrote:
Gianmaria Lari <[hidden email]> writes:

> On 8 November 2017 at 18:15, David Kastrup <[hidden email]> wrote:
>
>> Gianmaria Lari <[hidden email]> 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.

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

Gianmaria Lari
On 27 November 2017 at 07:39, Gianmaria Lari <[hidden email]> wrote:

On 27 November 2017 at 00:24, David Kastrup <[hidden email]> wrote:
Gianmaria Lari <[hidden email]> writes:

> On 8 November 2017 at 18:15, David Kastrup <[hidden email]> wrote:
>
>> Gianmaria Lari <[hidden email]> 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?


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?
Thank you, G.

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

David Kastrup
Gianmaria Lari <[hidden email]> writes:

> On 27 November 2017 at 07:39, Gianmaria Lari <[hidden email]>
> wrote:
>
>>
>> On 27 November 2017 at 00:24, David Kastrup <[hidden email]> wrote:
>>
>>> Gianmaria Lari <[hidden email]> writes:
>>>
>>> > On 8 November 2017 at 18:15, David Kastrup <[hidden email]> wrote:
>>> >
>>> >> Gianmaria Lari <[hidden email]> 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?
>>>
>>
>
> 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>

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

Gianmaria Lari


On 27 November 2017 at 09:32, David Kastrup <[hidden email]> wrote:
Gianmaria Lari <[hidden email]> writes:

> On 27 November 2017 at 07:39, Gianmaria Lari <[hidden email]>
> wrote:
>
>>
>> On 27 November 2017 at 00:24, David Kastrup <[hidden email]> wrote:
>>
>>> Gianmaria Lari <[hidden email]> writes:
>>>
>>> > On 8 November 2017 at 18:15, David Kastrup <[hidden email]> wrote:
>>> >
>>> >> Gianmaria Lari <[hidden email]> 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?
>>>
>>
>
> 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{}
}

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

David Kastrup
Gianmaria Lari <[hidden email]> writes:

> On 27 November 2017 at 09:32, David Kastrup <[hidden email]> wrote:
>
>> Gianmaria Lari <[hidden email]> 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)?

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

Gianmaria Lari


On 27 November 2017 at 10:30, David Kastrup <[hidden email]> wrote:
Gianmaria Lari <[hidden email]> writes:

> On 27 November 2017 at 09:32, David Kastrup <[hidden email]> wrote:
>
>> Gianmaria Lari <[hidden email]> 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

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: tempo percentage

David Kastrup
Gianmaria Lari <[hidden email]> writes:

> On 27 November 2017 at 10:30, David Kastrup <[hidden email]> wrote:
>
>> 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.

For your particular example, that would not have made a difference.  But
you also removed (ly:make-moment ...) .

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user