[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: |
Thu, 17 Sep 2020 00:47:37 -0700 |
User-agent: |
Roundcube Webmail/1.4.2 |
On 2020-09-17 12:08 am, Martín Rincón Botero wrote:
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?
Strings are primitive markup, so you just need to convert things into
strings. The only time you need to do more is if you want to adjust the
formatting/styling of the markup.
Here is an update to the code I posted earlier that reformats a \tempo
command into \markup, which should hopefully demonstrate this:
%%%%
\version "2.20.0"
#(define (tempo? arg)
(and (ly:music? arg)
(not (null? (extract-typed-music arg 'tempo-change-event)))))
describeTempo =
#(define-scheme-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:~{\t~s=~s~^\n~}"
(list 'tempo-unit tempo-unit
'metronome-count metronome-count
'text text))
(set! tempo-unit
(if (ly:duration? tempo-unit)
#{ \markup \box #(ly:duration->string tempo-unit) #}
#{ \markup unspecified #}))
(set! metronome-count
(cond ((number-pair? metronome-count)
#{ \markup { between
\box #(format #f "~d" (car metronome-count)) and
\box #(format #f "~d" (cdr metronome-count)) } #})
((number? metronome-count)
#{ \markup { exactly
\box #(format #f "~d" metronome-count) } #})
(else #{ \markup unspecified #})))
(set! text
(if (markup? text)
#{ \markup \box #text #}
#{ \markup unspecified #}))
#{
\markup \pad-around #1 \column {
\line { \italic tempo-unit is #tempo-unit }
\line { \italic metronome-count is #metronome-count }
\line { \italic text is #text }
}
#}))
\describeTempo \tempo 4 = 50
\describeTempo \tempo "Text" 8. = 60-70
\describeTempo \tempo \markup \bold "Text"
%%%%
====
GNU LilyPond 2.20.0
Processing `tempo-function.ly'
Parsing...
Tempo: tempo-unit=#<Duration 4 >
metronome-count=50
text=#f
Tempo: tempo-unit=#<Duration 8. >
metronome-count=(60 . 70)
text="Text"
Tempo: tempo-unit=#f
metronome-count=#f
text=(#<procedure bold-markup (layout props arg)> "Text")
Finding the ideal number of pages...
Fitting music on 1 page...
Drawing systems...
Layout output to `tempo-function.cropped.eps'...
Converting to PNG...
Deleting `tempo-function.cropped.eps'...
Success: compilation successfully completed
====
-- Aaron Hill
tempo-function.cropped.png
Description: PNG image
- Scheme predicative types, Martín Rincón Botero, 2020/09/16
- Re: Scheme predicative types, Lukas-Fabian Moser, 2020/09/16
- Re: Scheme predicative types, Lukas-Fabian Moser, 2020/09/17
- Re: Scheme predicative types, Aaron Hill, 2020/09/17
- Re: Scheme predicative types, Aaron Hill, 2020/09/17
- Re: Scheme predicative types, Lukas-Fabian Moser, 2020/09/17
- Re: Scheme predicative types, Aaron Hill, 2020/09/17
- Re: Scheme predicative types, Martín Rincón Botero, 2020/09/17
- Re: Scheme predicative types, Aaron Hill, 2020/09/17
- Re: Scheme predicative types, Martín Rincón Botero, 2020/09/18
- Re: Scheme predicative types, Martín Rincón Botero, 2020/09/18