lilypond-user
[Top][All Lists]
Advanced

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

Re: Q re LSR snippet 744


From: Thomas Morley
Subject: Re: Q re LSR snippet 744
Date: Sat, 19 Mar 2016 15:30:49 +0100

2016-03-19 12:41 GMT+01:00 Michael Gerdau <address@hidden>:
>> somewhere between 2.14. and 2.16. LilyPond internals changed how the
>> Hyphen is represented.
>>
>> The check for
>> (eq? (ly:music-property lyrics 'name) 'HyphenEvent)
>> in
>> (lyrics->list lyrics)
>> will never be true nowadays.
>
> Ah...ok...it's not me being too stupid to understand the logic then :)
>
>> You need to look into the 'articulations of lyrics to find the hyphen.
>> Then the rest works again.
>>
>> I've fixed it in LSR
>> http://lsr.di.unimi.it/LSR/Item?id=744
>
> Thanks a lot. Looking at the code it's all clear now.
>
> Best wishes,
> Michael


Because it's an really old snippet, I rewrote large parts of it,
reflecting functionality being in the source meanwhile.
Please test, if no glitch escaped me, I'll replace the old code with
the one below:

\version "2.19.38"

#(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
        ((music-is-of-type? lyrics 'lyric-event)
          (let* ((art (ly:music-property lyrics 'articulations))
                 (hyphen?
                   (not (null?
                     (filter
                       (lambda (m)
                         (music-is-of-type? m 'hyphen-event))
                       art))))
                 (text (ly:music-property lyrics 'text)))
            (if hyphen? (list text hyphen?) (list text))))
        ((music-is-of-type? lyrics 'line-break-event)
         (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 one level, but don't flatten markup constructs!"
  ;; The check for markup? is likely not needed
  ;; We let it in for clarity
  (append-map (lambda (e) (if (markup? e) e `(,@e))) x))

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

#(define-markup-command (verse layout props lyrics) (ly:music?)
  #:properties ((display-nl #f)
                (make-line make-justify-markup))
  "Verse command that marks up a column of \\nl-separated lines"
  (let* ((unnested-lyr-ls
           (reduce-hyphens (flatten-nonmarkup-list (lyrics->list lyrics))))
         (split-cond?
           (lambda (a)
             (and (not display-nl)
                  (equal? a linebreakindicator))))
         (list-of-lines
           (map
             (lambda (l) (make-line l))
             (split-list-by-separator unnested-lyr-ls split-cond?))))
    (if (null? unnested-lyr-ls)
        (begin
          (ly:warning "lyrics is a empty, returning empty-stencil")
          empty-stencil)
        (interpret-markup layout props (make-column-markup list-of-lines)))))

%%%%%%%%%%%%%%%%

mus = \relative c'' { \partial 4. g8 a g e c r4 r8 g' a g | f d }

test = \lyricmode {
  \override LyricHyphen.minimum-distance = #1.2
  Du lil -- le \markup \italic fis -- \markup \italic ker \nl
  Du \markup \italic lil -- \markup \italic le fis -- ker
}

%{
<<
  \new Voice = "mel" \mus
  \new Lyrics \lyricsto "mel" \test
>>
%}

\mus
\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 }
%%{
%  To have left-aligned word-wrapping with
%  long lines, use
  \markup { \override #`(make-line . ,make-wordwrap-markup)
            \verse #test }
%  (the default is make-justify-markup)
%}




Cheers,
  Harm



reply via email to

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