[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
replace-stencil and overlay-stencil (was: Re: time signature 4 / \breve
From: |
Aaron Hill |
Subject: |
replace-stencil and overlay-stencil (was: Re: time signature 4 / \breve ?) |
Date: |
Wed, 16 Oct 2019 21:42:00 -0700 |
User-agent: |
Roundcube Webmail/1.3.8 |
On 2019-10-16 7:00 pm, Graham King wrote:
\version "2.19.82"
{
\once \override Staff.TimeSignature #'stencil =
#(lambda (grob)
(grob-interpret-markup
grob
#{ \markup
\override #'(baseline-skip . 1)
\center-column {
\musicglyph "four"
\musicglyph "noteheads.sM1" } #}))
\time 8/1
c'\breve c' c' c'
}
If you find yourself doing this type of stencil \override on a regular
basis, you could wrap it up in a more general-purpose helper similar to
the following:
%%%%
\version "2.19.83"
replace-stencil = #(define-music-function (grob text) (grob-list?
markup?)
(define (stencil grob) (grob-interpret-markup grob text))
#{ \override $grob . stencil = $stencil #})
{
\once \replace-stencil Staff.TimeSignature
\markup \override #'(baseline-skip . 1)
\center-column { \musicglyph "four" \musicglyph "noteheads.sM1" }
\time 8/1 c'\breve c' c' c'
}
%%%%
Putting together the function above got me thinking about and working on
a version that overlays \markup on an existing stencil instead of
replacing it:
%%%%
\version "2.19.83"
overlay-stencil = #(define-music-function (grob align text)
(grob-list? (number-pair? '(0 . 0)) markup?)
(define stencil (grob-transformer 'stencil (lambda (grob orig)
(let ((x (interval-index (ly:stencil-extent orig X) (car align)))
(y (interval-index (ly:stencil-extent orig Y) (cdr align)))
(new (grob-interpret-markup grob text)))
(ly:stencil-add orig (ly:stencil-translate new (cons x y)))))))
#{ \override $grob . stencil = $stencil #})
red-x = \markup \with-dimensions-from \null
\vcenter \center-align \with-color #red "X"
{
\overlay-stencil Staff.Clef #'(-1 . 1) "Clef"
b'8 c''
\temporary \overlay-stencil NoteHead \red-x
g' a'
\revert NoteHead.stencil
b'2
}
%%%%
Not sure how useful these would be in practice, but the resulting syntax
might be preferable for some folks.
-- Aaron Hill
overlay-stencil.cropped.png
Description: PNG image