Thanks!

This seems to work quite well : )

But I am confused about what you said. For me, it is posting the accidental on 
tied notes after line breaks.

Best,

Michael

Oct 28, 2023, 22:40 by l...@gmx.de:

> Hi Michael,
>
>> Thanks Lukas!
>>
>> This works but also forces the accidental on tied notes.
>>
>
> Sorry for not getting back to you sooner.
>
> The following version registers ties and removes our auto-generated 
> accidentals for notes in which a tie ends. (It's a bit overeager and also 
> removes tied accidentals after line breaks, so we get a behaviour as if 
> Accidental.hide-tied-accidental-after-break is set to ##t. Please give word 
> if you want me to change that.)
>
> Lukas
>
> \version "2.24.0"
>
> forced-accidentals-pitches =
> #(music-pitches #{ bes b #})
>
> #(define (diatonic-pitch-class= p q)
>    (and (= (ly:pitch-notename p) (ly:pitch-notename q))
>         (= (ly:pitch-alteration p) (ly:pitch-alteration q))))
>
> Force_accidentals_engraver =
> #(lambda (context)
>    (let
>     ((ties '())
>      (affected-note-events '()))
>    (make-engraver
>     (end-acknowledgers
>      ((tie-interface engraver grob source-engraver)
>       (set! ties (cons grob ties))))
>     ((stop-translation-timestep engraver)
>      (for-each
>       (lambda (tie)
>         (let* ((right-notehead (ly:spanner-bound tie RIGHT))
>                (right-notehead-cause (ly:grob-property right-notehead 
> 'cause)))
>           (if (member right-notehead-cause affected-note-events)
>               (ly:grob-suicide!
>                ;;; the accidental grob should be guaranteed to
>                ;;; exist since we forced it into existence...
>                (ly:grob-object
>                 right-notehead 'accidental-grob)))))
>       ties)
>      (set! ties '())
>      (set! affected-note-events '()))
>     (listeners
>      ((note-event engraver event)
>       (when (member (ly:event-property event 'pitch)
>                     forced-accidentals-pitches
>                     diatonic-pitch-class=)
>         (ly:event-set-property! event 'force-accidental #t)
>         (set! affected-note-events
>               (cons event affected-note-events))))))))
>
> \layout {
>   \context {
>     \Voice
>     \consists #Force_accidentals_engraver
>   }
> }
>
> \transpose a c' \relative
> {
>   a8 gis~ gis g fis g gis a
>   gis1~ gis2 gis
> }
>

Reply via email to