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?

Cheers,

Steven

MWE:
#(set-object-property! 'instrument 'translation-type? string?)

#(define instruments
  `(
    (flute . (
      (id . "flute")
      (clef . "treble")
    ))))

makeMusic =
#(define-music-function
  (music) (ly:music?)
    (make-apply-context
      (lambda (context)
        (let* (
               (instrument-symbol (ly:context-property context 'instrument))
               (instrument (assoc-ref instruments instrument-symbol))
               (clef (if instrument (assoc-ref instrument 'clef) 'treble))
              )
        #{
          \clef #clef
          #music
        #}
        )
      )
    )
)

\score {
  \new Staff \with {
    instrument = #'flute
  } { \makeMusic \relative { c'4 d e f } }
}

Reply via email to