Le mercredi 19 avril 2023 à 09:44 -0400, William Rehwinkel via LilyPond user 
discussion a écrit :

> Dear list,
> 
> I use the following stencil (which is derived the bracketify-stencil 
> procedure from lilypond) to draw editorial brackets around rests.
> 
> The output looks very nice and more preferable for my use than using 
> \parenthesize (mainly because it changes in size for quarter note 
> rests). However, I would like to ask if it is possible to modify the 
> \override command to have the brackets account for the dots after the 
> rest? Perhaps a higher level stencil that draws the Rest and dots?

Makes me think I should revive my work on adding a `\bracket` command to 
LilyPond...

Anyway, try:

```
\version "2.25.3"

#(define (bracketify-rest thick protrusion vpadding hpadding)
   (grob-transformer
    'stencil
    (lambda (grob stil)
      (let* ((dot (ly:grob-object grob 'dot #f))
             (ext-grobs (ly:grob-list->grob-array (if dot (list dot grob) (list 
grob))))
             (ref (ly:grob-common-refpoint-of-array grob ext-grobs X))
             (x-ext (coord-translate (ly:relative-group-extent ext-grobs ref X)
                                     (- (ly:grob-relative-coordinate grob ref 
X))))
             (ext (interval-widen (ly:stencil-extent stil Y)
                                  hpadding))
             (lb (ly:stencil-aligned-to (ly:bracket Y ext thick protrusion)
                                        X RIGHT))
             (rb (ly:stencil-aligned-to (ly:bracket Y ext thick (- protrusion))
                                        X LEFT)))
        (ly:stencil-add
         stil
         (ly:stencil-translate-axis rb (interval-end x-ext) X)
         (ly:stencil-translate-axis lb (interval-start x-ext) X))))))

\relative a {
  \override Rest.stencil = #(bracketify-rest 0.15 0.5 0.2 0.6)
  r1
  r2. r4
  a1\rest
}
```

You can find the documentation for the functions used in the Internals 
Reference.

I've also cleaned it up a bit to use `grob-transformer` (cf. 
[here](https://extending-lilypond.gitlab.io/en/extending/backend.html#using-grob-transformer)).


> Unfortunately I had trouble finding the source code which handles 
> \parenthesize in the lilypond repository, which probably could have 
> helped me.


It's spread a bit all around. The `\parenthesize` function itself is in 
`ly/music-functions-init.ly`. The engraver for parentheses lives in 
`lily/parenthesis-engraver.cc`. The `Parentheses` grob is defined, like all 
grobs, in `scm/define-grobs.scm`, and the callbacks it uses are in 
`scm/output-lib.scm`.

HTH,

Jean

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to