lilypond-user
[Top][All Lists]
Advanced

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

Re: Custom tie vertical offsets


From: Aaron Hill
Subject: Re: Custom tie vertical offsets
Date: Fri, 09 Oct 2020 09:51:15 -0700
User-agent: Roundcube Webmail/1.4.9

On 2020-10-09 12:20 am, Andrew Bernard wrote:
Some time ago Harm developed custom flared tie code for me. Because
these ties are flat and not curved, they very often come so close to
staff lines that they can be hard to read. I can manually compensate
for that with

\once \override Tie.Y-offset = #n

but this is tedious with hundreds of ties. Here's the existing code.
Is it possible to include a vertical offset of a small amount such as
0.5 that intelligently takes account of the tie direction?

Firstly, you could certainly make Y-offset a procedure that applies an offset in the direction of the Tie:

%%%%
  \override Tie.Y-offset = #(lambda (grob)
    (* 0.5 (ly:grob-property grob 'direction)))
%%%%

That would slide all Ties half a staff space in their own direction.

Alternately, you might want to modify Harm's code to quantize the Y coordinate so that it always sits next to, but not on, staff lines:

%%%%
\version "2.20.0"

#(define ((flared-tie coords) grob)
  (define (scale-coords coords xex yex)
    (map (lambda (coord)
           (cons (interval-index xex (1- (* 2 (car coord))))
                 (interval-index yex (1- (* 2 (cdr coord))))))
         coords))
  (define (quantize y dir) (- (round (+ y dir)) dir))

  (if (grob::is-live? grob)
      (let* ((dir (ly:grob-property grob 'direction))
             (th (ly:staff-symbol-line-thickness grob))
             (sten (ly:tie::print grob))
             (xex (ly:stencil-extent sten X))
             (yex (ly:stencil-extent sten Y)))
        (or (< 0 dir) (set! yex (reverse-interval yex)))
        (set-cdr! yex (quantize (cdr yex) (* 3 th dir)))
        (make-connected-line
         (scale-coords coords xex yex)
         grob))
      '()))

#(define flare-tie
   (flared-tie '((0 . 0) (0.1 . 1) (0.9 . 1) (1 . 0))))
{ \override Tie.stencil = #flare-tie
  | f'2._~4 | g'2._~4 | c''2.^~4 | d''2.^~4 }
%%%%

Take note of the (* 3 th dir) in the code above. This is the scaled direction factor used for the quantize procedure. Setting this to zero will round the values to be exactly on the staff line. Using (* 0.5 dir) would result in a position exactly halfway between staff lines. Finally, my rationale for (* 3 th dir) is to use the thickness of the staff lines to help position the tie to be reasonably close to the line.


-- Aaron Hill

Attachment: tie-quant.cropped.png
Description: PNG image


reply via email to

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