Hello! Over the last two years I've been *really* using Lilypond to write
scores, one situation came when creating unfolded scores: I'd always repeat
the guitar and bass guitar parts for four times, but the drums would be
doing something different each time - or they would be doing a
polimetric part. So when viewing the unfolded score with all instruments it
would become hard to spot the repetitions of the guitar and bass parts.

I realized that using markup would be tedious and counterproductive,
because I'd have to manually intervene and make the score much more prone
to errors. So today I co-wrote (with ChatGPT's help) a snippet that does
exactly what I wanted: the volta repetitions are indicated without the need
for markups.

I guess this isn't "vibe coding" (especially because I reviewed the code,
making sure it runs), but my knowledge of Scheme is almost negligible... So
I thought it'd be better to share and get some feedback.

The only downside of using this snippet is the need to remove some tags of
the variable being used in the \score block. This isn't much a hassle *for
me... *but I can see some reasons this isn't so great.

%%CODE STARTS
\version "2.24.0"
%
%%SNIPPET STARTS
ritornello =
#(define-music-function
  (voltas music)
  (number? ly:music?)
  (let* (
         ;; List of volta numbers from 1 to (voltas - 1) so that we mark
passes 1 to (voltas - 1), showing n+1 in the text.
         (volta-list (iota (- voltas 1) 1))
         ;; For each pass, generate a \volta block with aditional strings.
         (volta-marks
           (map
             (lambda (n)
               #{ \volta #(list n) {
                 \textMark \markup {\italic \concat { #(number->string (+ n
1)) "ยบ" "v.:" } }
               } #})
             volta-list))
        )
    ;; folScore is the tag to be used in folded scores, as it prints only
the total numbers of volta in the last measure.
    ;; unScore is the tag to be used in unfolded Scores, as it prints every
start of volta.
    #{ % main function body
      \repeat volta #voltas {
        \tag #'unScore  { \volta #'(1) {\textMark \markup \bold \italic
"Start of theme"}}
        #music
        \tag #'folScore {\textEndMark \markup \bold {\concat {
#(number->string voltas) "x" } }}
        \tag #'unScore  { #@volta-marks }
      }
      \tag #'unScore  {{\textEndMark \markup \bold \italic "End of theme"}}

    #} ;; end of main function body
    ) ;; end of let*
  ) % end of ritornello function
%
%%SNIPPET ENDS
%
var = {\relative c'' {c1 d e d}}
test = { \ritornello 10 {\var} }
%
\score {\removeWithTag #'unScore {\test}}
\score {\removeWithTag #'folScore {\unfoldRepeats {\test}}}
%%CODE ENDS

Reply via email to