Changing properties for individual grobs
The \applyOutput command allows the tuning of any layout object, in any context. It requires a Scheme function with three arguments.
In the example below, function mc-squared is executed for all NoteHead grobs (within the current Voice context) at the current time step; the function modifies the grob's stencil, using the staff-position property to replace some pitches with markup.
See the ‘Extending’ manual for more information.
\version "2.24"
#(define (mc-squared grob grob-origin context)
(let ((sp (ly:grob-property grob 'staff-position)))
(ly:grob-set-property!
grob 'stencil
(grob-interpret-markup grob
#{ \markup \lower #0.5
#(case sp
((-5) "m")
((-3) "c ")
((-2) #{ \markup \teeny \bold 2 #})
(else "bla")) #}))))
\relative c' {
<d f g b>2
\applyOutput Voice.NoteHead #mc-squared
<d f g b>2
}