[Top][All Lists]

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

Re: Function for note string to fraction?

From: Thomas Morley
Subject: Re: Function for note string to fraction?
Date: Tue, 20 May 2014 00:50:24 +0200

2014-05-19 22:50 GMT+02:00 Peter Bjuhr <address@hidden>:
> On 2014-05-15 15:17, Peter Bjuhr wrote:
> is there already a function that converts a string "4." to the fraction
> '3/8', or the other-way round?
> Maybe it's helpful to know that the string is intended for use with \note, e
> g
> \note #"4." #UP
> and the fraction is intended for use with \set Timing.baseMoment, e g
> \set Timing.baseMoment = #(ly:make-moment 3/8)
> After some research I think I've found a way forward with this:
> In ' scm/define-markup-commands.scm' there's a function/procedure called
> 'parse-simple-duration', which is used to translate from '\note' to
> '\note-by-number'.
> In a similar way I could use that to create the arguments to
> 'ly:make-duration'. And from there it would be easy to get the moment with '
> ly:duration->string'.
> This all leads to an additional question: Is it possible to include and use
> 'parse-simple-duration' in a local script (without copy and pasting it)?

Well, I would have no problem to c/p 'parse-simple-duration', though
yes, it is possible:

#(define (note-to-moment notestr)
   (let ((parsed ((@@ (lily) parse-simple-duration ) notestr)))
        (ly:make-duration (car parsed) (cadr parsed)))))

#(write (note-to-moment "4."))

--> #<Mom 3/8>

Though, quoting guile-manual:
— syntax: @@ module-name binding-name
Refer to the binding named binding-name in module module-name. The
binding must not have been exported by the module. This syntax is only
intended for debugging purposes or as a last resort.



reply via email to

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