Hi again,

On Fri, May 11, 2012 at 11:24 AM, David Nalesnik
<david.nales...@gmail.com>wrote:

> Hi Urs,
>
> On Fri, May 11, 2012 at 7:06 AM, Urs Liska <li...@ursliska.de> wrote:
>
>> Am I right that you can't make a Stem dashed? I didn"t find anything in
>> the IR.
>>
>> What would then be the proper way to attach a dashed line to a note in
>> place of the Stem?
>>
>>
> Here's something I came up with.  It's not ideal.  If you compare the
> substitute stems with ordinary stems, you'll find differences.  (These
> relate, I think, to how rounded the lines are--to 'blot-diameter.)  But
> hopefully this will do.
>
> The argument allows you to specify the number of dashes in your stem.
>

Looking at this some more, I've come up with an alternate which more
closely duplicates an ordinary stem.  Instead of using line segments, I
used round-filled-box stencils, which is what Lily uses to draw stems.

Everything is fine when the dashes aren't too small.  If you ask for more
than 6 at staff-size 20, though, some dashes won't appear.  You see similar
behavior if the staff size is reduced.  (To see this, uncomment the line at
the top of the function.)  I'm not sure what's going on here, if this is a
limitation of 'round-filled-box, or something I'm doing wrong.

Anyway, here it is:

\version "2.15.38"

%#(set-global-staff-size 14)

#(define (dashed-stem num)
  (lambda (grob)
    (let* ((stencil (ly:stem::print grob))
           (X-ext (ly:stencil-extent stencil X))
           (Y-ext (ly:stencil-extent stencil Y))
           (b-d (ly:output-def-lookup (ly:grob-layout grob) 'blot-diameter))
           (len (interval-length Y-ext))
           (lst '())
           (factors
             (map
               (lambda (x) (* (/ len (1- (* 2 num))) x))
               (iota (* 2 num)))))

     (define (helper args)
       (set! lst
             (cons
               (ly:make-stencil
                 `(round-filled-box
                   (- ,(car X-ext))
                   ,(cdr X-ext)
                   (- ,(+ (car Y-ext) (car args)))
                   ,(+ (car Y-ext) (cadr args))
                   ,b-d)
                 X-ext
                 Y-ext)
               lst))

       (if (null? (cddr args))
           lst
           (helper (cddr args))))

     (if (zero? num)
         stencil
         (apply ly:stencil-add (helper factors))))))

\relative c'' {
  \once \override Stem #'stencil = #(dashed-stem 2)
  c
  \once \override Stem #'stencil = #(dashed-stem 3)
  d
  \once \override Stem #'stencil = #(dashed-stem 5)
  e
  \once \override Stem #'stencil = #(dashed-stem 6)
  f
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to