Aaron Hill <lilyp...@hillvisions.com> writes: > I found using ly:parser-include-string was helpful for this purpose.
That's a sledgehammer. > Consider the following: > > %%%% > \version "2.19.82" > > Alice.Melody = \fixed f' { f4 g a bes c'1 } > Alice.Lyrics = \lyricmode { do re mi fa sol } > > Bob.Melody = \fixed f' { c'4 bes d' g a1 } > Bob.Lyrics = \lyricmode { sol fa la re mi } > > Global = { > \key f \major > s1*2 \bar "|." > } > > makeItSo = #(define-music-function (label) (symbol?) > (define (lookup section) (ly:parser-include-string > (format #f "\\~a.~a" label section))) > #{ << > \new Staff \with { > instrumentName = $(symbol->string label) > } << > \Global > \new Voice = "melody" { $(lookup 'Melody) } > >> > \new Lyrics \lyricsto "melody" { $(lookup 'Lyrics) } > >> #} ) > > \makeItSo #'Alice > \makeItSo #'Bob > %%%% > > This \makeItSo is akin to a macro, able to inject a dynamically > constructed string into the parser as if it were typed by hand. With the same interface, I'd use %%%% \version "2.19.82" Alice.Melody = \fixed f' { f4 g a bes c'1 } Alice.Lyrics = \lyricmode { do re mi fa sol } Bob.Melody = \fixed f' { c'4 bes d' g a1 } Bob.Lyrics = \lyricmode { sol fa la re mi } Global = { \key f \major s1*2 \bar "|." } makeItSo = #(define-music-function (label) (symbol?) (let ((name (symbol->string label)) (value (ly:parser-lookup label))) #{ << \new Staff \with { instrumentName = #name } << \Global \new Voice = "melody" { $value . Melody } >> \new Lyrics \lyricsto "melody" { $value . Lyrics } >> #} )) \makeItSo #'Alice \makeItSo #'Bob %%%% But I don't like this kind of double-serve and it's not particularly flexible, so I'd rather use %%%% \version "2.19.82" Alice.Melody = \fixed f' { f4 g a bes c'1 } Alice.Lyrics = \lyricmode { do re mi fa sol } Bob.Melody = \fixed f' { c'4 bes d' g a1 } Bob.Lyrics = \lyricmode { sol fa la re mi } Global = { \key f \major s1*2 \bar "|." } makeItSo = #(define-music-function (name value) (markup? list?) #{ << \new Staff \with { instrumentName = #name } << \Global \new Voice = "melody" { $value . Melody } >> \new Lyrics \lyricsto "melody" { $value . Lyrics } >> #} ) \makeItSo "Alice" \Alice \makeItSo "Bob" \Bob %%%% Or you could also refer to this from a main variable by putting Alice.name = "Alice" Bob.name = "Bob" and then fetching stuff from there. -- David Kastrup _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user