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: jakob lund
Subject: Re: Using lyrics in a markup
Date: Wed, 19 Jan 2011 14:15:29 +0100

2011/1/18 Marc Hohl <address@hidden>:
> Am 18.01.2011 18:56, schrieb Graham Percival:
>>
>> On Tue, Jan 18, 2011 at 05:24:11PM +0100, Marc Hohl wrote:
>>>
>>> These functions should be bundled in a snippet, or perhaps included in
>>> the
>>> lilypond distribution?
>>
>> Start by adding it to LSR.
>
> Done.
>
> http://lsr.dsi.unimi.it/LSR/Snippet?id=744

Great... I managed to create a \markup macro in order to make it
easier to use. I chose the name \verse for the macro because I thought
it would be nice with a short name if you're going to type it multiple
times, e.g. to handle line breaks, like the example.


Cheers, Jakob.


#(define-markup-command (verse layout props lyrics) (ly:music?)
"Transform a \\lyricmode lyric into a \\markup \\line"
  (interpret-markup layout props
    (make-line-markup (reduce-hyphens (flatten-nonmarkup-list
(lyrics->list lyrics))))))

#(define (lyrics->list lyrics)
"Return only syllables and hyphens from  @code{lyrics}."
         (if (ly:music? lyrics)
             (if (memq (ly:music-property lyrics 'name) '(LyricEvent
HyphenEvent))
                 (begin (if (eq? (ly:music-property lyrics 'name) 'LyricEvent)
                            (list (ly:music-property lyrics 'text))
                            (list "--")))
                 (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 wd (eat (car wds) (cdr wds)))))))

%% ----------------------------

wordsOne = \lyricmode { This is my ex --  \markup { \italic am }  -- ple text. }
wordsTwo = \lyricmode { Here goes the se -- cond line then. }
melody = \relative c' { c4 d e f | g a c2 }

\new Voice { \melody \melody }
\addlyrics { \words \wordsTwo }

\markup \column{ \verse #words \verse #wordsTwo }


>
> Regards,
>
> Marc
>>
>> Cheers,
>> - Graham
>>
>
>



reply via email to

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