[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing a parameter to Scheme
From: |
Aaron Hill |
Subject: |
Re: Passing a parameter to Scheme |
Date: |
Sat, 29 Oct 2022 04:22:51 -0700 |
On 2022-10-29 2:50 am, Paul Hodges wrote:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
speak = {
\once \override Stem.stencil =
#(lambda (grob)
(let* ((x-parent (ly:grob-parent grob X))
(is-rest? (ly:grob? (ly:grob-object x-parent 'rest))))
(if is-rest?
empty-stencil
(ly:stencil-combine-at-edge
(ly:stem::print grob)
Y
(- (ly:grob-property grob 'direction))
(grob-interpret-markup grob
(markup #:center-align #:fontsize
-2
#:musicglyph
"noteheads.s2cross"))
-2.3))))
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This works fine, writing "\speak c4" for instance.
However, I'd like to be able to parameterise the position of the cross
which is hard-coded as -2.3, so that I can write "\speak #-3.8 c" for
instance. I've tried a couple of ways to write it, but I can't find
one that works. I suppose that I will need something like "lambda
(grob posn)" to define the parameter for use at the end, but I can't
see how to get the value of posn from the LilyPond source into the
Scheme procedure.
Review the documentation on defining and using music functions:
[1]:
https://lilypond.org/doc/v2.23/Documentation/extending/music-functions
You could end up with something like this:
%%%%
speak =
#(define-music-function
(position)
(number?)
(define (stencil-proc grob)
(let* ((x-parent (ly:grob-parent grob X))
(is-rest? (ly:grob? (ly:grob-object x-parent 'rest))))
(if is-rest?
empty-stencil
(ly:stencil-combine-at-edge
(ly:stem::print grob)
Y
(- (ly:grob-property grob 'direction))
(grob-interpret-markup grob
(markup #:center-align #:fontsize -2
#:musicglyph "noteheads.s2cross"))
(- position)))))
#{ \once \override Stem.stencil = #stencil-proc #})
{
\speak 1.6 g'4
\speak 2.2 b'8 8
\speak 2.8 a'2
}
%%%%
-- Aaron Hill