On 2021-05-14 6:40 pm, Ralph Palmer wrote:
> Excellent! Thank you, Aaron. I wish I could understand what your
> function
> does - how it works.
The technique involves querying the current Score.repeatCommands and
replacing any existing (volta "...") command with the user-provided
version. This preserves the other repeat commands such as (end-repeat)
and (volta #f).
Here is a minorly-refactored version with some documentation, comments,
and a helpful usage warning:
%%%%
\version "2.22.0"
\include "english.ly"
changeVoltaText =
#(define-music-function
(text) (markup?)
(_i "Replaces the volta text within the currently-set
@code{repeatCommands}.")
(define (volta-text? cmd)
;; Look for the (volta "...") pattern.
(and (pair? cmd)
(eq? 'volta (car cmd))
(markup? (cadr cmd))))
(define (replacer cmd)
(if (volta-text? cmd) `(volta ,text) cmd))
(define (proc ctxt)
(let ((cmds (ly:context-property ctxt 'repeatCommands '())))
(if (any volta-text? cmds)
(ly:context-set-property! ctxt 'repeatCommands (map replacer cmds))
(ly:input-warning (*location*) "No volta text was replaced."))))
#{ \context Score \applyContext #proc #})
test = {
\time 3/4
\repeat volta 3
{
a'4 b' c' |
\changeVoltaText "dud"
#(ly:expect-warning "No volta text was replaced.")
b'4 c' d' |
}
\alternative {
{
\changeVoltaText "1., 3."
e'4 f' g' |
}
{
d'4 c' b' |
}
{
\changeVoltaText \markup \with-color #red "4."
g'4 a' b' |
}
}
c'1
}
\score {
\test
}
%%%%
-- Aaron Hill
Thanks for this modification, Aaron Hill.
Ralph