Changing properties for individual grobs: Difference between revisions
Appearance
m New category Tags: Mobile edit Mobile web edit |
extend documentation |
||
| Line 1: | Line 1: | ||
The <code>\applyOutput</code> command allows the tuning of any layout object, in any context. It requires a Scheme function with three arguments. | The <code>\applyOutput</code> command allows the tuning of any layout object, in any context. It requires a Scheme function with three arguments. | ||
In the example below, function <code>mc-squared</code> is executed for all <code>NoteHead</code> grobs (within the current <code>Voice</code> context) at the current time step; the function modifies the grob's <code>stencil</code>, using the <code>staff-position</code> property to replace some pitches with markup. | |||
See the [https://lilypond.org/doc/v2.24/Documentation/extending/running-a-function-on-all-layout-objects ‘Extending’ manual] for more information. | |||
<lilypond version="2.24"> | <lilypond version="2.24"> | ||
| Line 7: | Line 11: | ||
grob 'stencil | grob 'stencil | ||
(grob-interpret-markup grob | (grob-interpret-markup grob | ||
#{ \markup \lower #0.5 | |||
#(case sp | |||
((-5) "m") | |||
((-3) "c ") | |||
((-2) #{ \markup \teeny \bold 2 #}) | |||
(else "bla")) #})))) | |||
\relative c' { | \relative c' { | ||
| Line 21: | Line 25: | ||
</lilypond> | </lilypond> | ||
[[Category:Really cool]] | |||
[[Category:Scheme]] | [[Category:Scheme]] | ||
[[Category:Tweaks and overrides]] | [[Category:Tweaks and overrides]] | ||
[[Category:Included in the official documentation]] | [[Category:Included in the official documentation]] | ||
[[Category:Snippet]] | [[Category:Snippet]] | ||
Revision as of 17:46, 26 December 2025
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
}