lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using lyrics in a markup


From: Jan-Peter Voigt
Subject: Re: Using lyrics in a markup
Date: Fri, 04 Mar 2011 12:12:28 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8

On 10.02.2011 09:20, Marc Hohl wrote:
Am 08.02.2011 12:00, schrieb Jan-Peter Voigt:
Hello Marc, hello Jakob, hello list,

I just wanted to share a tiny extension of the lyrics->markup function:

...
            (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))
;; to include stanza, copy the following three lines into the conditional of the function ((and (equal? (ly:music-property lyrics 'name) 'PropertySet)
                    (equal? (ly:music-property lyrics 'symbol) 'stanza))
               (markup #:bold (ly:music-property lyrics 'value)))
...

So if there are \set stanza statements, they will go into the markup.
This is great! Will this go into the lsr snippet, too?

Regards,

Marc

Hello again,

I came across our lyrics->markup snippet and made another extension: Stanza numbers often are left to the verse block. Now there is another bool-parameter to the verse-command, wich tells, if the stanza number shall be left of the verse or inline. I will post this to LSR, when I treat multiple stanza numbers correctly with the first one left.

It would be nice, if someone could test it.

Cheers,
Jan-Peter

%%snip%%
\version "2.12.3"

#(define linebreakindicator "\\")

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

% format lyrics bold
lyrbold = #(define-music-function (parser location lyrics) (ly:music?)
  (music-map
    (lambda (m)
            (begin
              (if (equal? (ly:music-property m 'name) 'LyricEvent)
(ly:music-set-property! m 'text (markup #:bold (ly:music-property m 'text))))
              m))
    lyrics))

% format lyrics italic
lyritalic = #(define-music-function (parser location lyrics) (ly:music?)
  (music-map
    (lambda (m)
            (begin
              (if (equal? (ly:music-property m 'name) 'LyricEvent)
(ly:music-set-property! m 'text (markup #:italic (ly:music-property m 'text))))
              m))
    lyrics))


%% Function to extract strings from lyrics.
#(define (lyrics->list lyrics append-stanza)
        "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))
              ((and (eq? (ly:music-property lyrics 'name) 'PropertySet)
                    (eq? (ly:music-property lyrics 'symbol) 'stanza))
               (if append-stanza
(begin (append-stanza (markup #:bold (ly:music-property lyrics 'value))) '())
                 (markup #:bold (ly:music-property lyrics 'value))))
              (else (let ((elt (ly:music-property lyrics 'element))
                          (elts (ly:music-property lyrics 'elements)))
                         (if (ly:music? elt)
                             (lyrics->list elt append-stanza)
                             (if (null? elts)
                                 '()
                                 (map (lambda(x)
(lyrics->list x append-stanza))
                                      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 stanzblock) (ly:music? boolean?)
  "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))
        (stlist (list))
       )
       (let*
((append-stanza (lambda (stm)(set! stlist (append stlist (list stm))))) (get-stanza (lambda ()(if (> (length stlist) 0) (car stlist) #f)))
          (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 (if stanzblock append-stanza #f))))))
         )
         (if (get-stanza)
(interpret-markup layout props (markup #:line ((get-stanza) (make-column-markup list-of-lines)))) (interpret-markup layout props (make-column-markup list-of-lines))
       ))
))
%%%%%%%%%%%%%%%%

textA = \lyricmode {
  \set stanza = "1."
  Toch -- ter __ Zi -- on, freu -- e dich, \nl
  jauch -- ze laut, Je -- ru -- sa -- lem. \nl
  Sieh, __ dein \lyrbold { 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, \lyritalic { Je -- ru -- sa -- lem. }
}

\bookpart {
  \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 { With line breaks (no overrides) } } }
  \markup { \override #'(line-width . 40) \verse #textA ##t }
  \markup { \line { \bold { With visible line break character } } }
\markup { \override #'(line-width . 40) \override #'(display-nl . #t) \verse #textA ##t } \markup { \line { \bold { With visible line break character, left aligned and stanza inline } } } \markup { \override #'(line-width . 40) \override #'(display-nl . #t) \override #`(make-line . ,make-wordwrap-markup) \verse #textA ##f }
}
%%snip%%




reply via email to

[Prev in Thread] Current Thread [Next in Thread]