|
From: | Pierre Perol-Schneider |
Subject: | Re: replace-stencil and overlay-stencil (was: Re: time signature 4 / \breve ?) |
Date: | Thu, 17 Oct 2019 07:53:25 +0200 |
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_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user
[Prev in Thread] | Current Thread | [Next in Thread] |