Jump to content

Replacing some accidentals with a user-defined stencil: Difference between revisions

From LilyPond wiki
No edit summary
m New category
 
Line 32: Line 32:
[[Category:Pitches]]
[[Category:Pitches]]
[[Category:Scheme]]
[[Category:Scheme]]
[[Category:Tweaks and overrides]][[Category:Snippet]]
[[Category:Tweaks and overrides]]
[[Category:Snippet]]

Latest revision as of 23:38, 21 November 2025

Here is a way to replace all accidentals of any sort with an arbitrary stencil (in this case, a markup). Alterations are defined as 1 for a double-flat, -3/4 for a sesquiflat, etc.

\version "2.24"

%% Originally contributed by vv on -user-fr:
% https://lists.gnu.org/archive/html/lilypond-user-fr/2020-03/msg00130.html
%% This causes a rather ugly collision on older LilyPond versions.

doubleSharp = \markup \concat {
  \raise #-.15 \sharp \sharp
}

\layout {
  \context {
    \Score
    \override Accidental.stencil =
    #(lambda (grob)
       (if (= 3/4
         (ly:pitch-alteration
          (ly:event-property
           (ly:grob-property
            (ly:grob-property grob 'cause)
            'cause) 'pitch)))
        (grob-interpret-markup
         grob (markup doubleSharp))
        (ly:accidental-interface::print grob)))
  }
}

\relative c'{ cisis cisih des }