I've tried the snippet on some other code and found it faulty while working
with multi part instrument system. So I've tried to change some of the
\textMark and \textEndMark to \markup where it is useful.

The snippet is discriminated with start and end in the example.
Note to self: the "sectionMax" tag is meant for the highest priority tag
for a grid system. I'm pretty much sure this way of coding is faulty... but
it is to the best of my ability to do so.

%%CODE STARTS
%
\version "2.25.25"
%
%%SNIPPET STARTS
ritornello =
#(define-music-function
  (voltas music)
  (number? ly:music?)
  (let* (
         ;; List of volta numbers from 1 to (voltas - 1)
         (volta-list (iota (- voltas 1) 1))
         ;; For each pass, generate a \volta block with markup
         (volta-marks
           (map
             (lambda (n)
               #{ \volta #(list n) {
                    <>^\markup {\italic \concat { #(number->string (+ n 1))
"º" "v.:" } }
                  } #})
             volta-list))
        )
    ;; Main function body
    #{
      \repeat volta #voltas {
        \tag #'unScore  {
          \volta #'(1) {
            <>^\markup \bold \italic "Start of theme"
          }
        }
        #music
        \tag #'folScore {
          \textEndMark \markup \bold {\concat { #(number->string voltas)
"x" } }
        }
        \tag #'unScore {
          #@volta-marks }
      }
      %\tag #'(unScore) { <>^\markup "Pivot" } % As at the same time it
seems most unwanted and stupid, some examples make me alter it to have
usability.
    #}
  )
)
%%SNIPPET ENDS
%
guitarNotes = {\relative c' {
    \ritornello 4 {
      \repeat unfold 2 {g,8 fis e e}
      \repeat unfold 2 {c' b a a}
    } % end ritornelo
    \tag #'(sectionMax) { \textMark \markup \box \bold "Bridge" }
    <a e'>1
  } % fim relative
} % fim guitarNotes
%
guitar = {
<<
  \new Staff {\transpose c c' {{\guitarNotes}}}
  \new TabStaff \keepWithTag #'(void) {\guitarNotes}
>>
} % fim guitar
%
batUp = {\drummode {
  \ritornello 6 {
  \time 3/4
  \repeat unfold 1 {hh4 hh8 <sn> hh4}
  \time 2/4
  {hh4 <hh sn>4}
  } % unfold
  \time 2/4
  hh4 hh4
  \tag #'section { \textMark \markup \box \bold "Bridge" }
  \time 4/4
  hh1
 } % fim drummode
} % fim batUp
%
batDown = {\drummode {
  \repeat volta 6 {
  \repeat unfold 1 {bd4 r r}
  {bd4 r}
  } % fim repeat unfold
  r8 bd8 r8 bd8
  %
  bd1
 } % fim drummode
} % fim batUp
%
bateria = {
\new DrumStaff \with { \consists Merge_rests_engraver } {
<<
\new DrumVoice = "up" {\voiceOne \batUp }
\new DrumVoice = "down" {\voiceTwo \batDown }
>>
} % fim DrumStaff
} % fim drums
%
grade = {
<<
  \guitar
  \removeWithTag #'highlight {\bateria}
>>
} % fim grade
%
\score { \removeWithTag #'unScore {\guitar} }
\score { \removeWithTag #'unScore {\bateria} }
\score { {\unfoldRepeats {\removeWithTag #'(folScore section) {\grade}}}
\layout { \enablePolymeter } }
%
%%CODE ENDS



Em seg., 18 de ago. de 2025 às 16:01, Lucas Cavalcanti <[email protected]>
escreveu:

> 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