Le 26/12/2022 à 17:39, Rip _Mus a écrit :
Hello,is there a way to modify a spanner to get a slow-fast trill (like the one in the picture)?Obviously with user-provided glyphs.
Try \version "2.24.0" slowFastTrill = \tweak TrillSpanner.stencil #(lambda (grob) (let* ((left (ly:spanner-bound grob LEFT)) (right (ly:spanner-bound grob RIGHT)) (sys (ly:grob-system grob)) (my-coord (ly:grob-relative-coordinate grob sys X)) (trill-start-x (interval-start (ly:grob-extent left sys X))) (glyph-stil (ly:stencil-translate-axis (ly:stencil-aligned-to (grob-interpret-markup grob#{ \markup \general-align #Y #CENTER \musicglyph "scripts.trill" #})
X LEFT) trill-start-x X)) (squiggle-glyph-stil (grob-interpret-markup grob#{ \markup \lower #0.6 \general-align #X #LEFT \musicglyph "scripts.trill_element" #})) (squiggle-glyph-width (interval-length (ly:stencil-extent squiggle-glyph-stil X)))
(start-x (+ (interval-end (ly:stencil-extent glyph-stil X)) 0.8)) (end-x (interval-start (ly:grob-extent right sys X))) (thickness (* (ly:grob-property grob 'thickness 2.0) (ly:staff-symbol-line-thickness grob))) (det (ly:grob-property grob 'details)) (squiggle-height (assoc-get 'squiggle-height det 0.3))(squiggle-initial-width (assoc-get 'squiggle-initial-width det 2.0)) (squiggle-speed-factor (assoc-get 'squiggle-speed-factor det 0.4))
(squiggle-Y-scale (assoc-get 'squiggle-Y-scale det 0.55))) (let loop ((x start-x) (dir UP) (i 1) (stil glyph-stil)) (if (>= x end-x) (ly:stencil-translate-axis stil (- my-coord) X)(let ((width (* squiggle-initial-width (/ (expt i squiggle-speed-factor)))))
(loop (+ x width) (- dir) (1+ i) (let ((squiggle (ly:stencil-translate-axis (ly:stencil-scale squiggle-glyph-stil(/ width squiggle-glyph-width)
squiggle-Y-scale)
x
X)))
(ly:stencil-add stil squiggle))))))))
\startTrillSpan
{
\pitchedTrill c''1_~\slowFastTrill des'' c''1
<>\stopTrillSpan
\once \override TrillSpanner.thickness = 3
\once \override TrillSpanner.details.squiggle-initial-width = 0.4
\once \override TrillSpanner.details.squiggle-Y-scale = 0.8
%% Use a negative value for a fast-slow trill.
%% Bad things will happen if you set this to 1 or more!
\once \override TrillSpanner.details.squiggle-speed-factor = -0.6
\pitchedTrill c''1_~\slowFastTrill des'' c''1
<>\stopTrillSpan
}
This is basically a hastily written variant of ly:line-spanner::print
that only caters for trills and does not handle all the stuff like
padding, text at the right end, line breaks, etc.
Perhaps we should change LilyPond to introduce a line-stencil property
for line spanners that would be read by stencil to provide the line
stencil, while stencil would add the texts and whatnot. Reimplementing
the full stencil callback is cumbersome, and I feel like I've done
this sort of thing a thousand times already.
I'm trying to figure out how spanners were written to be able to at least modify an existing one, TextSpanner or TrillSpanner, (or write one on purpose, if it's not too complicated, but I guess it is!), but I can't find the definitions.
The grob definitions can be viewed in the Internals Reference, or alternatively in the Scheme source code in scm/define-grobs.scm: https://gitlab.com/lilypond/lilypond/-/blob/master/scm/define-grobs.scm The bulk of the logic for TrillSpanner, TextSpanner and such is in the C++ file lily/line-spanner.cc: https://gitlab.com/lilypond/lilypond/-/blob/master/lily/line-spanner.cc Best, Jean
OpenPGP_signature
Description: OpenPGP digital signature
