Jump to content

Flat ties: Difference between revisions

From LilyPond wiki
No edit summary
m Avoid tabs
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
The function takes the default <code>Tie.stencil</code> as an argument, calculating the result relying on the extents of this default.
This snippet provides a function <code>flared-tie</code> to draw a tie that consist of straight lines. It is intended as a replacement for the default tie-drawing function (i.e., a replacement argument for the <code>stencil</code> property of the <code>Tie</code> grob).


Further tweaking is possible by overriding <code>Tie.details.height-limit</code> or with <code>\shape</code>. It's also possible to change the custom-definition on the fly.
The argument of <code>flared-tie</code> is a list of coordinate pairs that specify additional points between the first and last point to span up the tie’s lines. The first and last point are identical to the original tie’s start and end point, respectively. The X&nbsp;and Y&nbsp;coordinate values are multiples of the bounding box length and height of the original tie (also taking care of the tie’s direction); consequently, the first point has coordinates (0,0), and the last point (1,0).


<lilypond version="2.24" full>
The function <code>flare-tie</code> defines a shorthand for a flat tie. Further tweaking of the shape is possible by overriding <code>Tie.details.height-limit</code> or with <code>\shape</code>. It is also possible to change the custom definition on the fly.
%% http://lsr.di.unimi.it/LSR/Item?id=1031


<lilypond version="2.24">
#(define ((flared-tie coords) grob)
#(define ((flared-tie coords) grob)
  (define (pair-to-list pair)
  (define (pair-to-list pair)
     (list (car pair) (cdr pair)))
     (list (car pair) (cdr pair)))
 
  (define (normalize-coords goods x y dir)
  (define (normalize-coords goods x y dir)
    (map
    (map
       (lambda (coord)
       (lambda (coord)
        ;(coord-scale coord (cons x (* y dir)))
         (cons (* x (car coord)) (* y dir (cdr coord))))
         (cons (* x (car coord)) (* y dir (cdr coord))))
       goods))
       goods))
 
  (define (my-c-p-s points thick)
  (define (my-c-p-s points thick)
    (make-connected-path-stencil
    (make-connected-path-stencil points thick 1.0 1.0 #f #f))
      points
 
      thick
  ;; Calling `ly:tie::print` and assigning its return value to a
      1.0
  ;; variable in this outer `let` triggers LilyPond to position the
      1.0
  ;; tie, allowing us to extract its extents.  We only proceed,
      #f
  ;; however, if the tie doesn't get discarded (for whatever reason).
      #f))
  (let ((sten (ly:tie::print grob)))
    (if (grob::is-live? grob)
  ;; outer let to trigger suicide
        (let* ((layout (ly:grob-layout grob))
  (let ((sten (ly:tie::print grob)))
                (line-thickness (ly:output-def-lookup layout
    (if (grob::is-live? grob)
                                                      'line-thickness))
        (let* ((layout (ly:grob-layout grob))
                (thickness (ly:grob-property grob 'thickness 0.1))
              (line-thickness (ly:output-def-lookup layout 'line-thickness))
                (used-thick (* line-thickness thickness))
              (thickness (ly:grob-property grob 'thickness 0.1))
                (dir (ly:grob-property grob 'direction))
              (used-thick (* line-thickness thickness))
                (xex (ly:stencil-extent sten X))
              (dir (ly:grob-property grob 'direction))
                (yex (ly:stencil-extent sten Y))
              (xex (ly:stencil-extent sten X))
                (lenx (interval-length xex))
              (yex (ly:stencil-extent sten Y))
                (leny (interval-length yex))
              (lenx (interval-length xex))
                (xtrans (car xex))
              (leny (interval-length yex))
                (ytrans (if (> dir 0)(car yex) (cdr yex)))
              (xtrans (car xex))
                ;; Add last point.
              (ytrans (if (> dir 0)(car yex) (cdr yex)))
                (coord-list (append coords '((1.0 . 0.0))))
              (uplist
                (uplist
                 (map pair-to-list
                 (map pair-to-list
                       (normalize-coords coords lenx (* leny 2) dir))))
                       (normalize-coords coord-list lenx (* leny 2) dir))))
          (ly:stencil-translate
  (ly:stencil-translate
            (my-c-p-s uplist used-thick)
      (my-c-p-s uplist used-thick)
            (cons xtrans ytrans)))
    (cons xtrans ytrans)))
        '())))
  '())))


% Define a default tie shape consisting of three straight lines.
#(define flare-tie
#(define flare-tie
  (flared-tie '((0 . 0)(0.1 . 0.2) (0.9 . 0.2) (1.0 . 0.0))))
  (flared-tie '((0.1 . 0.3) (0.9 . 0.3))))
 
\relative c' {
  a4~ a
  \once \override Tie.stencil = #flare-tie
  a4~ a \break
 
  <a c e a c e a c e>~ q
  \once \override Tie.stencil = #flare-tie
  q~ q\break
 
  <>^\markup \small \typewriter "height-limit = 14"
  \override Tie.details.height-limit = 14
  a'4~ a
  \once \override Tie.stencil = #flare-tie
  a4~ a \break


\layout {
  <>^\markup \small \typewriter "height-limit = 0.5"
   \context {
   \override Tie.details.height-limit = 0.5
    \Voice
  a4~ a
    \override Tie.stencil = #flare-tie
  \once \override Tie.stencil = #flare-tie
   }
   a4~ a \break
}
 
  \revert Tie.details.height-limit


\paper {
  <>^\markup \small \typewriter
   ragged-right = ##f
            "\shape #'((0 . 0) (0 . -1) (0 . -1) (0 . 0))"
   tagline = ##f
   \shape #'((0 . 0) (0 . -1) (0 . -1) (0 . 0)) Tie
}
  a4~ a
  \once \override Tie.stencil = #flare-tie
   \shape #'((0 . 0) (0 . -1) (0 . -1) (0 . 0)) Tie
  a4~ a \break


\relative c' {
   <>^\markup \small \typewriter
  a4~a
            "#(flared-tie '((0.2 . 2) (0.5 . -3) (0.8 . 1))"
  \override Tie.height-limit = 4
   \once \override Tie.stencil =
  a'4~a
        #(flared-tie '((0.2 . 2) (0.5 . -3) (0.8 . 1)))
  a'4~a
   a4~ a
   <a,, c e a c e a c e>~ q
   <>_\markup \small \typewriter
 
            "#(flared-tie '((0.5 . 2)))"
  \break
   \once \override Tie.stencil = #(flared-tie '((0.5 . 2)))
 
   a'4~ a
  a'4~a
  \once \override Tie.details.height-limit = 14
  a4~a
 
  \break
 
  a4~a
  \once \override Tie.details.height-limit = 0.5
  a4~a
 
  \break
 
  a4~a
  \shape #'((0 . 0) (0 . 0.4) (0 . 0.4) (0 . 0)) Tie
  a4~a
 
  \break
 
  a4~a
   \once \override Tie.stencil =  
    #(flared-tie '((0 . 0)(0.1 . 0.4) (0.9 . 0.4) (1.0 . 0.0)))
   a4~a
    
  a4~a
   \once \override Tie.stencil =  
    #(flared-tie '((0 . 0)(0.06 . 0.1) (0.94 . 0.1) (1.0 . 0.0)))
   a4~a
}
}
</lilypond>
</lilypond>


[[Category:Contemporary notation]]
[[Category:Scheme]]
[[Category:Staff notation]]
[[Category:Staff notation]]
[[Category:Tweaks and overrides]]
[[Category:Tweaks and overrides]]
[[Category:Scheme]]
[[Category:Included in the official documentation]]
[[Category:Contemporary notation]]
[[Category:Snippet]]
[[Category:Included in the official documentation]][[Category:Snippet]]

Latest revision as of 16:15, 10 December 2025

This snippet provides a function flared-tie to draw a tie that consist of straight lines. It is intended as a replacement for the default tie-drawing function (i.e., a replacement argument for the stencil property of the Tie grob).

The argument of flared-tie is a list of coordinate pairs that specify additional points between the first and last point to span up the tie’s lines. The first and last point are identical to the original tie’s start and end point, respectively. The X and Y coordinate values are multiples of the bounding box length and height of the original tie (also taking care of the tie’s direction); consequently, the first point has coordinates (0,0), and the last point (1,0).

The function flare-tie defines a shorthand for a flat tie. Further tweaking of the shape is possible by overriding Tie.details.height-limit or with \shape. It is also possible to change the custom definition on the fly.

\version "2.24"

#(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))

   ;; Calling `ly:tie::print` and assigning its return value to a
   ;; variable in this outer `let` triggers LilyPond to position the
   ;; tie, allowing us to extract its extents.  We only proceed,
   ;; however, if the tie doesn't get discarded (for whatever reason).
   (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))
                (xtrans (car xex))
                (ytrans (if (> dir 0)(car yex) (cdr yex)))
                ;; Add last point.
                (coord-list (append coords '((1.0 . 0.0))))
                (uplist
                 (map pair-to-list
                      (normalize-coords coord-list lenx (* leny 2) dir))))
           (ly:stencil-translate
            (my-c-p-s uplist used-thick)
            (cons xtrans ytrans)))
         '())))

% Define a default tie shape consisting of three straight lines.
#(define flare-tie
   (flared-tie '((0.1 . 0.3) (0.9 . 0.3))))

\relative c' {
  a4~ a
  \once \override Tie.stencil = #flare-tie
  a4~ a \break

  <a c e a c e a c e>~ q
  \once \override Tie.stencil = #flare-tie
  q~ q\break

  <>^\markup \small \typewriter "height-limit = 14"
  \override Tie.details.height-limit = 14
  a'4~ a
  \once \override Tie.stencil = #flare-tie
  a4~ a \break

  <>^\markup \small \typewriter "height-limit = 0.5"
  \override Tie.details.height-limit = 0.5
  a4~ a
  \once \override Tie.stencil = #flare-tie
  a4~ a \break

  \revert Tie.details.height-limit

  <>^\markup \small \typewriter
             "\shape #'((0 . 0) (0 . -1) (0 . -1) (0 . 0))"
  \shape #'((0 . 0) (0 . -1) (0 . -1) (0 . 0)) Tie
  a4~ a
  \once \override Tie.stencil = #flare-tie
  \shape #'((0 . 0) (0 . -1) (0 . -1) (0 . 0)) Tie
  a4~ a \break

  <>^\markup \small \typewriter
             "#(flared-tie '((0.2 . 2) (0.5 . -3) (0.8 . 1))"
  \once \override Tie.stencil =
        #(flared-tie '((0.2 . 2) (0.5 . -3) (0.8 . 1)))
  a4~ a
  <>_\markup \small \typewriter
             "#(flared-tie '((0.5 . 2)))"
  \once \override Tie.stencil = #(flared-tie '((0.5 . 2)))
  a'4~ a
}