[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Flared horizontal bracket ties
From: |
Aaron Hill |
Subject: |
Re: Flared horizontal bracket ties |
Date: |
Fri, 07 Aug 2020 06:56:41 -0700 |
User-agent: |
Roundcube Webmail/1.4.2 |
On 2020-08-07 3:13 am, Andrew Bernard wrote:
Here is a wonderful function created for me by Thomas Morley, for
flared ties. It may be of interest to others, but my question is, how
can I modify this code to draw dashed lines, with controllable dash
period and dash fraction?
Andrew
%==================
Doing this fairly quickly, so there is code cleanup/refactoring left to
be done. But here is a rough proof of concept:
%%%%
\version "2.20.0"
#(define ((flared-tie coords) grob)
(define (pair-to-list pair)
(list (car pair) (cdr pair)))
(define (normalize-coords goods x y dir)
(map
(lambda (coord)
(cons (* x (car coord)) (* y dir (cdr coord))))
goods))
(define (my-c-p-s points thick)
(make-connected-path-stencil
points
thick
1.0
1.0
#f
#f))
(define (my-c-p-s-dashed points thick on off phase)
(apply ly:stencil-add
(map
(lambda (x1 y1 x2 y2)
(let* ((dx (- x2 x1))
(dy (- y2 y1))
(sten
(ly:make-stencil
(list 'dashed-line thick on off dx dy phase))))
(set! phase (+ phase (sqrt (+ (* dx dx) (* dy dy)))))
(ly:stencil-translate sten (cons x1 y1))))
(map car points)
(map cadr points)
(map car (cdr points))
(map cadr (cdr points)))))
; outer let to trigger suicide
(let ((sten (ly:tie::print grob)))
(if (grob::is-live? grob)
(let* ((layout (ly:grob-layout grob))
(line-thickness (ly:output-def-lookup layout
'line-thickness))
(thickness (ly:grob-property grob 'thickness 0.1))
(used-thick (* line-thickness thickness))
(dir (ly:grob-property grob 'direction))
(xex (ly:stencil-extent sten X))
(yex (ly:stencil-extent sten Y))
(lenx (interval-length xex))
(leny (interval-length yex))
(yex (ly:stencil-extent sten Y))
(xtrans (car xex))
(ytrans (if (> dir 0)(car yex) (cdr yex)))
(uplist
(map pair-to-list
(normalize-coords coords lenx (* leny 2) dir))))
(ly:stencil-translate
;(my-c-p-s uplist used-thick)
(my-c-p-s-dashed uplist used-thick 1.2 0.4 0)
(cons xtrans ytrans)))
'())))
%{
#(define flare-tie
(flared-tie '((0 . 0) (0.1 . 0.2) (0.9 . 0.2) (1.0 . 0.0))))
%}
#(define flare-tie
(flared-tie '((0 . 0) (0.1 . 0.3) (0.9 . 0.3) (1.0 . 0.0))))
{
b'1-\tweak Tie.stencil #flare-tie ~ b'1
}
%%%%
-- Aaron Hill
dashed-flared-ties.cropped.png
Description: PNG image