Hi Jakob, hello list,

I was about to answer with my 2.12-version ;-)
It is essentially like your version (using let and assoc props ...) but yours is open for override extension ...
Now its posted to LSR and has to be approved.

Best regards and cheers!
Jan-Peter

On 24.01.2011 10:35, jakob lund wrote:
Hi
...
I realized I had 2.12 installed as well..  After removing the
#:properties stuff and adding { } to \addlyrics, the new version
compiles in both 2.12 and 2.13 (the markup looks better in the 2.12
version though; seems that in 2.13, the lines are a little too close?)


Cheers Jakob.

\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
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to