lilypond-user
[Top][All Lists]
Advanced

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

Re: Scheme predicative types


From: Martín Rincón Botero
Subject: Re: Scheme predicative types
Date: Thu, 17 Sep 2020 09:08:28 +0200

Thank you Aaron for this explanation of the ly:prob-property! I see a function like ly:duration->string, is there any way to "convert" predicate types like ly:duration and number to markup?

Regards,
Martín. 

Am Do., 17. Sept. 2020 um 01:23 Uhr schrieb Aaron Hill <lilypond@hillvisions.com>:
On 2020-09-16 4:13 pm, Aaron Hill wrote:
> On 2020-09-16 12:09 pm, Lukas-Fabian Moser wrote:
>> I'm sure more knowledgeable people will be able to provide more
>> insightful answers, but for what it's worth: Looking at
>> lily/parser.yy, I see
>>
>> tempo_event:
>>     TEMPO steno_duration '=' tempo_range    {
>>         $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
>>     }
>>     | TEMPO text steno_duration '=' tempo_range    {
>>         $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
>>     }
>>     | TEMPO text {
>>         $$ = MAKE_SYNTAX (tempo, @$, $2);
>>     } %prec ':'
>>     ;
>>
>> which I take to mean: The three forms
>>
>>  * \tempo 4 = 96
>>  * \tempo Crazy 4 = 260-270
>>  * \tempo "Sluggishly slow"
>>
>> are hardcoded as variants into the parser. My guess is that this might
>> be hard (or impossible) to accomplish in a music function.
>
> You just need to be a little creative.  Consider:
>
> %%%%
> \version "2.20.0"
>
> #(define (tempo? arg)
>   (and (ly:music? arg)
>        (not (null? (extract-typed-music arg 'tempo-change-event)))))
>
> doSomethingWithATempo =
> #(define-void-function
>   (tempo)
>   (tempo?)
>   (set! tempo (first (extract-typed-music tempo 'tempo-change-event)))
>   (let ((tempo-unit (ly:prob-property tempo 'tempo-unit #f))
>         (metronome-count (ly:prob-property tempo 'metronome-count #f))
>         (text (ly:prob-property tempo 'text #f)))
>     (format #t "\nTempo: ~s"
>       (list (cons 'tempo-unit tempo-unit)
>             (cons 'metronome-count metronome-count)
>             (cons 'text text)))))
>
> \doSomethingWithATempo \tempo 4 = 60
> \doSomethingWithATempo \tempo "Text" 4 = 60
> \doSomethingWithATempo \tempo "Text"
> %%%%
>
> ====
> GNU LilyPond 2.20.0
> Processing `tempo-function.ly'
> Parsing...
> Tempo: ((tempo-unit . #<Duration 4 >) (metronome-count . 60) (text .
> #f))
> Tempo: ((tempo-unit . #<Duration 4 >) (metronome-count . 60) (text .
> "Text"))
> Tempo: ((tempo-unit . #f) (metronome-count . #f) (text . "Text"))
> Success: compilation successfully completed
> ====

Oops, I meant to include a test case for a tempo range:

%%%%
\doSomethingWithATempo \tempo "Text" 4 = 60-75
%%%%

====
Tempo: ((tempo-unit . #<Duration 4 >) (metronome-count 60 . 75) (text .
"Text"))
====

In summary, tempo-unit is ly:duration?; metronome-count is either
number? or number-pair?; and text is markup?.


-- Aaron Hill



--
www.martinrinconbotero.com

reply via email to

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