2016-07-01 20:43 GMT+02:00 Br. Gabriel-Marie | SSPX <brgabr...@sspx.org>:
> Because stanza numbers only appear on the first line.  Using instrumentName
> to label verse numbers provides automatic numbering on every line.  It
> wasn't my idea, actually, credit for that goes to Thomas Morley  a few
> issues ago in Vol 163:issue 95.  It works quite well.
>
> On 7/1/2016 1:30 PM, lilypond-user-requ...@gnu.org wrote:
>>
>> Why not use StanzaNumbers instead of instrumentName to label verse
>> numbers?


Meanwhile I tried to make StanzaNumber at every line-begin work, see attached.
Though, it's stacking workarounds, thus pretty expensive.
At least it _is_ possible, even now.
Maybe someone steps in futher improving it.

Cheers,
  Harm
\version "2.19.44"

#(define create-stanza-number-grob-engraver
;; puts out a StanzaNumber for every LyricText-grob
  (lambda (context)
   (let ((stanza (ly:context-property context 'stanza)))
     `((acknowledgers
         (lyric-syllable-interface .
           ,(lambda (engraver grob source-engraver)
             (let ((new-stanza-grob 
                     (ly:engraver-make-grob engraver 'StanzaNumber '())))
             ;; set 'id to select them later
             (ly:grob-set-property! new-stanza-grob 'id (markup->string stanza))
             (ly:grob-set-property! new-stanza-grob 'text stanza)))))))))
             
#(define (delete-adjacent-duplicates lst)
"Delete all duplicates in a list of strings."
  (if (and (not (null? lst)) (every string? lst))
      (fold-right (lambda (elem ret)
                    (if (equal? elem (first ret))
                        ret
                        (cons elem ret)))
                  (list (last lst))
                  (sort lst string<?))
      lst))
              
#(define (keep-stanza-number-at-line-begin grob)
"Delete all StanzaNumbers not starting a line."
  ;; If ly:item-break-dir is not zero, a line-break happens.
  ;; TODO Is this condition sufficient?
  (let ((break-dir (ly:item-break-dir grob)))
    (if (not (= 0 break-dir))
        (let* ((sys (ly:grob-system grob))
               (all-elts 
                 (ly:grob-array->list (ly:grob-object sys 'all-elements)))
               ;; get all StanzaNumbers
               (stanzas
                 (filter
                   (lambda (e)
                     (grob::has-interface e 'stanza-number-interface))
                   all-elts))
               ;; get all stanza-ids, without duplicates
               (stanza-ids
                 (delete-adjacent-duplicates
                   (filter
                     string?
                     (map
                       (lambda (x)
                         (ly:grob-property x 'id))
                       stanzas))))
               ;; put StanzaNumbers into sub-lists according to the 'id
               (id-selected-stanzas
                 (map
                   (lambda (val)
                     (filter
                       (lambda (x)
                         (equal? (ly:grob-property x 'id) val))
                       stanzas))
                   stanza-ids)))
          ;; keep only the first StanzaNumber of every line
          ;; all other's stencil is set #f
          ;; TODO there may be a StanzaNumber not catchable this way
          (for-each
             (lambda (lst)
               (if (not (null? (cdr lst)))
                   (for-each
                     (lambda (stz)
                       (ly:grob-set-property! stz 'stencil #f))
                     (cdr lst))))
             id-selected-stanzas)))))    

keepLineStartStanzaNumbers =
\layout {
  \context {
  \Score
  \override NonMusicalPaperColumn.after-line-breaking = 
    #keep-stanza-number-at-line-begin
  }
}

numberLyrics =
#(define-scheme-function (nmbr)(number?)
"Return a context-modification setting @code{stanza} and consisting 
@code{create-stanza-number-grob-engraver}."
#{
  \with {
    stanza = \markup \italic #(format #f "~a." nmbr)
    \consists #create-stanza-number-grob-engraver
  }
#})

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\paper { ragged-last-bottom = ##f }

\score {
  <<
    \new Staff { \key cis \major \repeat unfold 6 {  c''4 d'' e'' } }
    \new Lyrics \with \numberLyrics 1
      \lyricmode {
        \repeat unfold 6 {  foo -- bar -- buzz }
      }
      
    \new Lyrics \with \numberLyrics 2
      \lyricmode {
        \repeat unfold 6 {  very-very-long-syllable bur -- buuuzz }
      }
      
    \new Lyrics \with \numberLyrics 3
      \lyricmode {
        \repeat unfold 6 {  fuu -- bla -- blibbb }
      }
  >>
  \header { piece = \markup \rounded-box \fill-line { "Using StanzaNumber" } }
  \layout { \keepLineStartStanzaNumbers }
}

\score {
  <<
    \new Staff { \key cis \major \repeat unfold 6 {  c''4 d'' e'' } }
    \new Lyrics \with { instrumentName = "1." shortInstrumentName = "1." }
      \lyricmode {
        \repeat unfold 6 {  foo -- bar -- buzz }
      }
      
    \new Lyrics \with { instrumentName = "2." shortInstrumentName = "2." }
      \lyricmode {
        \repeat unfold 6 {  very-very-long-syllable bur -- buuuzz }
      }
      
    \new Lyrics \with { instrumentName = "3." shortInstrumentName = "3." }
      \lyricmode {
        \repeat unfold 6 {  fuu -- bla -- blibbb }
      }
  >>
  \header { piece = \markup \rounded-box \fill-line { "Using InstrumentName" } }
  \layout {
  	\context {
      \Score
      \override InstrumentName.X-offset = #'()
      \override InstrumentName.font-series = #'bold
      \override InstrumentName.font-shape = #'italic
    }
  	\context {
      \Lyrics
      \revert InstrumentName.font-size
    }
  }
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to