Hi Harm,

> currently I'm trying to add crosses to the start and end of arbitrary 
Glissandi.
> So far it works for unbroken and broken single-staff Glissando, as
> well as for unbroken cross-staff Glissando.
> Alas, I'm stuck for broken cross-staff Glissando.
> Attached are the files with the already done steps.
> 
> Any hints?

A diffent approach: You could simply extract the positions from the stencil 
itself. Simply pass the original stencil to your procedure:

%%%
glissandoX =
#(define-music-function (proc)(procedure?)
#{
  \override Glissando.stencil =
    #(grob-transformer 'stencil
      (lambda (grob orig)
        (apply ly:stencil-add orig
          (map
            (lambda (pt) (stencil-with-color (make-cross-stencil pt) red))
            (proc grob orig)))))
#})
%%%

Then get the stencil expression, which should be something like `('translate-
stencil (X . Y) (draw-line thickness x0 y0 x1 y1))`. So match against that 
expression and you’ll have your positions:

%%%
#(define (gliss-pts grob stc)
   (let* ((expr (ly:stencil-expr stc)))
     (match
      expr
      (('translate-stencil shift ('draw-line thick x0 y0 x1 y1))
       (list
        (cons (+ (car shift) x0) (+ (cdr shift) y0))
        (cons (+ (car shift) x1) (+ (cdr shift) y1)))))))
%%%

Now, of course this only works for line-style glissando. For something else it 
would for example be possible to calculate the positions from the skylines of 
the stencil:

%%%
#(define (gliss-pts grob stc)
   (let* ((skylines (ly:skylines-for-stencil stc Y))
          (points1 (sort (filter (lambda (x) (finite? (car x)))
                                 (ly:skyline->points (car skylines) Y))
                         (lambda (x y) (< (car x) (car y)))))
          (points2 (sort (filter (lambda (x) (finite? (car x)))
                                 (ly:skyline->points (cdr skylines) Y))
                         (lambda (x y) (< (car x) (car y))))))
     (if (or (not (>= (length points1) 2)) (not (>= (length points2) 2)))
         (ly:error "Unepected number of points"))
     (let ((pos00 (first points1))
           (pos10 (last points1))
           (pos01 (first points2))
           (pos11 (last points2)))
       (list
        (cons (* 0.5 (+ (car pos00) (car pos01)))
              (* 0.5 (+ (cdr pos00) (cdr pos01))))
        (cons (* 0.5 (+ (car pos10) (car pos11)))
              (* 0.5 (+ (cdr pos10) (cdr pos11))))))))
%%%

Best regards,
Tina

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to