On 2019-04-24 10:01 pm, foxfanfare wrote:
[ . . . ] The only thing
that might change is the name of the piece (here it is "IA"). I wonder,
is
it possible, instead of copying each time the same instrumentation, to
call
this block in a function and replace each time the name of the piece by
the
one defined? For instance, something like "\instrumentation #"IA"" or
"\instrumentation #"IB"", etc...
I had to typeset some hymns for projection recently and wanted a way to
reduce the amount of typing when it came to scores and books that were
basically the same structurally. (In my case, I was using a void
function and calling print-book-with-defaults since I was constructing a
\book, not the body of a \score.)
I found using ly:parser-include-string was helpful for this purpose.
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.
-- Aaron Hill
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user