Am 01.04.26 um 17:44 schrieb Lukas-Fabian Moser:
But this is all modulo a little change in the C++ source of the Stanza_number_engraver. That engraver would be a good candidate for getting moved to Scheme so it can be customized ...

This would lead to:

The version I posted had the drawback that mid-line \set stanza = ... didn't work anymore. Here's a slightly more sophisticated version that can also be configured.

But there's one problem: Each Lyric syllable gets a StanzaNumber grob, which takes up space. I do not know at the moment how it might be possible to avoid that.

\version "2.24"

#(define define-context-property (@@ (lily) translator-property-description))

#(define-context-property 'repeatStanzaFormatter procedure? "Procedure that re-formats a stanza number if it is auto-repeated.")

#(define (New_stanza_number_engraver context)
  (let
   ((stanza-grob #f)
    (force-display #f)
    (last-stanza '()))
   (make-engraver
    ((process-music engraver)
     (let ((stanza (ly:context-property context 'stanza)))
       (when (markup? stanza)
         (if (eq? stanza last-stanza)
             (set! stanza
                   ((ly:context-property context 'repeatStanzaFormatter (const #f))
                    stanza))
             (begin
              (set! last-stanza stanza)
              (set! force-display #t))))
       (when (markup? stanza)
         (set! stanza-grob
               (ly:engraver-make-grob engraver 'StanzaNumber '()))
         (when force-display
           (ly:grob-set-property! stanza-grob 'begin-of-line-visible #f))
         (ly:grob-set-property! stanza-grob 'text stanza))))
    (acknowledgers
     ((lyric-syllable-interface engraver lyric-grob source-engraver)
      (when stanza-grob
        (ly:pointer-group-interface::add-grob stanza-grob
                                              'side-support-elements
                                              lyric-grob))))
    ((stop-translation-timestep engraver)
     (set! force-display #f)
     (set! stanza-grob #f)))))


\layout {
  \context {
    \Lyrics
    \remove Stanza_number_engraver
    \consists #New_stanza_number_engraver
    % repeatStanzaFormatter = #(lambda (text) (markup #:concat ("(" text ")")))
    repeatStanzaFormatter = #identity
    \override StanzaNumber.after-line-breaking = #ly:chord-name::after-line-breaking
    \override StanzaNumber.begin-of-line-visible = ##t
  }
}

<<
  \new Staff {
    \repeat unfold 30 c'1
  }
  \new Lyrics \lyricmode {
    \set stanza = "1."
    \repeat unfold 15 { oh my }
  }
  \new Lyrics \lyricmode {
    \set stanza = "2."
    \repeat unfold 15 { I won't }
  }
  \new Lyrics \lyricmode {
    \set stanza = "3."
    Hi I should \set stanza = "3a." be visible.
  }
>>


Reply via email to