Re: Transparent box around notes
Thanks, I'll check it out! Il ven 3 mag 2024, 14:23 K. Blum ha scritto: > Hi Paolo, hi David, > > I've replaced the current stencil function with the one from the > openLilyLib "frames" module (which has even more capabilities). > Here is the result: > https://github.com/KlausBlum/Ly-Boxer-Snippet > If you like, please feel free to experiment or add further things... > > I'll try to send you an invitation to give you full access to that repo. > (Never done that before, but I'll find my way...) > > If anyone else is interested, please send a short message. :-) > > Cheers, > Klaus >
Re: Transparent box around notes
Hi Paolo, hi David, I've replaced the current stencil function with the one from the openLilyLib "frames" module (which has even more capabilities). Here is the result: https://github.com/KlausBlum/Ly-Boxer-Snippet If you like, please feel free to experiment or add further things... I'll try to send you an invitation to give you full access to that repo. (Never done that before, but I'll find my way...) If anyone else is interested, please send a short message. :-) Cheers, Klaus
Re: Transparent box around notes
Hi Paolo, But the alpha channel is ignored... Is there a way to fix this? AFAIK LilyPond cannot deal with alpha transparency at all. The impression of transparency is only achieved by placing the boxes in a layer behind the staff. I therefore replaced (see the attached file): (if filled (ly:make-stencil (list 'color fill-color (list 'round-filled-box (- (- (car xext) thick)) (+ (cdr xext) thick) (- (car yext)) (cdr yext) 0.0) xext yext)) empty-stencil) with: (if filled (stencil-with-color (ly:round-filled-box xext yext 0) fill-color) empty-stencil) At least, "xext" should be widened by "thick": %% (if filled (stencil-with-color (ly:round-filled-box (cons (- (car xext) thick) (+ (cdr xext) thick)) yext 0) fill-color) empty-stencil) %% This fixes the boundaries of boxes separated by a line break, see bar 8 in the example. Cheers, Klaus
Re: Transparent box around notes
Hello David and Klaus, A further improvement is to add colors with alpha channel. I therefore replaced (see the attached file): (if filled (ly:make-stencil (list 'color fill-color (list 'round-filled-box (- (- (car xext) thick)) (+ (cdr xext) thick) (- (car yext)) (cdr yext) 0.0) xext yext)) empty-stencil) with: (if filled (stencil-with-color (ly:round-filled-box xext yext 0) fill-color) empty-stencil) But the alpha channel is ignored... Is there a way to fix this? Thanks! > % \version "2.19.15" \version "2.24.1" \header { tagline = ##f } #(define-event-class 'music-boxer-event 'span-event) #(define-event-class 'box-event 'music-event) #(define (add-grob-definition grob-name grob-entry) (set! all-grob-descriptions (cons ((@@ (lily) completize-grob-entry) (cons grob-name grob-entry)) all-grob-descriptions))) #(define (define-grob-property symbol type? description) ;(if (not (equal? (object-property symbol 'backend-doc) #f)) ;(ly:error (_ "symbol ~S redefined") symbol)) (set-object-property! symbol 'backend-type? type?) (set-object-property! symbol 'backend-doc description) symbol) #(map (lambda (x) (apply define-grob-property x)) `( (filled ,boolean? "Should we fill in this box?") (fill-color ,color? "Background color for filling the rectangle") (acknowledge-finger-interface ,boolean? "Include fingerings in box?") (acknowledge-script-interface ,boolean? "Include scripts in box?") ; add more properties here )) #(define (make-box thick padding filled fill-color open-on-left open-on-right xext yext) (let* ((xext (interval-widen xext padding)) (yext (interval-widen yext padding))) (ly:stencil-add (if filled (stencil-with-color (ly:round-filled-box xext yext 0) fill-color) empty-stencil) (if (> thick 0) (make-filled-box-stencil (cons (- (car xext) thick) (+ (cdr xext) thick)) (cons (- (car yext) thick) (car yext))) empty-stencil) (if (> thick 0) (make-filled-box-stencil (cons (- (car xext) thick) (+ (cdr xext) thick)) (cons (cdr yext) (+ (cdr yext) thick))) empty-stencil) (if (and (not open-on-right) (> thick 0)) (make-filled-box-stencil (cons (cdr xext) (+ (cdr xext) thick)) yext) empty-stencil) (if (and (not open-on-left) (> thick 0)) (make-filled-box-stencil (cons (- (car xext) thick) (car xext)) yext) empty-stencil) ))) #(define (music-boxer-stencil grob) (let* ((elts (ly:grob-object grob 'elements)) (refp-X (ly:grob-common-refpoint-of-array grob elts X)) (X-ext (ly:relative-group-extent elts refp-X X)) (refp-Y (ly:grob-common-refpoint-of-array grob elts Y)) (Y-ext (ly:relative-group-extent elts refp-Y Y)) (padding (ly:grob-property grob 'padding 0.3)) (thick (ly:grob-property grob 'thickness 0.1)) (filled (ly:grob-property grob 'filled #f)) (fill-color (ly:grob-property grob 'fill-color grey)) (offset (ly:grob-relative-coordinate grob refp-X X)) ; (left-bound (ly:spanner-bound grob LEFT)) ; (right-bound (ly:spanner-bound grob RIGHT)) ; (break-dir-L (ly:item-break-dir left-bound)) ; (break-dir-R (ly:item-break-dir right-bound)) ; (open-on-left (if (= 1 break-dir-L) #t #f)) ; (open-on-right (if (= -1 break-dir-R) #t #f)) (open-on-left (and (ly:spanner? grob) (= 1 (ly:item-break-dir (ly:spanner-bound grob LEFT) ; (open-on-left ; (if (ly:spanner? grob) ; (if (= 1 (ly:item-break-dir (ly:spanner-bound grob LEFT))) ;#t #f) ; #f)) (open-on-right (and (ly:spanner? grob) (= -1 (ly:item-break-dir (ly:spanner-bound grob RIGHT) ;(open-on-right ;(if (ly:spanner? grob) ; (if (= -1 (ly:item-break-dir (ly:spanner-bound grob RIGHT))) ; #t #f) ; #f)) (stil (make-box thick padding filled fill-color open-on-left open-on-right X-ext Y-ext)) ) (ly:stencil-translate-axis stil (- offset) X) ) ) #(define box-stil music-boxer-stencil) #(add-grob-definition 'Box `( (stencil . ,box-stil) (meta . ((class . Item) (interfaces . ()) #(add-grob-definition 'MusicBoxer `( (stencil . ,music-boxer-stencil) (meta . ((class . Spanner) (interfaces . ()) #(define box-types
Re: Transparent box around notes
On 2024-04-30 5:30 pm, David Nalesnik wrote: What LilyPond version is the LSR currently running? (I'm wondering if you are able to use the revised add-grob-definition there.) This is documented on the Contributing page [1]. [1]: https://lsr.di.unimi.it/LSR/html/contributing.html LSR appears to be running 2.24.x at the moment. -- Aaron Hill
Re: Transparent box around notes
Hi Paolo, On Tue, Apr 30, 2024 at 4:09 PM Paolo Prete wrote: > Ta > > On Tue, Apr 30, 2024 at 8:04 PM K. Blum wrote: > >> Hi Paolo, hi everyone, >> >> > Yeah, it works if I just replace add-grob-definition with: >> > >> > #(define (add-grob-definition grob-name grob-entry) >> >(set! all-grob-descriptions >> > (cons ((@@ (lily) completize-grob-entry) >> > (cons grob-name grob-entry)) >> >all-grob-descriptions))) >> > >> > That said, the snippet is _very_ useful, and certainly much easier to >> > use than the lsr snippet. I strongly encourage the community to add it >> > to the repository, because the trial and error method is inaccurate >> > and time consuming. >> > That said, is there an easy way to adapt it so that it draws a colored >> > box (with transparency) instead of a rectangle with segments? >> >> if you read the further replies to the thread >> https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00416.html >> you will find that there was an attempt to combine David Nalesnik's >> engraver with the colored boxes from snippet 1000: >> https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00416.html >> >> I've applied your version of add-grob-definition from above to the >> latest working state of our attempts and came up with boxer3b.ly, see >> attached. >> > > This is really great, thanks, I'm going to use it intensively! > fortunately you read and responded to my message, otherwise this feature > would have been swallowed up and obscured in the confusion of the mailing > list archive (and I would have wasted days reinventing the wheel). > After I've done more testing I'll post a new message proposing to remove > the current snippet from the LSR and replace it with yours and David's > implementation. > What LilyPond version is the LSR currently running? (I'm wondering if you are able to use the revised add-grob-definition there.) -David
Re: Transparent box around notes
Ta On Tue, Apr 30, 2024 at 8:04 PM K. Blum wrote: > Hi Paolo, hi everyone, > > > Yeah, it works if I just replace add-grob-definition with: > > > > #(define (add-grob-definition grob-name grob-entry) > >(set! all-grob-descriptions > > (cons ((@@ (lily) completize-grob-entry) > > (cons grob-name grob-entry)) > >all-grob-descriptions))) > > > > That said, the snippet is _very_ useful, and certainly much easier to > > use than the lsr snippet. I strongly encourage the community to add it > > to the repository, because the trial and error method is inaccurate > > and time consuming. > > That said, is there an easy way to adapt it so that it draws a colored > > box (with transparency) instead of a rectangle with segments? > > if you read the further replies to the thread > https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00416.html > you will find that there was an attempt to combine David Nalesnik's > engraver with the colored boxes from snippet 1000: > https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00416.html > > I've applied your version of add-grob-definition from above to the > latest working state of our attempts and came up with boxer3b.ly, see > attached. > This is really great, thanks, I'm going to use it intensively! fortunately you read and responded to my message, otherwise this feature would have been swallowed up and obscured in the confusion of the mailing list archive (and I would have wasted days reinventing the wheel). After I've done more testing I'll post a new message proposing to remove the current snippet from the LSR and replace it with yours and David's implementation. Cheers, Paoo > > Hope to help, > Klaus > >
Re: Transparent box around notes
Hi Paolo, hi everyone, Yeah, it works if I just replace add-grob-definition with: #(define (add-grob-definition grob-name grob-entry) (set! all-grob-descriptions (cons ((@@ (lily) completize-grob-entry) (cons grob-name grob-entry)) all-grob-descriptions))) That said, the snippet is _very_ useful, and certainly much easier to use than the lsr snippet. I strongly encourage the community to add it to the repository, because the trial and error method is inaccurate and time consuming. That said, is there an easy way to adapt it so that it draws a colored box (with transparency) instead of a rectangle with segments? if you read the further replies to the thread https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00416.html you will find that there was an attempt to combine David Nalesnik's engraver with the colored boxes from snippet 1000: https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00416.html I've applied your version of add-grob-definition from above to the latest working state of our attempts and came up with boxer3b.ly, see attached. Maybe this comes closer to what you are looking for. (Note that I had to comment out two lines from David's "define-grob-proberty" function that causes an error in newer LY versions. I have no idea why because I don't understand such advanced scheme magic... maybe someone with more knowledge can chime in here.) Further attempts were discussed in a new thread: https://lists.gnu.org/archive/html/lilypond-user/2015-04/msg8.html I remember that someday I gave up trying to understand engravers... but created snippet 1000 instead. By the way: Together with Urs Liska a more advanced module for openLilyLib was created: https://github.com/openlilylib/analysis/blob/master/usage-examples/frames.pdf It should be possible to get this working again for newer LY versions. Hope to help, Klaus % \version "2.19.15" \version "2.24.3" \header { tagline = ##f } #(define-event-class 'music-boxer-event 'span-event) #(define-event-class 'box-event 'music-event) #(define (add-grob-definition grob-name grob-entry) (set! all-grob-descriptions (cons ((@@ (lily) completize-grob-entry) (cons grob-name grob-entry)) all-grob-descriptions))) #(define (define-grob-property symbol type? description) ;(if (not (equal? (object-property symbol 'backend-doc) #f)) ;(ly:error (_ "symbol ~S redefined") symbol)) (set-object-property! symbol 'backend-type? type?) (set-object-property! symbol 'backend-doc description) symbol) #(map (lambda (x) (apply define-grob-property x)) `( (filled ,boolean? "Should we fill in this box?") (fill-color ,color? "Background color for filling the rectangle") (acknowledge-finger-interface ,boolean? "Include fingerings in box?") (acknowledge-script-interface ,boolean? "Include scripts in box?") ; add more properties here )) #(define (make-box thick padding filled fill-color open-on-left open-on-right xext yext) (let* ((xext (interval-widen xext padding)) (yext (interval-widen yext padding))) (ly:stencil-add (if filled (ly:make-stencil (list 'color fill-color (list 'round-filled-box (- (- (car xext) thick)) (+ (cdr xext) thick) (- (car yext)) (cdr yext) 0.0) xext yext)) empty-stencil) (if (> thick 0) (make-filled-box-stencil (cons (- (car xext) thick) (+ (cdr xext) thick)) (cons (- (car yext) thick) (car yext))) empty-stencil) (if (> thick 0) (make-filled-box-stencil (cons (- (car xext) thick) (+ (cdr xext) thick)) (cons (cdr yext) (+ (cdr yext) thick))) empty-stencil) (if (and (not open-on-right) (> thick 0)) (make-filled-box-stencil (cons (cdr xext) (+ (cdr xext) thick)) yext) empty-stencil) (if (and (not open-on-left) (> thick 0)) (make-filled-box-stencil (cons (- (car xext) thick) (car xext)) yext) empty-stencil) ))) #(define (music-boxer-stencil grob) (let* ((elts (ly:grob-object grob 'elements)) (refp-X (ly:grob-common-refpoint-of-array grob elts X)) (X-ext (ly:relative-group-extent elts refp-X X)) (refp-Y (ly:grob-common-refpoint-of-array grob elts Y)) (Y-ext (ly:relative-group-extent elts refp-Y Y)) (padding (ly:grob-property grob 'padding 0.3)) (thick (ly:grob-property grob 'thickness 0.1)) (filled (ly:grob-property grob 'filled #f)) (fill-color (ly:grob-property grob 'fill-color grey)) (offset (ly:grob-relative-coordinate grob refp-X X)) ; (left-bound (ly:spanner-bound grob LEFT)) ;
Re: Transparent box around notes
On Tue, Apr 30, 2024 at 6:38 AM Werner LEMBERG wrote: > > > [...] the snippet is _very_ useful, and certainly much easier to use > > than the lsr snippet. > > Please submit the example as a new LSR snippet. > > I submitted it (see: https://lsr.di.unimi.it/LSR/Item?u=1=1188 ) but the second box is not correctly displayed (I tested it with LP 2.24.1 and it's ok). Should it be deleted? Note also that it partially overlaps with https://lsr.di.unimi.it/LSR/Item?id=1000 : it solves the non-automatic size issue, but it doesn't provide colors and background. > Note that we already have a (slightly different) issue for that: > > https://gitlab.com/lilypond/lilypond/-/issues/833 > > I added a link to the previous message > Are you willing to work on that? It would need extensive tests (for > example, to add other grobs like trill spanners to the box), > documentation, and one or more regression tests. > > Unfortunately I'm not that familiar with Scheme/Guile so to modify it with the color/background feature in a reasonably short time. And I don't even know if this modification is trivial or not... > > Werner >
Re: Transparent box around notes
> [...] the snippet is _very_ useful, and certainly much easier to use > than the lsr snippet. Please submit the example as a new LSR snippet. Note that we already have a (slightly different) issue for that: https://gitlab.com/lilypond/lilypond/-/issues/833 It would certainly help if you could add more information to the issue, for example, where to find the latest working example. > I strongly encourage the community to add it to the repository, > because the trial and error method is inaccurate and time consuming. Are you willing to work on that? It would need extensive tests (for example, to add other grobs like trill spanners to the box), documentation, and one or more regression tests. Werner
Re: Transparent box around notes
Yeah, it works if I just replace add-grob-definition with: #(define (add-grob-definition grob-name grob-entry) (set! all-grob-descriptions (cons ((@@ (lily) completize-grob-entry) (cons grob-name grob-entry)) all-grob-descriptions))) That said, the snippet is _very_ useful, and certainly much easier to use than the lsr snippet. I strongly encourage the community to add it to the repository, because the trial and error method is inaccurate and time consuming. That said, is there an easy way to adapt it so that it draws a colored box (with transparency) instead of a rectangle with segments? Thanks again, P (I attach here the updated version of the snippet) On Sun, Apr 28, 2024 at 11:38 AM Robin Bannister wrote: > Paolo Prete wrote: > > Note that there's also this (no trial-and-error): > > > > https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00142.html > > > > But it doesn't compile with 2.24... > > > > That's due to merge request !818 [1], applied between 2.23.3 and 2.23.4. > > Simon Albrecht ran into the same problem in another case, and Jean > helped him out [2] by adapting just the add-grob-definition part. > > Doing the same to David N's add-grob-definition gets his code running > again. Maybe that's all you need to do. > > > [1] https://gitlab.com/lilypond/lilypond/-/merge_requests/818 > [2] https://lists.gnu.org/archive/html/lilypond-user/2021-12/msg00045.html > > > Cheers, > Robin > \version "2.19.15" \header { tagline = ##f } #(define-event-class 'music-boxer-event 'span-event) #(define-event-class 'box-event 'music-event) % #(define (add-grob-definition grob-name grob-entry) %(let* ((meta-entry (assoc-get 'meta grob-entry)) % (class(assoc-get 'class meta-entry)) % (ifaces-entry (assoc-get 'interfaces meta-entry))) % ;; change ly:grob-properties? to list? to work from 2.19.12 back to at least 2.18.2 % (set-object-property! grob-name 'translation-type? ly:grob-properties?) % (set-object-property! grob-name 'is-grob? #t) % (set! ifaces-entry (append (case class % ((Item) '(item-interface)) % ((Spanner) '(spanner-interface)) % ((Paper_column) '((item-interface % paper-column-interface))) % ((System) '((system-interface %spanner-interface))) % (else '(unknown-interface))) % ifaces-entry)) % (set! ifaces-entry (uniq-list (sort ifaces-entry symbol1 \musicBoxerStart d8-4 g,-0 d' g, d'-4 g,-0 d' \musicBoxerEnd g, } %2 \repeat volta 2 { \box 1\f\fermata \musicBoxerStart g8-3 d-0 g d g8-4 d-0 g \musicBoxerEnd d\accent } } \score { \new Staff \melody } \layout { \context { \Global \grobdescriptions #all-grob-descriptions } \context { \Score \consists \musicBoxerEngraver % for spans \consists \boxEngraver } }
Re: Transparent box around notes
Paolo Prete wrote: Note that there's also this (no trial-and-error): https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00142.html But it doesn't compile with 2.24... That's due to merge request !818 [1], applied between 2.23.3 and 2.23.4. Simon Albrecht ran into the same problem in another case, and Jean helped him out [2] by adapting just the add-grob-definition part. Doing the same to David N's add-grob-definition gets his code running again. Maybe that's all you need to do. [1] https://gitlab.com/lilypond/lilypond/-/merge_requests/818 [2] https://lists.gnu.org/archive/html/lilypond-user/2021-12/msg00045.html Cheers, Robin
Re: Transparent box around notes
Note that there's also this (no trial-and-error): https://lists.gnu.org/archive/html/lilypond-user/2015-01/msg00142.html But it doesn't compile with 2.24... On Sat, Apr 27, 2024 at 2:20 PM Paolo Prete wrote: > Thanks for the tip, but unfortunately it doesn't seem to fit what I'm > looking for. > Looking for example at > https://lsr.di.unimi.it/LSR/Search?q=background+%7C+colorspan , the box > coordinates must be calculated with a trial and error procedure, which is > pretty tedious. > > Cheers, > P > > On Sat, Apr 27, 2024 at 12:17 PM Robin Bannister wrote: > >> Paolo Prete wrote: >> > Something like: >> > >> > \coloredBox color offsLeft offsTop offsRight offsBottom "labelstring" >> > labeldirection { c' e' f' } >> > >> > Many thanks for your help! >> > Paolo >> >> >> This may get you started: >> >> https://lsr.di.unimi.it/LSR/Search?q=background+%7C+colorspan >> >> >> Cheers, >> Robin >> >
Re: Transparent box around notes
Thanks for the tip, but unfortunately it doesn't seem to fit what I'm looking for. Looking for example at https://lsr.di.unimi.it/LSR/Search?q=background+%7C+colorspan , the box coordinates must be calculated with a trial and error procedure, which is pretty tedious. Cheers, P On Sat, Apr 27, 2024 at 12:17 PM Robin Bannister wrote: > Paolo Prete wrote: > > Something like: > > > > \coloredBox color offsLeft offsTop offsRight offsBottom "labelstring" > > labeldirection { c' e' f' } > > > > Many thanks for your help! > > Paolo > > > This may get you started: > > https://lsr.di.unimi.it/LSR/Search?q=background+%7C+colorspan > > > Cheers, > Robin >
Re: Transparent box around notes
Paolo Prete wrote: Something like: \coloredBox color offsLeft offsTop offsRight offsBottom "labelstring" labeldirection { c' e' f' } Many thanks for your help! Paolo This may get you started: https://lsr.di.unimi.it/LSR/Search?q=background+%7C+colorspan Cheers, Robin