[Top][All Lists]

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

Re: A slur enclosed by parentheses or brackets

From: Werner LEMBERG
Subject: Re: A slur enclosed by parentheses or brackets
Date: Sat, 12 Sep 2020 14:27:30 +0200 (CEST)

>> Is there an easy way to have a slur enclosed by parentheses or
>> brackets? Some urtext editions use parenthesized slurs to indicate
>> editorial additions.
> \parenthesize does not currently handle spanners, so you would need to
> do some manual work.
> Consider: [...]

Here is a slightly improved version with rotated parentheses.  There's
certainly room for more improvements...



\version "2.20.0"

parenthesizeSlur =
   -\tweak stencil
   #(lambda (grob)
     (let* ((cp (ly:grob-property grob 'control-points))
            (lp (grob-interpret-markup grob (markup #:fontsize -7 "(")))
            (rp (grob-interpret-markup grob (markup #:fontsize -7 ")")))
            (cp1 (first cp))
            (cp2 (second cp))
            (cpn-1 (list-ref cp (- (length cp) 2)))
            (cpn (last cp))
            (langle (/ (atan (- (cdr cp2) (cdr cp1))
                             (- (car cp2) (car cp1))) PI-OVER-180))
            (rangle (/ (atan (- (cdr cpn) (cdr cpn-1))
                             (- (car cpn) (car cpn-1))) PI-OVER-180)))

       (set! lp (ly:stencil-aligned-to lp Y CENTER))
       (set! lp (ly:stencil-aligned-to lp X 0.5))
       (set! lp (ly:stencil-translate lp (first cp)))

       (set! rp (ly:stencil-aligned-to rp Y CENTER))
       (set! rp (ly:stencil-aligned-to rp X -0.5))
       (set! rp (ly:stencil-translate rp cpn))

       (list-set! cp 0
         (cons (cdr (ly:stencil-extent lp X))
               (cdr cp1)))
       (set! lp (ly:stencil-rotate lp langle 0 0))
       (list-set! cp (1- (length cp))
         (cons (car (ly:stencil-extent rp X))
               (cdr cpn)))
       (set! rp (ly:stencil-rotate rp rangle 0 0))
       (ly:grob-set-property! grob 'control-points cp)

       (apply ly:stencil-add (list lp rp
         (ly:slur::print grob)))))

{ g'4\parenthesizeSlur (
      \parenthesizeSlur \( b' c''2 ) |
   g'2\parenthesizeSlur ( f'4 e' ) \) }

PNG image

reply via email to

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