On 09/06/2025 21:19, Steven Senden wrote:
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


I'm totally new to scripting and Scheme, so I'm at a bit of a loss. Could anybody shed their light on this?

I am sure that it would be possible to figure out a solution based on your initial thoughts, but here is an alternative that I have used.

\version "2.24.4"

\layout {
  indent = 3\cm
  \context {
    \Staff
    \name "ClarinetBflat"
    \alias Staff
    instrumentName = "Clarinet in B♭"
    shortInstrumentName = "Cl."
    \clef "treble"
  }
  \inherit-acceptability ClarinetBflat Staff
}

\midi {
  \context {
    \Staff
    \name "ClarinetBflat"
    instrumentTransposition = bes
  }
  \inherit-acceptability ClarinetBflat Staff
}

\score {
  \new ClarinetBflat { c'4 d' e' f' }
  \layout {}
  \midi {}
}

You could perhaps automate this further by writing scheme functions to return the contexts, looking up data in your table of instrument properties.

layoutcxt = #(define-scheme-function (instrument) (symbol?)
  #{
    \context {
      \Staff
      \name #(symbol->string instrument)
      \alias Staff
      ...
    }
  #}
)

\layout {
  \layoutcxt #'ClarinetBflat
  \inherit-acceptability ClarinetBflat Staff
}


--
Timothy Lanfear, Bristol, UK.

Reply via email to