Hello Steven, > Hi, > > I'm trying to create a script to automate certain things (setting > instrument name, default clef, transposition) based on a custom property > 'instrument' that is set when creating a new staff. I'm having trouble > retrieving that property when generating the music for that staff. Using > \applyContext or make-apply-context always results in a warning: > > warning: skipping zero-duration score
The issue here is that Lilypond works more or less in 3 stages:
→ The file is parsed and music expressions are gathered into scores
→ The music expressions are translated into grobs, which requires iteration
and sending stuff to engravers
→ The grobs are spaced on the paper and printed
The problem is that the context information only exists in the second step, so
\applyContext needs to delay evaluation until the second step. Thus it simply
returns 0-length music, and whatever the given function does, its return is
disregarded.
The 'ApplyContext music type has an iterator that will simply call the given
function in the current time. What you’d need would be a version that does
that and then calls the iterator of whatever music object that function
returns.
That being said, there is no real reason to do things that way. All things you
have given can be set directly on the context level. But rather than doing
that, they can all be applied in the \with-block. So rather you could do
something like:
%%%
instruments =
#`(
(flute
.
,#{
\with {
\clef "treble"
instrumentName = "Flauto"
}
,#})
(bassoon
.
,#{
\with {
\clef "bass"
instrumentName = "Fagotto"
}
#})
)
instrument =
#(define-scheme-function (instrument) (symbol?)
(assoc-get instrument instruments #{ \with { } #}))
\score {
<<
\new Staff \with { \instrument #'flute } \relative { c'4 d e f }
\new Staff \with { \instrument #'bassoon } \relative { c4 d e f }
\new Staff \with { \instrument #'not-in-list } \relative { c'4 d e f }
>>
}
%%%
Cheers,
Tina
signature.asc
Description: This is a digitally signed message part.
