Hi Tina, Thanks for the explanation. I'm still learning to get my grips with Lilypond. My original idea was to create instrument templates so: - I don't have to declare all the \with stuff every time - I can be flexible too. I want to be able to add more to the \with block if needed - I can switch between languages for instrument names - I can choose how to show transposition in instrument names (Clarinet in Bb vs. Clarinet (Bb)) - I can switch between concert and transposed switch with a single setting
Turns out there's already a module in OpenLilyLib that does the latter which I'll try out: https://github.com/openlilylib/oll-misc/tree/master/pitch/auto-transpose For now I'll settle with: \score { \new Staff \with { instrument = #'flute \setInstrumentName % custom function that sets the instrument name with transposition % etc } { \makeMusic #'flute \relative { c'4 d e f } } % explicitly state instrument again which handles the transposition } Cheers, Steven Op do 12 jun 2025 om 09:08 schreef Valentin Petzel <[email protected]>: > 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
