Thank you Aaron! This is exactly what I needed. On Sun, Feb 28, 2021 at 5:21 AM Aaron Hill <[email protected]> wrote:
> On 2021-02-27 3:55 pm, Dimitris Marinakis wrote: > > Is it possible to make a "stencil-wrapper" that will show the vertical > > centre of a stencil and have an extending line of variable length > > (which of > > course won't distort the spacing of the actual score)? > > Yes, though much of the particular work depends on how you wish to use > (and reuse) the functionality. It is pretty easy to hack any stencil, > especially with the use of grob-transformer. There are many examples on > the mailing list [1] as well as the LSR [2]. > > [1]: https://lists.gnu.org/archive/html/lilypond-user/ > [2]: http://lsr.di.unimi.it/LSR/Search > > While a little overengineered in places and certainly in need of > refactoring, here is one way of doing things: > > %%%% > \version "2.22.0" > > #(define ruler-thickness 0.075) > > horizontal-ruler = > #(define-scheme-function > (color alignment extension) > ((color? red) number? number-pair?) > (lambda (sten) > (let* ((xext (ly:stencil-extent sten X)) > (yext (ly:stencil-extent sten Y)) > (y (interval-index yext alignment))) > (apply ly:stencil-in-color > (ly:make-stencil > (list 'draw-line ruler-thickness > (+ (car xext) (car extension)) y > (+ (cdr xext) (cdr extension)) y) > empty-interval empty-interval) > color)))) > > vertical-ruler = > #(define-scheme-function > (color alignment extension) > ((color? red) number? number-pair?) > (lambda (sten) > (let* ((xext (ly:stencil-extent sten X)) > (yext (ly:stencil-extent sten Y)) > (x (interval-index xext alignment))) > (apply ly:stencil-in-color > (ly:make-stencil > (list 'draw-line ruler-thickness > x (+ (car yext) (car extension)) > x (+ (cdr yext) (cdr extension))) > empty-interval empty-interval) > color)))) > > combine-guides = > #(define-scheme-function > (first-proc second-proc) > (procedure? procedure?) > (lambda (sten) > (ly:stencil-add (first-proc sten) (second-proc sten)))) > > stencil-guide = > #(define-music-function > (guide-proc grob-path) > (procedure? key-list?) > (define stencil-proc > (grob-transformer 'stencil > (lambda (grob orig) > (ly:stencil-outline > (ly:stencil-add orig (guide-proc orig)) > orig)))) > #{ \override $grob-path . stencil = #stencil-proc #}) > > \fixed c' { > \stencil-guide \combine-guides > \horizontal-ruler #cyan #DOWN #'(-1 . 1) > \vertical-ruler #'(0.9 0.6 0.3) #CENTER #'(-1 . 1) > Staff.TimeSignature > \stencil-guide \horizontal-ruler #CENTER #'(-1 . 1) NoteHead > \stencil-guide \vertical-ruler #green #LEFT #'(-1 . 1) Accidental > bes4 a8 g <fis c'>2 > } > %%%% > > > -- Aaron Hill
