Subject: squiggle-line

From: philhar <[email-masked]>
Date: Fri, 15 Oct 2021 22:35:36 +0200

Bonjour.

Le TextSpanner n'accepte que des lignes continues ou discontinues, le 
trille, ou le zigzag. Il est utilisable sur une série notes avec 
\startTextSpan et \stopTextSpan.
Je voudrais une ondulation comme proposée par \draw-squiggle-line, mais 
ça ne marche que dans un \markup, donc sur une seule note.
Comment demander au TextSpanner de tracer une squiggle-line, avec les 
personnalisations possibles comme dans un markup (hauteur, longueur)  ?

Cordialement,
Michel

---

From: Jean Abou Samra <[email-masked]>
Date: Sat, 16 Oct 2021 02:29:27 +0200

Le 15/10/2021 à 22:35, philhar a écrit :
> Je voudrais une ondulation comme proposée par \draw-squiggle-line, 
> mais ça ne marche que dans un \markup, donc sur une seule note.

Bonjour,

C'est possible, en recodant certaines parties de la
fonction ly:line-spanner::print définie en C++. Voici
une proposition.

Cordialement,
Jean

\version "2.22.1"

#(use-modules (srfi srfi-11))

#(define (draw-text-spanner-allow-squiggle grob)
    (if (eq? 'squiggle (ly:grob-property grob 'style))
        (let*
          ((linfo (ly:grob-property grob 'left-bound-info))
           (rinfo (ly:grob-property grob 'right-bound-info))
           (common-X
             (ly:grob-common-refpoint
               (ly:grob-common-refpoint
                 (ly:spanner-bound grob LEFT)
                 (ly:spanner-bound grob RIGHT)
                 X)
               grob
               X))
           (lx (assoc-get 'X linfo 0.0))
           (rx (assoc-get 'X rinfo 0.0))
           (mag (expt 2 (* 1/6 (ly:grob-property grob 'font-size 0.0))))
           (lgap (* mag (assoc-get 'padding linfo 0.0)))
           (rgap (- (* mag (assoc-get 'padding rinfo 0.0)))))
          (if (< (- rx lx)
                 (+ lgap rgap))
              '()
              (let* ((coord (ly:grob-relative-coordinate grob common-X X))
                     (nlx (+ lx lgap (- coord)))
                     (nrx (+ rx rgap (- coord))))
                (define (stencil+correction d info)
                  (let ((stencil (assoc-get 'stencil info #f)))
                    (if stencil
                        (let* ((align (assoc-get 'stencil-align-dir-y 
info #f))
                               (aligned
                                 (if align
                                     (ly:stencil-aligned-to stencil Y align)
                                     stencil))
                               (offset (assoc-get 'stencil-offset info #f))
                               (offset-stencil
                                 (if offset
                                     (ly:stencil-translate aligned
(coord-scale offset mag))
                                     aligned))
                               (ext (ly:stencil-extent offset-stencil X)))
                          (values offset-stencil (interval-index ext (- 
d))))
                        (values empty-stencil 0))))
                (let-values
                  (((ls lc)
                    (stencil+correction LEFT linfo))
                   ((rs rc)
                    (stencil+correction RIGHT rinfo)))
                  (let ((lp (+ nlx lc))
                        (rp (+ nrx rc)))
                    (ly:stencil-add
                      (ly:stencil-translate-axis ls nlx X)
                      (ly:stencil-translate-axis rs nrx X)
                      (if (<= lp rp)
                          (ly:stencil-translate-axis
                            (grob-interpret-markup
                             grob
                             (make-draw-squiggle-line-markup
                               (ly:grob-property grob 'squiggle-length)
                               (cons (- rp lp)
                                     0)
                               #t))
                            lp
                            X)
                          empty-stencil)))))))
        (ly:line-spanner::print grob)))

#(set-object-property! 'squiggle-length 'backend-type? number?)
#(set-object-property! 'angularity 'backend-type? number?)
#(set-object-property! 'orientation 'backend-type? number?)

\layout {
   \context {
     \Score
     \override TextSpanner.stencil = #draw-text-spanner-allow-squiggle
     \override TextSpanner.squiggle-length = 2
     \override TextSpanner.angularity = 0.8
     \override TextSpanner.thickness = 0.3
     \override TextSpanner.height = 0.4
     \override TextSpanner.orientation = -1
   }
}

{
   \override TextSpanner.bound-details.left.padding = 4
   \override TextSpanner.bound-details.right.padding = 4
   \once \override TextSpanner.bound-details.left.text = "aaa"
   \once \override TextSpanner.bound-details.right.text = "bbb"
   c'1\startTextSpan R1*5 1\stopTextSpan
   \break
   \override TextSpanner.style = #'squiggle
   c'1\startTextSpan R1*5 1\stopTextSpan
   \override TextSpanner.bound-padding = #1.0
   \override TextSpanner.bound-details.left.text = "aaa"
   \override TextSpanner.bound-details.right.text = "bbb"
   \override TextSpanner.bound-details.right.padding = #0.6

   \override TextSpanner.bound-details.right.stencil-align-dir-y = #LEFT
   \override TextSpanner.bound-details.left.stencil-align-dir-y = #CENTER
   \override TextSpanner.bound-details.right.stencil-offset = #'(0.5 . 1)

   \break
   a'8\startTextSpan gis8 a4 b4\glissando
   b,4 | g' c\stopTextSpan c
}