Dear Aaron,
thanks again for that script! I could successfully adapt part of your script to most of what I wanted. I called the function \tempoTextSpan for use in constructions like rit. _ _ _ _ $new tempo with \startTextSpan \stopTextSpan, and it accepts a left text (e.g. "rit."), a tempo definition (metronome mark), and left and right \halign values. Since this is my second day of ever trying to make a Scheme function at all, there is still a lot I don't know how to do. The thing I couldn't adapt from your script is the Text part, when the user writes a new tempo with a construction like \tempo "Allegro". I suppose I have to somehow put my \once \override TextSpanner #'(bound-details right text) in some sort of conditional so that when the user puts a text, it displays a text, when it's a metronome, a metronome :-), but I couldn't figure out how to adapt what you already had. I also wasn't successful in adding \once \omit Score.MetronomeMark \tempo #tempo-unit = #metronome-count, so that the MIDI can pick up the new tempo mark, if a metronome is given (probably because the new tempo is converted to a markup and can't be used as a "real" tempo definition anymore?). Anyways, with those two features still missing, I'm quite happy with using the syntax shown in the example after the script:
\version "2.20.0"
#(define (tempo? arg)
(and (ly:music? arg)
(not (null? (extract-typed-music arg 'tempo-change-event)))))
tempoTextSpan =
#(define-scheme-function
(leftmarkup tempo lefthalign righthalign)
(markup? tempo? number? number?)
(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))
)
(set! tempo-unit
(if (ly:duration? tempo-unit)
#{ \markup {
\note #(ly:duration->string tempo-unit) #UP
} #} ))
(set! metronome-count
(cond ((number-pair? metronome-count)
#{ \markup {
#(format #f "~d" (car metronome-count)) -
#(format #f "~d" (cdr metronome-count)) } #})
((number? metronome-count)
#{ \markup {
#(format #f "~d" metronome-count) } #})
))
#{
\once \override TextSpanner.bound-details.left-broken.text = ##f
\once \override TextSpanner.bound-details.right-broken.text = ##f
\once \override TextSpanner #'(bound-details left text) = \markup \halign #lefthalign { \abs-fontsize #11 #leftmarkup }
\once \override TextSpanner #'(bound-details right text) = \markup \halign #righthalign { \abs-fontsize #10 \general-align #Y #DOWN #tempo-unit \abs-fontsize #11 \upright {"=" #metronome-count } }
#}))
{
\tempoTextSpan "accel." \tempo 4 = 50 #0 #2
c'1\startTextSpan
c'1
c'1\stopTextSpan
}
Thank you Aaron! Perhaps you or someone else can point me in the right direction for adding the two missing features to the script.
Best regards,
Martín.