On 2019-04-25 7:37 am, David Kastrup wrote:
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
%%%%
That makes so much more sense. I did not know that dotted values could
be referenced that way, which is why I opted for the "sledge" instead of
ly:parser-lookup. I also had the case where the value I was
substituting was not the top-level value, but actually the bottom-level
in the structure.
But even with that constraint, I found the following works and avoids
the string concatenation:
%%%%
\version "2.19.82"
Alice.Lyrics.StanzaI = \lyricmode { a b c }
Alice.Lyrics.StanzaII = \lyricmode { d e f }
Bob.Lyrics.StanzaI = \lyricmode { g h i }
Bob.Lyrics.StanzaII = \lyricmode { j k l }
foo = #(define-music-function (singer stanza) (symbol? symbol?)
#{ \new Lyrics { $(ly:parser-lookup singer) . Lyrics . $stanza } #} )
\foo Alice StanzaI
\foo Bob StanzaII
%%%%
Curious though why in the above, I can say "Alice" in lieu of "#'Alice".
Is it simply because the music function's type assertion of "symbol?"
lets the parser consume the next string as such?
-- Aaron Hill
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user