On Tue, Sep 6, 2016 at 11:07 AM, Marc Hohl <m...@hohlart.de> wrote:
> Am 06.09.2016 um 16:09 schrieb David Nalesnik:

>> Even if you for this to work, your mockup shows a line more complex
>> than a squiggle.  You'd only be able to get a simple zigzag line,
>> without the refinement at the ends, and without control of the
>> "amplitude" (as if my simple example below).
>
>
> I found out that the aplitude may be controlled by
>
> \override Staff.MultiMeasureRest.zigzag-length = #1.33
> \override Staff.MultiMeasureRest.zigzag-width = #1.33
>
> and playing around with these values.

Aha!

Well, I found time to finish what I started.  See attached. I added a
possibility of a wavy line.

David
\version "2.19.46"

#(define (make-zigzag-squiggle startX endX squiggle-length squiggle-height)
   (let* ((len (- endX startX))
          (squiggle-count (floor (/ len squiggle-length)))
          (leftover (- len (* squiggle-length squiggle-count))))
     (let loop ((start (+ startX (/ leftover 2)))
                (sqc squiggle-count)
                (y squiggle-height) ; amplitude
                (result '()))
       (if (= sqc 0)
           (append result (list (list endX 0)))
           (loop
            (+ start squiggle-length)
            (1- sqc)
            (* -1 y)
            (append result
              (list
               (list start 0)
               (list (+ start (/ squiggle-length 2)) y)
               (list (+ start squiggle-length) 0))))))))

#(define (make-wavy-squiggle startX endX squiggle-length squiggle-height)
   (let* ((len (- endX startX))
          (squiggle-count (floor (/ len squiggle-length)))
          (leftover (- len (* squiggle-length squiggle-count))))
     (let loop ((start (+ startX (/ leftover 2)))
                (sqc squiggle-count)
                (y squiggle-height) ; amplitude
                (result (list (list (+ startX (/ leftover 2)) 0))))
       (if (= sqc 0)
           (reverse (cons (list endX 0) result))
           (loop
            (+ start squiggle-length)
            (1- sqc)
            (* -1 y)
            (cons
             (list
              start 0
              (+ start (/ squiggle-length 2)) y
              (+ start squiggle-length) 0)
             result))))))

#(define* (my-big-rest grob proc squiggle-len squiggle-height #:optional width)
   (let* ((thick-thick (ly:grob-property grob 'thick-thickness 1.0))
          (hair-thick (ly:grob-property grob 'hair-thickness 0.1))
          (ss (ly:staff-symbol-staff-space grob))
          (slt (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
          (y (* slt (/ thick-thick 2) ss))
          (ythick (* hair-thick slt ss))
          (blot (if width (* 0.8 (min y ythick)) 0.0))
          (width (if width width 0.0))

          ;; default
          ;(m (ly:round-filled-box
          ;   (cons 0.0 (max 0.0 (- width (* 2 ythick))))
          ;  (cons (- y) y)
          ;  blot))

          (m (make-connected-path-stencil
              (proc 0 width squiggle-len squiggle-height)
              ythick 1 1 #f #f))

          (yb (ly:round-filled-box
               (offset-scale (cons -0.5 0.5) ythick)
               (cons (- ss) ss)
               blot))
          (m (ly:stencil-combine-at-edge m X RIGHT yb 0))
          (m (ly:stencil-combine-at-edge m X LEFT yb 0))
          (m (ly:stencil-aligned-to m X LEFT)))
     m))

#(define (my-stencil proc squiggle-length squiggle-height)
   (lambda (grob)
     (let* ((default-stil (ly:multi-measure-rest::print grob))
            (X-ext (ly:stencil-extent default-stil X))
            (len (interval-length X-ext)))
       (if (< len 2)
           default-stil
           (let* ((my-stil (my-big-rest grob proc squiggle-length squiggle-height len))
                  (sys (ly:grob-system grob))
                  (pos (ly:grob-relative-coordinate grob sys X)))
             ;; stencil from my-big-rest will be at 0.0; move it to X position of default
             (ly:stencil-translate-axis my-stil (car X-ext) X))))))

\markup \bold "DEFAULT:"

{
  \compressFullBarRests
  R1*24
  R1*4
  R1*72
}

\markup \bold "ZIGZAG:"

{
  \override Staff.MultiMeasureRest.stencil = #(my-stencil make-zigzag-squiggle 2 1) % squiggle length, height
  \compressFullBarRests
  R1*24
  % ignored
  R1*4
  \once \override Staff.MultiMeasureRest.stencil = #(my-stencil make-zigzag-squiggle 3 1)
  R1*72
}

\markup \bold "WAVY:"

{
  \override Staff.MultiMeasureRest.stencil = #(my-stencil make-wavy-squiggle 2 1)
  \compressFullBarRests
  R1*24
  R1*4
  \once \override Staff.MultiMeasureRest.stencil = #(my-stencil make-wavy-squiggle 3 2)
  R1*72
}

\layout {
  indent = 0
  ragged-right = ##f
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to