Re: Using lyrics in a markup
Am 04.03.2011 12:12, schrieb Jan-Peter Voigt: [...] 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. Just a quick response after a short test: Works for me, but as you mentioned, it fails when more stanzas are declared and stanzblock = ##t. Apart from this, would a separate property be the better way to handle the output? Anyway, this is a very useful enhancement for my current project - great work, thank you! Regards, Marc ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
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?)
Re: Using lyrics in a markup
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 ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
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. Best regards, Jan-Peter On 24.01.2011 20:36, Marc Hohl wrote: Am 24.01.2011 15:33, schrieb Jan-Peter Voigt: Hello Phil, I posted the "improved" version this morning with a bit more text about the possible overrides. So you can approve that and delete the old one or copy either the code of the new snippet (or the attached one) to the old and delete the new one. ... huh??? OK, I try once more ;-) - Delete old snippet and approve new one or - update old snippet with code from the new one (or the attached) and delete pending new snippet. The uploaded code and the attached differ only very slightly in the verse-markup-command. (howto get override props) Whatever - looks great! Thanks to you both, Jan-Peter and Jakob for improving this stuff, it will be very helpful for my current project! Regards, Marc Cheers, Jan-Peter On 24.01.2011 15:12, Phil Holmes wrote: I've slightly lost the plot of what's needed here. There's http://lsr.dsi.unimi.it/LSR/Item?id=744 which I think could be edited for the new improvements, and there's an improved version waiting for approval. Please let me know if the old version is to be edited or deleted, and whether the new version should be approved. -- Phil Holmes ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Am 24.01.2011 15:33, schrieb Jan-Peter Voigt: Hello Phil, I posted the "improved" version this morning with a bit more text about the possible overrides. So you can approve that and delete the old one or copy either the code of the new snippet (or the attached one) to the old and delete the new one. ... huh??? OK, I try once more ;-) - Delete old snippet and approve new one or - update old snippet with code from the new one (or the attached) and delete pending new snippet. The uploaded code and the attached differ only very slightly in the verse-markup-command. (howto get override props) Whatever - looks great! Thanks to you both, Jan-Peter and Jakob for improving this stuff, it will be very helpful for my current project! Regards, Marc Cheers, Jan-Peter On 24.01.2011 15:12, Phil Holmes wrote: I've slightly lost the plot of what's needed here. There's http://lsr.dsi.unimi.it/LSR/Item?id=744 which I think could be edited for the new improvements, and there's an improved version waiting for approval. Please let me know if the old version is to be edited or deleted, and whether the new version should be approved. -- Phil Holmes ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
- Original Message - From: "Jan-Peter Voigt" To: "Phil Holmes" Cc: "jakob lund" ; "Lilypond-User" Sent: Monday, January 24, 2011 2:33 PM Subject: Re: Using lyrics in a markup Hello Phil, I posted the "improved" version this morning with a bit more text about the possible overrides. So you can approve that and delete the old one or copy either the code of the new snippet (or the attached one) to the old and delete the new one. ... huh??? OK, I try once more ;-) - Delete old snippet and approve new one or - update old snippet with code from the new one (or the attached) and delete pending new snippet. The uploaded code and the attached differ only very slightly in the verse-markup-command. (howto get override props) Cheers, Jan-Peter I've updated the old snippet with the new code and description. -- Phil Holmes ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Hello Phil, I posted the "improved" version this morning with a bit more text about the possible overrides. So you can approve that and delete the old one or copy either the code of the new snippet (or the attached one) to the old and delete the new one. ... huh??? OK, I try once more ;-) - Delete old snippet and approve new one or - update old snippet with code from the new one (or the attached) and delete pending new snippet. The uploaded code and the attached differ only very slightly in the verse-markup-command. (howto get override props) Cheers, Jan-Peter On 24.01.2011 15:12, Phil Holmes wrote: I've slightly lost the plot of what's needed here. There's http://lsr.dsi.unimi.it/LSR/Item?id=744 which I think could be edited for the new improvements, and there's an improved version waiting for approval. Please let me know if the old version is to be edited or deleted, and whether the new version should be approved. -- Phil Holmes \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 \d
Re: Using lyrics in a markup
I've slightly lost the plot of what's needed here. There's http://lsr.dsi.unimi.it/LSR/Item?id=744 which I think could be edited for the new improvements, and there's an improved version waiting for approval. Please let me know if the old version is to be edited or deleted, and whether the new version should be approved. -- Phil Holmes ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
2011/1/24 jakob lund : > Hi > > 2011/1/24 Jan-Peter Voigt : >> 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 ... > > Why? The only difference (AFAICT) is that you did the clever thing and > used chain-assoc-get instead of reinventing the wheel like I did... I > oughtta have guessed there was already a function to do that :-) > > >> another question: This snippet is mostly your work, but I posted it to LSR >> with my name. Shall I add a text: >> "created by Jakob Lund" or something similar? > > No, never mind... And in fact, Marc wrote the first bit, if you look > up the thread :-) > > > Cheers > > Jakob. > >> Now its posted to LSR and has to be approved. By the way, the first version (no line breaks) is here http://lsr.dsi.unimi.it/LSR/Item?id=744 might as well just update that entry if possible? Jakob >> >> 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. >> >> > ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Hi 2011/1/24 Jan-Peter Voigt : > 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 ... Why? The only difference (AFAICT) is that you did the clever thing and used chain-assoc-get instead of reinventing the wheel like I did... I oughtta have guessed there was already a function to do that :-) > another question: This snippet is mostly your work, but I posted it to LSR > with my name. Shall I add a text: > "created by Jakob Lund" or something similar? No, never mind... And in fact, Marc wrote the first bit, if you look up the thread :-) Cheers Jakob. > 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. > > ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Hi, On 24.01.2011 13:22, jakob lund wrote: By the way, the first version (no line breaks) is here http://lsr.dsi.unimi.it/LSR/Item?id=744 might as well just update that entry if possible? This has to be done by an "LSR-administrator" ;-) If someone is able and willing to do this, go ahead and decide wether to take Jakobs or my version ;-) Cheers, Jan-Peter. ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
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
Re: Using lyrics in a markup
Hi 2011/1/23 jakob lund : > 2011/1/23 Jan-Peter Voigt : >> Hello and thank you Jakob, hello list, >> >> this piece is a great work. It compiles well in 2.13(.47 lilybuntu) and adds >> a very useful function to lily! >> The .ly is attached again, because I think it is good to have it on the >> devel-list. >> I would like to add it to LSR to have it in the main distro once. But it >> doesn't compile in 2.12(.3) stable, so it can't be uploaded right now. >> What else should we do now? >> >> Lilypond 2.12 complains about these lines: >> ... >> #(define-markup-command (verse layout props lyrics) (ly:music?) >> #:properties ((display-nl #f) >> (make-line make-justify-markup)) >> ... >> >> by the way: Is this #:properties(()) notation a new functionality in 2.13? I >> haven't seen it before? > > You're probably right about the #:properties syntax -- it should be > easy enough to swap make-line and display-nl with their default values > (make-justify-markup resp. #f) in the macro code to make it compile in > 2.12 (which I don't have installed so I'm not gonna test it) ... ? 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.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* ( ;; The first three associations replace the two commented ;; lines above in a (presumably?) 2.12-compatible way... (property (lambda (key default) (let ((a (assoc key (apply append props (if (->bool a) (cdr a) default (display-nl (property 'display-nl #f)) (make-line (property 'make-line make-justify-markup)) (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 } %{ << \new Voice = "mel" \relative c'' { \partial 4. g8 a g e c r4 r8 g' a g | f d} \new Lyric
Re: Using lyrics in a markup
2011/1/23 Jan-Peter Voigt : > Hello and thank you Jakob, hello list, > > this piece is a great work. It compiles well in 2.13(.47 lilybuntu) and adds > a very useful function to lily! > The .ly is attached again, because I think it is good to have it on the > devel-list. > I would like to add it to LSR to have it in the main distro once. But it > doesn't compile in 2.12(.3) stable, so it can't be uploaded right now. > What else should we do now? > > Lilypond 2.12 complains about these lines: > ... > #(define-markup-command (verse layout props lyrics) (ly:music?) > #:properties ((display-nl #f) > (make-line make-justify-markup)) > ... > > by the way: Is this #:properties(()) notation a new functionality in 2.13? I > haven't seen it before? You're probably right about the #:properties syntax -- it should be easy enough to swap make-line and display-nl with their default values (make-justify-markup resp. #f) in the macro code to make it compile in 2.12 (which I don't have installed so I'm not gonna test it) ... ? > And is there a tutorial on all those comma- and accent-notations like in > \override #`(make-line . ,make-wordwrap-markup) ? > I haven't found it in my scheme-tutorials. I think it's mostly connected to macro definitions, as a shortcut to insert references into lists. If you write \override #'(make-line . make-wordwrap-markup) you get en error: Wrong type to apply: make-wordwrap-markup because then the value of the property is set to the SYMBOL make-wordwrap-markup rather than FUNCTION referred to by that symbol. As far as I know, `(make-line . ,make-wordwrap-markup) is the same as (cons 'make-line make-wordwrap-markup), just like '(this that the-other) is the same as (list 'this 'that 'the-other). The backtick ` is called "quasiquote" an the comma is "unquote". Btw in that last comment in the file, it should read "\verse #words" instead of "\verse \words" of course, please correct that if you put it on LSR Regards Jakob. > > Best regards, > Jan-Peter. > > Am 23.01.2011 um 14:15 schrieb jakob lund: > >> oops, forgot to reply to list (sorry about the extra spam Jan-Peter) > I don't mind ;-) >> 2011/1/23 jakob lund : >>> 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. >>> > ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Hello and thank you Jakob, hello list, this piece is a great work. It compiles well in 2.13(.47 lilybuntu) and adds a very useful function to lily! The .ly is attached again, because I think it is good to have it on the devel-list. I would like to add it to LSR to have it in the main distro once. But it doesn't compile in 2.12(.3) stable, so it can't be uploaded right now. What else should we do now? Lilypond 2.12 complains about these lines: ... #(define-markup-command (verse layout props lyrics) (ly:music?) #:properties ((display-nl #f) (make-line make-justify-markup)) ... by the way: Is this #:properties(()) notation a new functionality in 2.13? I haven't seen it before? And is there a tutorial on all those comma- and accent-notations like in \override #`(make-line . ,make-wordwrap-markup) ? I haven't found it in my scheme-tutorials. Best regards, Jan-Peter. Am 23.01.2011 um 14:15 schrieb jakob lund: > oops, forgot to reply to list (sorry about the extra spam Jan-Peter) I don't mind ;-) > 2011/1/23 jakob lund : >> 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. >> lyrics-to-text.ly Description: Binary data ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
oops, forgot to reply to list (sorry about the extra spam Jan-Peter) 2011/1/23 jakob lund : > 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 : >> Hello again, >> >> so you would have to check (pseudo-scheme): >> ... >> (if (and (string? x)(string=? x >> "")) >> ( ...)) > > 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 : > 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 { } >>> >>> 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
Re: Using lyrics in a markup
Hello again, so you would have to check (pseudo-scheme): ... (if (and (string? x)(string=? x "")) ( ...)) ... 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 : >>> 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 { } > > 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. ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
2011/1/21 David Kastrup > > Jan Warchoł writes: > > The ś character that you used is used in polish language, for example. > > That's just a bug of your mail reading software. He used the pilcrow > sign, namely ¶ and not ś. Oh. Good to know. Thanks, Janek ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Jan Warchoł writes: > 2011/1/20 Marc Hohl >> >> 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? > > +1, however i'd vote for either: > - specific command (starting with \) > - ordinary end of line character > and not some special character that is "supposed to be used rarely". > The ś character that you used is used in polish language, for example. That's just a bug of your mail reading software. He used the pilcrow sign, namely ¶ and not ś. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
2011/1/20 Marc Hohl > > Am 20.01.2011 09:20, schrieb jakob lund: >> >> However, I am guessing that the desired output is actually >> >> Tochter Zion, freue dich, >> jauchze laut, Jerusalem. >> Sieh, dein König kommt zu dir, >> ja, er kommt, der Friedefürst. >> Tochter Zion, freue dich, >> jauchze laut, Jerusalem. >> >> rather than >> >> Tochter Zion, freue dich, jauchze laut, Jerusalem. Sieh, dein König >> kommt zu dir, ja, er kommt, der Friedefürst. Tochter Zion, freue dich, >> jauchze laut, Jerusalem. >> >> where the line breaking depends on column width, font size etc.? I >> can't think of way to control the line breaks, except to enter each >> line individually, like > > 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? +1, however i'd vote for either: - specific command (starting with \) - ordinary end of line character and not some special character that is "supposed to be used rarely". The ś character that you used is used in polish language, for example. cheers, Janek ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
> 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! Lets dive into the lily-code and search for oppertunities! > strI = \lyricmode > { > \set stanza = "1." > Toch -- ter Zi -- on, freu -- e dich,¶jauch -- ze laut, > Je -- ru -- sa -- lem.¶Sieh, __ dein Kö -- nig kommt zu dir,¶ > ja, __ er kommt, der Frie -- de -- fürst.¶Toch -- ter Zi -- on, > freu -- e dich,¶ jauch -- ze laut, Je -- ru -- sa -- lem. > } > > and the output is as expected? > > I don't know how easy such an implemantation would be, me neither ;-) > but giving a > list of characters to ignore and filter then out in Lyrics and using > this information to rearrange the text would give a lot more flexibility > to this feature. This would give also the option of splitting verse-lines with an arbitrary character. In our church-hymn-books (Kirchengesangbuch) the verse-lines a divided by '/'. So the output could look like: e.g. Tochter Zion, freue dich, / jauchze laut, Jerusalem. / Sieh, dein König kommt zu / dir, / ja, er kommt, der Friedefürst. / Tochter Zion, freue dich, / jauchze laut, Jerusalem. Well I am happy with the solution found by Jakob, you and anybody else who contributed ;-) But we should try to find other options ;-) Best regards, Jan-Peter ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Congratulations and thank you very much! :-) The first "desired" output would be nice, but in that case one has to use line by line input of the lyrics. I think thats OK for church songs like this one. But there are many cases, where I just want a justified markup of the lyrics. Best regards, Jan-Peter Am 20.01.2011 um 09:20 schrieb jakob lund: > That's a good point.. After experimenting a bit I think that replacing > make-line-markup with make-justify-markup in the macro definition (the > define-markup-command part) does what you want. > > However, I am guessing that the desired output is actually > > Tochter Zion, freue dich, > jauchze laut, Jerusalem. > Sieh, dein König kommt zu dir, > ja, er kommt, der Friedefürst. > Tochter Zion, freue dich, > jauchze laut, Jerusalem. > > rather than > > Tochter Zion, freue dich, jauchze laut, Jerusalem. Sieh, dein König > kommt zu dir, ja, er kommt, der Friedefürst. Tochter Zion, freue dich, > jauchze laut, Jerusalem. > > where the line breaking depends on column width, font size etc.? I > can't think of way to control the line breaks, except to enter each > line individually, like > > strIa = \lyricmode { Toch -- ter Zi -- on, freu -- e dich, } > strIb = \lyricmode { jauch -- ze laut, Je -- ru -- sa -- lem.} > strIc = \lyricmode { Sieh, __ dein Kö -- nig kommt zu dir, } > strId = \lyricmode { ja, __ er kommt, der Frie -- de -- fürst. } > > .. etc, and then eventually > > \markup \column { \verse #strIa \verse #strIb \verse #strIc \verse #strId } > > > Regards > -- Jakob. ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Am 20.01.2011 09:20, schrieb jakob lund: 2011/1/19 Jan-Peter Voigt: Hello scheme-gurus, nr. 744 is bookmarked ;-) There's one more thing. I tried the verse-command and it works nicely, but it will wrap lines: say you have a stanza like this --snip-- strI = \lyricmode { \set stanza = "1." Toch -- ter Zi -- on, freu -- e dich, jauch -- ze laut, Je -- ru -- sa -- lem. Sieh, __ dein Kö -- nig kommt zu dir, ja, __ er kommt, der Frie -- de -- fürst. Toch -- ter Zi -- on, freu -- e dich, jauch -- ze laut, Je -- ru -- sa -- lem. } \markup \column{ \wordwrap { \verse #strI } } \markuplines \justified-lines { \verse #strI } --snip-- it will not wrap lines but cross the page margin. Do have an idea how to deal with that? That's a good point.. After experimenting a bit I think that replacing make-line-markup with make-justify-markup in the macro definition (the define-markup-command part) does what you want. However, I am guessing that the desired output is actually Tochter Zion, freue dich, jauchze laut, Jerusalem. Sieh, dein König kommt zu dir, ja, er kommt, der Friedefürst. Tochter Zion, freue dich, jauchze laut, Jerusalem. rather than Tochter Zion, freue dich, jauchze laut, Jerusalem. Sieh, dein König kommt zu dir, ja, er kommt, der Friedefürst. Tochter Zion, freue dich, jauchze laut, Jerusalem. where the line breaking depends on column width, font size etc.? I can't think of way to control the line breaks, except to enter each line individually, like 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? So your input will look like \override Lyrics #'ignore-chars= #'(¶) % this is pseudo code! strI = \lyricmode { \set stanza = "1." Toch -- ter Zi -- on, freu -- e dich,¶jauch -- ze laut, Je -- ru -- sa -- lem.¶Sieh, __ dein Kö -- nig kommt zu dir,¶ ja, __ er kommt, der Frie -- de -- fürst.¶Toch -- ter Zi -- on, freu -- e dich,¶ jauch -- ze laut, Je -- ru -- sa -- lem. } and the output is as expected? I don't know how easy such an implemantation would be, but giving a list of characters to ignore and filter then out in Lyrics and using this information to rearrange the text would give a lot more flexibility to this feature. Regards, Marc strIa = \lyricmode { Toch -- ter Zi -- on, freu -- e dich, } strIb = \lyricmode { jauch -- ze laut, Je -- ru -- sa -- lem.} strIc = \lyricmode { Sieh, __ dein Kö -- nig kommt zu dir, } strId = \lyricmode { ja, __ er kommt, der Frie -- de -- fürst. } .. etc, and then eventually \markup \column { \verse #strIa \verse #strIb \verse #strIc \verse #strId } Regards -- Jakob. ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
2011/1/19 Jan-Peter Voigt : > Hello scheme-gurus, > nr. 744 is bookmarked ;-) > There's one more thing. I tried the verse-command and it works nicely, but > it will wrap lines: > say you have a stanza like this > --snip-- > strI = \lyricmode > { > \set stanza = "1." > Toch -- ter Zi -- on, freu -- e dich, > jauch -- ze laut, Je -- ru -- sa -- lem. > Sieh, __ dein Kö -- nig kommt zu dir, > ja, __ er kommt, der Frie -- de -- fürst. > Toch -- ter Zi -- on, freu -- e dich, > jauch -- ze laut, Je -- ru -- sa -- lem. > } > \markup \column{ \wordwrap { \verse #strI } } > \markuplines \justified-lines { \verse #strI } > --snip-- > it will not wrap lines but cross the page margin. Do have an idea how to > deal with that? That's a good point.. After experimenting a bit I think that replacing make-line-markup with make-justify-markup in the macro definition (the define-markup-command part) does what you want. However, I am guessing that the desired output is actually Tochter Zion, freue dich, jauchze laut, Jerusalem. Sieh, dein König kommt zu dir, ja, er kommt, der Friedefürst. Tochter Zion, freue dich, jauchze laut, Jerusalem. rather than Tochter Zion, freue dich, jauchze laut, Jerusalem. Sieh, dein König kommt zu dir, ja, er kommt, der Friedefürst. Tochter Zion, freue dich, jauchze laut, Jerusalem. where the line breaking depends on column width, font size etc.? I can't think of way to control the line breaks, except to enter each line individually, like strIa = \lyricmode { Toch -- ter Zi -- on, freu -- e dich, } strIb = \lyricmode { jauch -- ze laut, Je -- ru -- sa -- lem.} strIc = \lyricmode { Sieh, __ dein Kö -- nig kommt zu dir, } strId = \lyricmode { ja, __ er kommt, der Frie -- de -- fürst. } .. etc, and then eventually \markup \column { \verse #strIa \verse #strIb \verse #strIc \verse #strId } Regards -- Jakob. ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Hello scheme-gurus, nr. 744 is bookmarked ;-) There's one more thing. I tried the verse-command and it works nicely, but it will wrap lines: say you have a stanza like this --snip-- strI = \lyricmode { \set stanza = "1." Toch -- ter Zi -- on, freu -- e dich, jauch -- ze laut, Je -- ru -- sa -- lem. Sieh, __ dein Kö -- nig kommt zu dir, ja, __ er kommt, der Frie -- de -- fürst. Toch -- ter Zi -- on, freu -- e dich, jauch -- ze laut, Je -- ru -- sa -- lem. } \markup \column{ \wordwrap { \verse #strI } } \markuplines \justified-lines { \verse #strI } --snip-- it will not wrap lines but cross the page margin. Do have an idea how to deal with that? Best regards, Jan-Peter >> 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. > ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
2011/1/18 Marc Hohl : > 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 >> > > ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Le 18/01/2011 20:21, Marc Hohl disait : 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 Just wonderful. When you have several verses, you even may do : \new Voice { \melody } \addlyrics { \wordsA } \addlyrics { \wordsB } textA = #(lyrics->text wordsA) textB = #(lyrics->text wordsB) \markup{ Verse 1. } #(markup* (make-line-markup textA)) \markup { Verse 2.} #(markup* (make-line-markup textB)) for those who don't read music! Thank you Marc. Cheers, Jean-Charles ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
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 Regards, Marc Cheers, - Graham ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
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. Cheers, - Graham ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Am 18.01.2011 16:10, schrieb jakob lund: [...] Sure... You have to play the game, right? [...] snip Jakob Wow, I am very impressed! The named let construct is absolutely new to me, but allows for very elegant code. These functions should be bundled in a snippet, or perhaps included in the lilypond distribution? Great work, thank you! Regards Marc ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
2011/1/18 Jan-Peter Voigt : > Hello List, > > this is a very cool snippet! I also thought of trying this excersize ... > perhaps tomorrow ;-) > I think it should be posted to LSR! > There is one thing I tried: If you have markups in your lyrics: > > words = \lyricmode { This is my ex -- am -- ple \markup { \italic text } } > > this function will fail. > Perhaps someone is willing to play this scheme-game a bit further? > Sure... You have to play the game, right? To allow markups, we have to use (markup #:concat ( . . )) instead of string-concatenate. The flatten-list function also has to be adjusted to leave the markups intact. There is no need to call flatten-list from inside the recursion in lyrics->list. It probably doesn't do any harm in this case, but I wonder if the original function (extract-named-music) is ever used on any `heavy' nested music structures, because if so, it might be a good idea to redefine it? (Theoretically, calling flatten-list from inside the recursion may result in N^2 calls to flatten-list when returning N elements from extract-named-music...) #(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) ;; Define initial first-word 'wd' and remaining-words 'wds' (let eat ((wd (car text)) (wds (cdr text))) (cond ;; Last syllable reached: Terminate recursion ((null? wds) (list wd)) ((and (equal? "--" (car wds)) (not (null? (cdr wds ;; The next word is a hyphen AND there is a syllable after that hyphen ;; Concatenate the syllable after the hyphen onto wd, and recurse (eat (markup #:concat ((markup wd) (markup (cadr wds (cddr wds))) ;; Not a hyphen, just use wd as the first word on the list, and then recurse. (else (cons wd (eat (car wds) (cdr wds))) #(define (lyrics->text lyrics) (reduce-hyphens (flatten-nonmarkup-list (lyrics->list lyrics snip Jakob > Best regards, > Jan-Peter > > > On 18.01.2011 12:56, jakob lund wrote: >> >> 2011/1/18 Marc Hohl: >>> >>> Am 15.01.2011 21:51, schrieb Neil Puttock: On 15 January 2011 19:01, Marc Hohl wrote: > Now I wonder whether it is possible to create a kind of text book by > including the lyrics in a markup, perhaps with a scheme function which > replaces the " -- " by "". > > Is it possible to store the text in a variable? [...] For simplicity I've ignored hyphens, but it shouldn't be too difficult to add them (or use their position in the list of strings to restore the hyphenated words). >>> >>> This is what I got so far: >>> >>> \version "2.13.46" >>> >>> words = \lyricmode { This is my ex -- am -- ple text } >>> >>> #(define (lyrics->list lyrics) >>> "Return a flat list containing all syllables and hyphens from >>> @code{lyrics}." >>> (let ((extracted-list >>> (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) >>> '( >>> (flatten-list extracted-list))) >
Re: Using lyrics in a markup
Hello List, this is a very cool snippet! I also thought of trying this excersize ... perhaps tomorrow ;-) I think it should be posted to LSR! There is one thing I tried: If you have markups in your lyrics: words = \lyricmode { This is my ex -- am -- ple \markup { \italic text } } this function will fail. Perhaps someone is willing to play this scheme-game a bit further? Best regards, Jan-Peter On 18.01.2011 12:56, jakob lund wrote: 2011/1/18 Marc Hohl: Am 15.01.2011 21:51, schrieb Neil Puttock: On 15 January 2011 19:01, Marc Hohlwrote: Now I wonder whether it is possible to create a kind of text book by including the lyrics in a markup, perhaps with a scheme function which replaces the " -- " by "". Is it possible to store the text in a variable? [...] For simplicity I've ignored hyphens, but it shouldn't be too difficult to add them (or use their position in the list of strings to restore the hyphenated words). This is what I got so far: \version "2.13.46" words = \lyricmode { This is my ex -- am -- ple text } #(define (lyrics->list lyrics) "Return a flat list containing all syllables and hyphens from @code{lyrics}." (let ((extracted-list (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) '( (flatten-list extracted-list))) text = #(lyrics->list words) melody = \relative c' { c4 d e f | g a c2 } \new Voice { \melody } \addlyrics { \words } #(markup* (make-line-markup text)) The function liyrics->list extracts the syllables and the hyphens. Cool! The second part (eliminating the hyphens in the list and concatenate the surrounding syllables) seems a bit harder, but I try to find a solution. That's a nice scheme exercise... The following would work (but not if there are consecutive hyphens) #(define (reduce-hyphens text) ;; Define initial first-word 'wd' and remaining-words 'wds' (let eat ((wd (car text)) (wds (cdr text))) (cond ;; Last syllable reached: Terminate recursion ((null? wds) (list wd)) ((and (equal? "--" (car wds)) (not (null? (cdr wds ;; The first remaining word is a hyphen AND there is a syllable after that ;; Concatenate that syllable onto wd, and recurse (eat (string-concatenate (list wd (cadr wds))) (cddr wds))) ;; Not a hyphen, just use wd as the first word on the list, and then recurse. (else (cons wd (eat (car wds) (cdr wds))) #(define (lyrics->text lyrics) (reduce-hyphens (lyrics->list lyrics))) text = #(lyrics->text words) Cheers Jakob. Regards, Marc ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
2011/1/18 Marc Hohl : > Am 15.01.2011 21:51, schrieb Neil Puttock: >> >> On 15 January 2011 19:01, Marc Hohl wrote: >> >>> Now I wonder whether it is possible to create a kind of text book by >>> including the lyrics in a markup, perhaps with a scheme function which >>> replaces the " -- " by "". >>> >>> Is it possible to store the text in a variable? >> >> [...] >> >> For simplicity I've ignored hyphens, but it shouldn't be too difficult >> to add them (or use their position in the list of strings to restore >> the hyphenated words). > > This is what I got so far: > > \version "2.13.46" > > words = \lyricmode { This is my ex -- am -- ple text } > > #(define (lyrics->list lyrics) > "Return a flat list containing all syllables and hyphens from > @code{lyrics}." > (let ((extracted-list > (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) > '( > (flatten-list extracted-list))) > > > text = #(lyrics->list words) > > melody = \relative c' { c4 d e f | g a c2 } > > \new Voice { \melody } > \addlyrics { \words } > > #(markup* (make-line-markup text)) > > The function liyrics->list extracts the syllables and the hyphens. Cool! > > The second part (eliminating the hyphens in the list and concatenate the > surrounding > syllables) seems a bit harder, but I try to find a solution. That's a nice scheme exercise... The following would work (but not if there are consecutive hyphens) #(define (reduce-hyphens text) ;; Define initial first-word 'wd' and remaining-words 'wds' (let eat ((wd (car text)) (wds (cdr text))) (cond ;; Last syllable reached: Terminate recursion ((null? wds) (list wd)) ((and (equal? "--" (car wds)) (not (null? (cdr wds ;; The first remaining word is a hyphen AND there is a syllable after that ;; Concatenate that syllable onto wd, and recurse (eat (string-concatenate (list wd (cadr wds))) (cddr wds))) ;; Not a hyphen, just use wd as the first word on the list, and then recurse. (else (cons wd (eat (car wds) (cdr wds))) #(define (lyrics->text lyrics) (reduce-hyphens (lyrics->list lyrics))) text = #(lyrics->text words) Cheers Jakob. > > Regards, > > Marc > > ___ > lilypond-user mailing list > lilypond-user@gnu.org > http://lists.gnu.org/mailman/listinfo/lilypond-user > ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Am 15.01.2011 21:51, schrieb Neil Puttock: On 15 January 2011 19:01, Marc Hohl wrote: Now I wonder whether it is possible to create a kind of text book by including the lyrics in a markup, perhaps with a scheme function which replaces the " -- " by "". Is it possible to store the text in a variable? [...] For simplicity I've ignored hyphens, but it shouldn't be too difficult to add them (or use their position in the list of strings to restore the hyphenated words). This is what I got so far: \version "2.13.46" words = \lyricmode { This is my ex -- am -- ple text } #(define (lyrics->list lyrics) "Return a flat list containing all syllables and hyphens from @code{lyrics}." (let ((extracted-list (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) '( (flatten-list extracted-list))) text = #(lyrics->list words) melody = \relative c' { c4 d e f | g a c2 } \new Voice { \melody } \addlyrics { \words } #(markup* (make-line-markup text)) The function liyrics->list extracts the syllables and the hyphens. The second part (eliminating the hyphens in the list and concatenate the surrounding syllables) seems a bit harder, but I try to find a solution. Regards, Marc ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
Am 15.01.2011 21:51, schrieb Neil Puttock: On 15 January 2011 19:01, Marc Hohl wrote: Now I wonder whether it is possible to create a kind of text book by including the lyrics in a markup, perhaps with a scheme function which replaces the " -- " by "". Is it possible to store the text in a variable? Store the lyrics first, then extract the text from the LyricEvent objects: \version "2.13.46" words = \lyricmode { This is my ex -- am -- ple text } text = #(map (lambda (x) (ly:music-property x 'text)) (extract-named-music words 'LyricEvent)) melody = \relative c' { c4 d e f | g a c2 } \new Voice { \melody } \addlyrics { \words } #(markup* (make-line-markup text)) For simplicity I've ignored hyphens, but it shouldn't be too difficult to add them (or use their position in the list of strings to restore the hyphenated words). Thanks for this solution! I'll investigate further how to concatenate the syllables of the hyphenated words ... Regards, Marc Cheers, Neil ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Using lyrics in a markup
On 15 January 2011 19:01, Marc Hohl wrote: > Now I wonder whether it is possible to create a kind of text book by > including the lyrics in a markup, perhaps with a scheme function which > replaces the " -- " by "". > > Is it possible to store the text in a variable? Store the lyrics first, then extract the text from the LyricEvent objects: \version "2.13.46" words = \lyricmode { This is my ex -- am -- ple text } text = #(map (lambda (x) (ly:music-property x 'text)) (extract-named-music words 'LyricEvent)) melody = \relative c' { c4 d e f | g a c2 } \new Voice { \melody } \addlyrics { \words } #(markup* (make-line-markup text)) For simplicity I've ignored hyphens, but it shouldn't be too difficult to add them (or use their position in the list of strings to restore the hyphenated words). Cheers, Neil ___ lilypond-user mailing list lilypond-user@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-user