Am Freitag, 6. Dezember 2024, 15:40:53 MEZ schrieb Steph Phillips: > Hi all, this one's probably a simple solution, but I'm a little fuzzy on > how to implement custom Scheme functions still. > > I'm working on a musical theater score, and there are lots of instrument > changes formatted like this: > > changeBbClar = ^\markup { > \general-align #X #-0.7 > \bold > \override #'(box-padding . 0.5) \box > "Bb Clarinet" > } > > My end goal is a function where I can define the name of the instrument > and the x-alignment - something like > > \InstrumentChange "Bb Clarinet" #-0.7 > > Thanks a ton, > ~Steph
Hi Steph, in this particular case it might be useful to create an engraver which automatically annotates changes in instrument name. This not only gives you the regular overriding interface for changing things, it also gives you a lot of possibilities for the formatting of the style in question. See the appended file for how this can be done. Cheers, Valentin
#(define* (define-grob! grob-name grob-entry #:optional (extends #f)) (set! all-grob-descriptions (cons ((@@ (lily) completize-grob-entry) (cons grob-name (if extends (append grob-entry (assoc-get extends all-grob-descriptions '())) grob-entry))) all-grob-descriptions))) #(define-grob! 'InstrumentChange `( (direction . ,UP) (font-series . bold) (text . ,(lambda (grob) (markup #:override '(box-padding . 0.5) #:box (assoc-get 'to-instrument (ly:grob-property grob 'details) "")))) ) 'TextScript) \layout { \context { \Global \grobdescriptions #all-grob-descriptions } } #(define (instrument-change-engraver context) (let ((instrument-name #f)) (make-engraver ((initialize engraver) (set! instrument-name (ly:context-property context 'instrumentName))) ((process-music engraver) (if (not (equal? instrument-name (ly:context-property context 'instrumentName))) (let ((grob (ly:engraver-make-grob engraver 'InstrumentChange '()))) (ly:grob-set-nested-property! grob '(details from-instrument) instrument-name) (ly:grob-set-nested-property! grob '(details to-instrument) (ly:context-property context 'instrumentName)))) (set! instrument-name (ly:context-property context 'instrumentName)))))) \layout { \context { \Staff \consists #instrument-change-engraver } } \new Staff \with { instrumentName = "Clarinet in A" } { c'4 d' e' f' | \set Staff.instrumentName = "Clarinet in Bb" g' a' b' } \new Staff \with { instrumentName = "Clarinet in A" } { c'4 d' e' f' | \override Staff.InstrumentChange.self-alignment-X = #-0.7 \set Staff.instrumentName = "Clarinet in Bb" g' a' b' } \new Staff \with { instrumentName = "Clarinet in A" } { c'4 d' e' f' | \override Staff.InstrumentChange.text = #(lambda (grob) (markup (assoc-get 'from-instrument (ly:grob-property grob 'details) "(?)") " → " (assoc-get 'to-instrument (ly:grob-property grob 'details) "(?)"))) \set Staff.instrumentName = "Clarinet in Bb" g' a' b' }
signature.asc
Description: This is a digitally signed message part.