Hello Phil,

I posted the "improved" version this morning with a bit more text about the possible overrides. So you can approve that and delete the old one or copy either the code of the new snippet (or the attached one) to the old and delete the new one. ... huh???
OK, I try once more ;-)

- Delete old snippet and approve new one
or
- update old snippet with code from the new one (or the attached) and delete pending new snippet.

The uploaded code and the attached differ only very slightly in the verse-markup-command. (howto get override props)

Cheers,
Jan-Peter


On 24.01.2011 15:12, Phil Holmes wrote:
I've slightly lost the plot of what's needed here. There's http://lsr.dsi.unimi.it/LSR/Item?id=744 which I think could be edited for the new improvements, and there's an improved version waiting for approval. Please let me know if the old version is to be edited or deleted, and whether the new version should be approved.

--
Phil Holmes




\version "2.12.3"

#(define linebreakindicator "\\")

% \nl command that inserts the placeholder event into a lyrics
nl = #(make-music 'LineBreakEvent)

%% Function to extract strings from lyrics.
%  
#(define (lyrics->list lyrics)
        "Return only syllables and hyphens from  @code{lyrics}."
        (if (ly:music? lyrics)
            (cond 
              ((eq? (ly:music-property lyrics 'name) 'LyricEvent) 
               (ly:music-property lyrics 'text))
              ((eq? (ly:music-property lyrics 'name) 'HyphenEvent) 
               (list "--"))
              ((eq? (ly:music-property lyrics 'name) 'LineBreakEvent)
               (list linebreakindicator))
              (else (let ((elt (ly:music-property lyrics 'element))
                          (elts (ly:music-property lyrics 'elements)))
                         (if (ly:music? elt)
                             (lyrics->list elt)
                             (if (null? elts)
                                 '()
                                 (map (lambda(x)
                                             (lyrics->list x))
                                      elts)))))
            )
            '()))

#(define (flatten-nonmarkup-list x)
        "Unnest list, but don't flatten markup constructs!"
        (cond ((null? x) '())
              ((not (pair? x)) (list x))
              (else (append (if (markup? (car x)) 
                                (list (car x)) 
                                (flatten-nonmarkup-list (car x)))
                            (flatten-nonmarkup-list (cdr x))))))

#(define (reduce-hyphens text) 
        (let eat ((wd (car text)) (wds (cdr text)))
                 (cond 
                   ((null? wds) (list wd))
                   ((and (equal? "--" (car wds)) (not (null? (cdr wds))))
                    (eat (markup #:concat (wd (cadr wds)))
                         (cddr wds)))
                   (else (cons (markup wd) (eat (car wds) (cdr wds)))))))

#(define (split-on predicate? l) 
        (let loop ((h '()) (r l))
                  (cond 
                    ((null? r)
                     (if (null? h) h (list (reverse h))))
                    ((predicate? (car r)) 
                     (if (null? h)
                         (loop h (cdr r))
                         (cons (reverse h) (loop '() (cdr r)))))
                    (else 
                      (loop (cons (car r) h) (cdr r))))))

#(define-markup-command (verse layout props lyrics) (ly:music?)
  "Verse command that marks up a column of \\nl-separated lines"
  (let ((display-nl (chain-assoc-get 'display-nl props #f))
        (make-line (chain-assoc-get 'make-line props make-justify-markup)))
       (let*
         ((split-cond? (lambda (a) (and 
                      (not display-nl )
                      (equal? a linebreakindicator))))
          (list-of-lines (map 
              (lambda (l) (make-line (reduce-hyphens l)))   
              (split-on split-cond? (flatten-nonmarkup-list (lyrics->list lyrics)))))
         )
         (interpret-markup layout props (make-column-markup list-of-lines)))
))
%%%%%%%%%%%%%%%%

test = \lyricmode {
  Du lil -- le \markup \italic fis -- \markup \italic ker \nl 
  Du \markup \italic lil -- \markup \italic le fis -- ker }

textA = \lyricmode {
  \set stanza = "1."
  Toch -- ter __ Zi -- on, freu -- e dich, \nl
  jauch -- ze laut, Je -- ru -- sa -- lem. \nl
  Sieh, __ dein Kö -- nig kommt zu dir, \nl
  ja, __ er kommt, der Frie -- de -- fürst. \nl
  Toch -- ter Zi -- on, freu -- e dich, \nl
  jauch -- ze laut, Je -- ru -- sa -- lem.
}

\bookpart {
  \score {
    <<
      \relative c'' { \partial 4. g8 a g e c r4 r8 g' a g | f d r4 }
      \addlyrics { \test }
    >>
  }
  \markup { \line { \bold { With line breaks (no overrides) } } }
  \markup { \verse #test }
  \markup { \line { \bold { With visible line break character } } }
  \markup { \override #'(display-nl . #t) \verse #test }
  
  \score {
    \relative c'' {
      \time 2/2
      \key ees \major
      \dynamicUp \autoBeamOff
      
      bes2 g4.( aes8) | bes2 ees, | f8([ g aes bes] aes4) g | f1 |
      g8([ aes bes c] bes4) bes | ees2 bes | aes4( g8[ aes] f4.) ees8 | ees2. r4 |
      g8([ f g aes] g4) g | f2 ees | aes4( g f) ees | d1 |
      ees8([ d ees f] ees4) ees | c'2 a! | bes4( c8[ bes] a!4.) bes8 | bes2.\< r4\! |
      bes2 g4.( aes8) | bes2 ees, | f8([ g aes bes] aes4) g | f1 |
      g8([ aes bes c] bes4) bes | ees2 bes | aes4( g8[ aes] f4.) ees8 | ees1 \bar "|."
    }
    \addlyrics { \textA }
  }
  \markup { \line { \bold { A carol } } }
  \markup { \override #'(line-width . 40) \verse #textA }
  \markup { \override #'(line-width . 40) \override #'(display-nl . #t) \verse #textA }
  \markup { \override #'(line-width . 40) \override #'(display-nl . #t) \override #`(make-line . ,make-wordwrap-markup) \verse #textA }
}
%{ 
  To have left-aligned word-wrapping with 
  long lines, use 
  \markup { \override #`(make-line . ,make-wordwrap-markup) 
            \verse #words }
  (the default is make-justify-markup)
%}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to