lilypond-user
[Top][All Lists]
Advanced

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

Re: Scheme predicative types


From: Aaron Hill
Subject: Re: Scheme predicative types
Date: Wed, 16 Sep 2020 16:13:07 -0700
User-agent: Roundcube Webmail/1.4.2

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
====


-- Aaron Hill



reply via email to

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