Hi,
I am trying to get accidentals to be reset at every word break in a section of music without meter; I found some code to advance the internalBarNumber, in order to force the accidentals to be reset:
resetAccidentals = \applyContext
#(lambda (x)
(begin
(ly:context-set-property!
(ly:context-property-where-defined x 'internalBarNumber)
'internalBarNumber
(1+ (ly:context-property x 'internalBarNumber)))
))
After this definition, putting in a \resetAccidentals in between words is working correctly causing the accidentals to get reset. However, I wanted something more automatic, but I am not sure exactly how to go about it. I remembered an engraver I had seen that collected lyric words by looking at lyric-hyphen-interface grobs and checking for LyricSpace ones, so I tried to write something to advance the internalBarNumber whenever a LyricSpace is encountered, but it isn't working reliably.
This is what I had:
resetAccidentalsAtNewWordsEngraver =
#(lambda (context)
(let ((new-word #f)) ; signal to end word and begin another
(make-engraver
(acknowledgers
((lyric-hyphen-interface engraver grob source-engraver)
(let* ((props (ly:grob-basic-properties grob))
(meta (assoc-get 'meta props))
(text-items (ly:grob-object grob 'text-items))
(name (assoc-get 'name meta)))
; reset accidentals by incrementing bar number at every LyricSpace
(if (eq? name 'LyricSpace) (ly:context-set-property!
(ly:context-property-where-defined context 'internalBarNumber)
'internalBarNumber
(1+ (ly:context-property context 'internalBarNumber)))))
))))
)
However, I am still trying to figure out how engravers and contexts work to be able to know exactly what's going on.
Thanks for any help or ideas,
Benjamin Bloomfield