Hi Michael,
this is easily accomplished with an custom engraver. (I perfectly
understand that the terms "easily" and "custom engraver" don't seem to
go well together at first - I thought so for many years as well -, but
after some getting used to it, the concept is actually quite simple and
elegant.)
\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)
(make-engraver
(listeners
((note-event engraver event)
(if (member (ly:event-property event 'pitch)
forced-accidentals-pitches
diatonic-pitch-class=)
(ly:event-set-property! event 'force-accidental #t))))))
\layout {
\context {
\Voice
\consists #Force_accidentals_engraver
}
}
\transpose a c' \relative
{
a8 gis g fis g gis a4
}
Lukas
Am 21.10.23 um 11:37 schrieb Michael Winter via LilyPond user discussion:
Thanks Jean,
I am not sure I completely follow.
Lets say I have a music sequence:
a b c d e f g a bes c d e f g ...
How do I apply what you have written as a function to only show the
flats and naturals for b and bes. Again. I do not want to apply this
to individual notes.
Sorry if I am missing something.
Best,
Michael
Oct 21, 2023, 01:37 by j...@abou-samra.fr:
Try
|\displayMusic c'! |
This shows you that the |!| syntax corresponds to setting the
|force-accidental| property to true. Thus, if you have identified
the note events you want to force accidentals on, you can do
|(ly:music-set-property! the-note-event 'force-accidental #t) |
on each of them.
Best,
Jean