oops, forgot to reply to list (sorry about the extra spam Jan-Peter)
2011/1/23 jakob lund <[email protected]>:
> Hi again
>
> After fiddling some more with this, I came up with a simple solution.
> Instead of a string, a LineBreakEvent is inserted into the lyric --
> neither \lyricmode or \addlyrics complain about this, and the events
> doesn't seem to appear in the music output. This removes the need for
> the filter function.
>
> The lyrics->list function then recognizes the placeholders and
> replaces them with occurrences of the indicator string, which the
> verse command then uses to split the lines.
>
> It seems to work well, try it out.
>
> 2011/1/21 Jan-Peter Voigt <[email protected]>:
>> Hello again,
>>
>> so you would have to check (pseudo-scheme):
>> ...
>> (if (and (string? x)(string=? x
>> "<someIndicatorStringNooneWouldEverUseInARealLyric>"))
>> (<introduceNewLine> ...))
>
> There is no \linebreak or equivalent command in \markup, so what
> happens is that the list of syllables is cut at every occurrence of
> the indicator string, producing a list of lists. Then, a markup
> function is mapped over this list of lists, producing a list of
> markups; the resulting list of markups is then passed to
> make-column-markup, which produces the line breaks :-)
>
> :-)
>
> Jakob.
>
>> ...
>>
>> and this would probably be done in the (reduce-hyphens text)-method/function.
>>
>> If this works one could define a variable with the lyrics including the
>> newlines. Then use it filtered with \lyricsto and markedup with \verse.
>>
>> Best regards,
>> Jan-Peter.
>>
>>
>> Am 20.01.2011 um 16:35 schrieb jakob lund:
>>
>>> 2011/1/20 Jan-Peter Voigt <[email protected]>:
>>>>> What do you think of allowing to define a additional "line break
>>>>> character",
>>>>> for example ¶, which could be filtered out within \lyricsmode, and used
>>>>> as a
>>>>> newline in the \verse?
>>>> Thats a good idea!
>>>>> So your input will look like
>>>>> \override Lyrics #'ignore-chars= #'(¶) % this is pseudo code!
>>>
>>> I guess this would mean that the Lyrics context would have to filter
>>> out the ¶ as it goes. A simpler version of the same idea could be
>>>
>>> nl = \lyricmode { <someIndicatorStringNooneWouldEverUseInARealLyric> }
>>>
>>> and then use
>>>
>>> words = \lyricmode { Toch -- ter \nl Zi -- on }
>>>
>>> then add a filter (a music function that calls music-filter) to use
>>> with addlyrics, like this
>>>
>>> \addlyrics \removeLineBreakIndicators \words
>>>
>>> and then update the \verse macro to produce a new line for every
>>> occurence of the indicator.
>>> that should be doable...
>>>
>>> Jakob.
>>
>>
>>
>
\version "2.13"
#(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?)
#:properties ((display-nl #f)
(make-line make-justify-markup))
"Verse command that marks up a column of \\nl-separated lines"
(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 }
\relative c'' { \partial 4. g8 a g e c r4 r8 g' a g | f d}
\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 \words }
(the default is make-justify-markup)
%}
_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user