[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Changing volta number text
From: |
Aaron Hill |
Subject: |
Re: Changing volta number text |
Date: |
Fri, 14 May 2021 19:26:01 -0700 |
User-agent: |
Roundcube Webmail/1.4.9 |
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
- Changing volta number text, Ralph Palmer, 2021/05/14
- Re: Changing volta number text, Peter Chubb, 2021/05/14
- Re: Changing volta number text, Kieren MacMillan, 2021/05/18
- Re: Changing volta number text, Ralph Palmer, 2021/05/18
- Re: Changing volta number text, Kieren MacMillan, 2021/05/18
- Re: Changing volta number text, Carl Sorensen, 2021/05/18
- Re: Changing volta number text, Jean Abou Samra, 2021/05/18
- Re: Changing volta number text, Carl Sorensen, 2021/05/19
- Re: Changing volta number text, Ralph Palmer, 2021/05/20