lilypond-user
[Top][All Lists]
Advanced

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

Re: Flared horizontal bracket ties


From: Thomas Morley
Subject: Re: Flared horizontal bracket ties
Date: Fri, 7 Aug 2020 23:21:10 +0200

Am Fr., 7. Aug. 2020 um 12:13 Uhr schrieb Andrew Bernard
<andrew.bernard@gmail.com>:
>
> 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
>
> %==================
>
> %{
>   Flared horizontal bracket ties
>   by Thomas Morley
> %}
>
>
> #(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))
>
>    ; 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)
>             (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))))
>

Hi Andrew,

I changed make-connected-path-stencil to make-connected-line.
As a big advantage, make-connected-line reads and reacts upon
grob-properties. This allows for some simplifications as well.

Though, there is always the problem that dashed and dotted lines are
made up from sequences of printed parts and spaces and they may be
connected at a space-part, which looks like being not connected or not
reaching the wished end. See the first dashed Tie in the example
below.
This happens for unsuitable settings of dash-fraction/dash-period.
If dash-period is very small it's unlikely to happen, though with
greater values the problem may not be avoidable.
(With draw-dashed/dotted-line-markup-commands I had undertaken the
effort to ensure printed parts at all endings, but it comes with the
cost that the needed scaling may lead to unequal printing for
line-lengths with only a small difference.
But hey, printing line-lengths with only a small difference exactly
equal is worse imho. Although this still happens if the line is made
up of glyphs like for default-Arpeggio)

Anyway, here the code:

#(define ((flared-tie coords) grob)

  (define (normalize-coords goods x y dir)
    (map
      (lambda (coord) (cons (* x (car coord)) (* y dir (cdr coord))))
      goods))

  (if (grob::is-live? grob)
      (let* ((sten (ly:tie::print grob))
             (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))
             (xtrans (car xex))
             (ytrans (if (> dir 0)(car yex) (cdr yex)))
             (uplist (normalize-coords coords lenx (* leny 2) dir)))

        (ly:stencil-translate
         (make-connected-line uplist grob)
         (cons xtrans ytrans)))
      '()))

#(define flare-tie
   (flared-tie '((0 . 0) (0.1 . 0.3) (0.9 . 0.3) (1.0 . 0.0))))

{
  \override Tie.stencil = #flare-tie
  a''1~ a''

  \override Tie.style = #'dashed-line
  a''1~ a''
  \once \override Tie.dash-fraction = 0.2
  \once \override Tie.dash-period = 1
  a''1~ a''
  \override Tie.style = #'dotted-line
  a''1~ a''
  \once \override Tie.dash-period = 0.3
  a''1~ a''
  \override Tie.style = #'zigzag
  a''1~ a''
  \override Tie.style = #'trill
  a''1~ a''
}

Cheers,
  Harm

Attachment: atest-104.cropped.png
Description: PNG image


reply via email to

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