lilypond-user
[Top][All Lists]
Advanced

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

Re: How to pass a fraction as a parameter for a Scheme function


From: David Kastrup
Subject: Re: How to pass a fraction as a parameter for a Scheme function
Date: Tue, 09 Jun 2020 22:10:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Paolo Prete <paolopr976@gmail.com> writes:

> Hello,
>
> I don't understand how to use a fraction as a parameter for a scheme
> function. More specifically, this gives me an error:
>
> %%%%%%%%%%%%
>
> proportionalNotationDur = #(define-music-function (parser location frac)
> (scheme?)                          #{ \set
> Score.proportionalNotationDuration = #(ly:make-moment frac) #})
> {
>   \proportionalNotationDur 1/16
>   c' c' c' c'
> }
>
> %%%%%%%%%%%%
>
> How can I fix it?
> Thanks!

A fraction is a number _pair_ (because \time 4/4 is different from \time
2/2), not rational number.  For ly:make-moment, you need to convert to a
rational number or two integers.  The predicate should really, really,
really cater to the correct type: scheme? is just asking for trouble.

Personally, I'd rather use a duration in order to write 16 instead of
1/16 and 16*3 instead of 3/16.

But for the usage you want, one can do

proportionalNotationDur =
#(define-music-function (parser location frac) (fraction?)
    #{ \set Score.proportionalNotationDuration = #(fraction->moment frac) #})
{
  \proportionalNotationDur 1/16
  c' c' c' c'
}


-- 
David Kastrup



reply via email to

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