[Top][All Lists]

[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 =
  (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' |

\score {

-- Aaron Hill

reply via email to

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