lilypond-user
[Top][All Lists]
Advanced

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

Re: Function for /score block


From: Aaron Hill
Subject: Re: Function for /score block
Date: Thu, 25 Apr 2019 09:36:22 -0700
User-agent: Roundcube Webmail/1.3.8

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



reply via email to

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