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 07:04:36 -0700
User-agent: Roundcube Webmail/1.3.8

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



reply via email to

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