[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dashed Stem

From: David Nalesnik
Subject: Re: Dashed Stem
Date: Sat, 12 May 2012 07:32:39 -0500


On Sat, May 12, 2012 at 3:05 AM, Urs Liska <address@hidden> wrote:
Hi David, Hi Thomas,

thank you very much!
I'm increasingly fascinated by LilyPond - and this mailing list.
And I'll definitely have to learn how to write Scheme functions myself ...

With your suggestions I can really solve the problem at hand, so thanks.
What I especially like about the new solution is that it automatically uses the original Stem's thickness (so it's independent from overrides.

Maybe it would be nice to be able to use this more generally (as a \stemDashed command). But for this it shouldn't have a fixed number of dashes but rather a consistent dash pattern (independent from the Stem's length. Although I don't really understand the function, I assume that the original Stem's length is already used. So it should be quite simple to use this and calculate the dashes from that?
I don't expect to be able to apply such complex operations as curve's 'dash-definition. But if one would use two variables that are defined in the function's file one could then redefine them in the music file.

I've come up with a simpler variant which makes use of the 'dashed-line function.  (I didn't use this initially because I couldn't figure out how to get the roundedness of the line segments to match the ordinary stem's and also because I wanted to ensure a full-length dash at top and bottom.)

These functions require two arguments: one for the length of the dash and one for the length of the spaces in between.  Setting values might require some trial and error.  Some combinations won't fit the length of the stem such that a segment appears at its end.

See what you think!

\version "2.15.38"

#(define (dashed-stem on off)
  (lambda (grob)
    (let* ((stencil (ly:stem::print grob))
           (X-ext (ly:stencil-extent stencil X))
           (Y-ext (ly:stencil-extent stencil Y))
           (width (interval-length X-ext))
           (len (interval-length Y-ext)))

      (ly:output-def-set-variable! (ly:grob-layout grob) 'blot-diameter 0.08)
          `(dashed-line ,width ,on ,off 0 ,len 0))
        (cons 0 (interval-start Y-ext))))))

dashedStem =
#(define-music-function (parser location on off) (number? number?)
  \once \override Stem #'stencil = #(dashed-stem on off)

\relative c'' {
  \dashedStem #0.5 #0.75
  \dashedStem #0.5 #0.5
  \dashedStem #0.25 #0.5
  \dashedStem #0.25 #0.25


reply via email to

[Prev in Thread] Current Thread [Next in Thread]