Re: Transparent box around notes

2024-05-04 Thread Paolo Prete
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

2024-05-03 Thread K. Blum

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

2024-05-01 Thread K. Blum

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

2024-05-01 Thread Paolo Prete
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

2024-04-30 Thread Aaron Hill

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

2024-04-30 Thread David Nalesnik
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

2024-04-30 Thread Paolo Prete
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

2024-04-30 Thread K. Blum

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

2024-04-30 Thread Paolo Prete
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

2024-04-29 Thread Werner LEMBERG


> [...] 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

2024-04-29 Thread Paolo Prete
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

2024-04-28 Thread Robin Bannister

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

2024-04-27 Thread Paolo Prete
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

2024-04-27 Thread Paolo Prete
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

2024-04-27 Thread Robin Bannister

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



Transparent box around notes

2024-04-26 Thread Paolo Prete
Hello LilyPonders,

How can I draw a box around a group of notes so that (see the attached
image)

1) it is filled with a transparent color
2) it occupies the minimum area that includes the notes + four (optional)
offsets (left, top, right, bottom) that can be set by the user?
3) ... it would be great if I can add a label to the top or bottom of the
box

Something like:

\coloredBox color offsLeft offsTop offsRight offsBottom "labelstring"
labeldirection { c' e' f' }

Many thanks for your help!
Paolo


Re: box around notes

2015-04-09 Thread Klaus Blum
Hi David, 


David Nalesnik-2 wrote
 I hope that one day this will be trouble-free!

I didn't know that things can get that complicated when diving deep into a
lily pond... ;-)

David Nalesnik-2 wrote
 How did you arrive at 1?

Well, I just took some insane value to get above anything else...

David Nalesnik-2 wrote
 Something somewhere has calculated vertical spacing too early, and this
 messes up the positioning of the Beam grob.
 
 The problem is in the stencil callback for Box, which in your version is
 set to the same function as MusicBoxer.  When you request information
 about
 Y-extent, the function ly:relative-group-extent triggers vertical spacing
 routines before LilyPond is ready.  She must determine line breaks before
 the final stamp is put on the vertical aspect.
 
 I believe what is needed is a pure callback for Y-extent, so that
 LilyPond can make a safe estimate (i.e., without side effects) to use for
 purposes of line-breaking.  

If there is a way to have a separate callback, just to return an estimate
for Y-extent, IMO it would be okay just to return '(0 . 0) because the boxes
don't need to avoid collision with anything. (Just making LilyPond believe
the boxes have no Y-extent maybe could also prevent them pushing away the
dynamics...) 
But if that means not to use ly:relative-group-extent at all, things really
start to get unpleasant... 
In that case, I'd just introduce a user-settable property for Y-extent
instead of hard-coding. At least, the X-extent would be automatic. Maybe
I'll try that in the evening.

David Nalesnik-2 wrote
 You can read about purity here:
 http://lilypond.org/doc/v2.19/Documentation/contributor/understanding-pure-properties

Yeah, always open to new challenges, even if understanding this will be a
task for a lifetime... I'll be back in a few years. ;-)  
Seriously, I'll give it a try. 

David Nalesnik-2 wrote
 Hope this helps somewhat!

Definitely!

Cheers, 
Klaus




--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/box-around-notes-tp35581p174286.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-04-07 Thread David Nalesnik
Hi Klaus.

On Mon, Apr 6, 2015 at 4:55 PM, Klaus Blum benbigno...@gmx.de wrote:

 Hi David,

 here's my first attempt to apply my drawing function to your project.
 Thanks
 again for sharing this really cool tool!


You're very welcome.  What you've done with it is really impressive, and I
hope that one day this will be trouble-free!



 I've played around with some settings, and I also experimented with the
 messed up dynamics problem when taking the engravers out of the score
 context.
 It works if you set outside-staff-priority to a value high enough:
\override MusicBoxer.outside-staff-priority = #1
\override Box.outside-staff-priority = #1
 However, this leads to a warning:
 Ein Objekt außerhalb der Notenzeile sollte eine Richtung haben, Vorgabe
 ist
 »nach oben«
 (Following the lilypond translation, this is the original warning message:
 #: axis-group-interface.cc:786
 msgid an outside-staff object should have a direction, defaulting to up)

 It seems that there is something taken into account for spacing
 calculations, but LilyPond doesn't know if this mysterious something is
 located above or below the score.


Well, the mysterious somethings are quite simply the boxes.  When you set
outside-staff-priority, the object becomes an outside-staff object, and
thus needs a direction to know how it should be moved when arranging
outside-staff objects.

In the attached file, I put the relevant information into the grob
description.  I lowered the outside-staff-priority from 1 to 251 to
show that (here at least) it only has to be larger than the dynamic which
has a priority of 250.  How did you arrive at 1?



 By the way, if I put a box around an eighth note that is attached to a
 beam,
 the beam completely disappears. With MusicBoxer this is not the case.


The warning is the key -- well, a first clue:

 programming error: minimise_least_squares ():  Nothing to minimise
This means that vertical spacing is triggered
before line breaking

Something somewhere has calculated vertical spacing too early, and this
messes up the positioning of the Beam grob.

The problem is in the stencil callback for Box, which in your version is
set to the same function as MusicBoxer.  When you request information about
Y-extent, the function ly:relative-group-extent triggers vertical spacing
routines before LilyPond is ready.  She must determine line breaks before
the final stamp is put on the vertical aspect.

I believe what is needed is a pure callback for Y-extent, so that
LilyPond can make a safe estimate (i.e., without side effects) to use for
purposes of line-breaking.  Unfortunately, I'm having no luck with this.

You can read about purity here:
http://lilypond.org/doc/v2.19/Documentation/contributor/understanding-pure-properties

In the attached, I duplicated most of the code of music-boxer-stencil for
box-stil with a small change.  This is not a solution, just a demonstration
of what causes the programming error and the disappeared beam.  Note that I
just hardcoded Y-extent so that no calculation happens -- obviously a
non-solution ...

Possibly you can continue to use the same stencil callback for both
objects. In any case I'm pretty sure you will have to move the
determination of height to a separate group of functions.




 Unfortunately I cannot be much of help for any explanation because the way
 LilyPond acts behind the scenes is still a mystery to me...


I'd like to be able to say that it all becomes clear at some point, but
alas...

Hope this helps somewhat!

David
\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 symbol?)))
 (set! ifaces-entry (cons 'grob-interface ifaces-entry))
 (set! meta-entry (assoc-set! meta-entry 'name grob-name))
 (set! meta-entry (assoc-set! meta-entry 'interfaces
ifaces-entry))
 (set! grob-entry 

Re: box around notes

2015-04-06 Thread Pierre Perol-Schneider
BTW, regarding the smiley up on the last rest, did you see this:
http://lsr.di.unimi.it/LSR/Item?id=904
JFYI, Cheers
Pierre

2015-04-07 0:04 GMT+02:00 Pierre Perol-Schneider 
pierre.schneider.pa...@gmail.com:

 Nice work Klaus, thanks for sharing.
 Cheers,
 Pierre

 2015-04-06 23:55 GMT+02:00 Klaus Blum benbigno...@gmx.de:

 Hi David,

 here's my first attempt to apply my drawing function to your project.
 Thanks
 again for sharing this really cool tool!

 I've played around with some settings, and I also experimented with the
 messed up dynamics problem when taking the engravers out of the score
 context.
 It works if you set outside-staff-priority to a value high enough:
\override MusicBoxer.outside-staff-priority = #1
\override Box.outside-staff-priority = #1
 However, this leads to a warning:
 Ein Objekt außerhalb der Notenzeile sollte eine Richtung haben, Vorgabe
 ist
 »nach oben«
 (Following the lilypond translation, this is the original warning message:
 #: axis-group-interface.cc:786
 msgid an outside-staff object should have a direction, defaulting to up)

 It seems that there is something taken into account for spacing
 calculations, but LilyPond doesn't know if this mysterious something is
 located above or below the score.

 By the way, if I put a box around an eighth note that is attached to a
 beam,
 the beam completely disappears. With MusicBoxer this is not the case.

 Unfortunately I cannot be much of help for any explanation because the way
 LilyPond acts behind the scenes is still a mystery to me...

 Cheers,
 Klaus

 boxer4.ly http://lilypond.1069038.n5.nabble.com/file/n174138/boxer4.ly
 boxer4.pdf http://lilypond.1069038.n5.nabble.com/file/n174138/boxer4.pdf
 



 --
 View this message in context:
 http://lilypond.1069038.n5.nabble.com/box-around-notes-tp35581p174138.html
 Sent from the User mailing list archive at Nabble.com.

 ___
 lilypond-user mailing list
 lilypond-user@gnu.org
 https://lists.gnu.org/mailman/listinfo/lilypond-user



___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-04-06 Thread Klaus Blum
Hi David, 

here's my first attempt to apply my drawing function to your project. Thanks
again for sharing this really cool tool!

I've played around with some settings, and I also experimented with the
messed up dynamics problem when taking the engravers out of the score
context.
It works if you set outside-staff-priority to a value high enough:
   \override MusicBoxer.outside-staff-priority = #1
   \override Box.outside-staff-priority = #1
However, this leads to a warning:
Ein Objekt außerhalb der Notenzeile sollte eine Richtung haben, Vorgabe ist
»nach oben«
(Following the lilypond translation, this is the original warning message:
#: axis-group-interface.cc:786
msgid an outside-staff object should have a direction, defaulting to up)

It seems that there is something taken into account for spacing
calculations, but LilyPond doesn't know if this mysterious something is
located above or below the score.

By the way, if I put a box around an eighth note that is attached to a beam,
the beam completely disappears. With MusicBoxer this is not the case.

Unfortunately I cannot be much of help for any explanation because the way
LilyPond acts behind the scenes is still a mystery to me...

Cheers, 
Klaus

boxer4.ly http://lilypond.1069038.n5.nabble.com/file/n174138/boxer4.ly  
boxer4.pdf http://lilypond.1069038.n5.nabble.com/file/n174138/boxer4.pdf  



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/box-around-notes-tp35581p174138.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-04-06 Thread Pierre Perol-Schneider
Nice work Klaus, thanks for sharing.
Cheers,
Pierre

2015-04-06 23:55 GMT+02:00 Klaus Blum benbigno...@gmx.de:

 Hi David,

 here's my first attempt to apply my drawing function to your project.
 Thanks
 again for sharing this really cool tool!

 I've played around with some settings, and I also experimented with the
 messed up dynamics problem when taking the engravers out of the score
 context.
 It works if you set outside-staff-priority to a value high enough:
\override MusicBoxer.outside-staff-priority = #1
\override Box.outside-staff-priority = #1
 However, this leads to a warning:
 Ein Objekt außerhalb der Notenzeile sollte eine Richtung haben, Vorgabe
 ist
 »nach oben«
 (Following the lilypond translation, this is the original warning message:
 #: axis-group-interface.cc:786
 msgid an outside-staff object should have a direction, defaulting to up)

 It seems that there is something taken into account for spacing
 calculations, but LilyPond doesn't know if this mysterious something is
 located above or below the score.

 By the way, if I put a box around an eighth note that is attached to a
 beam,
 the beam completely disappears. With MusicBoxer this is not the case.

 Unfortunately I cannot be much of help for any explanation because the way
 LilyPond acts behind the scenes is still a mystery to me...

 Cheers,
 Klaus

 boxer4.ly http://lilypond.1069038.n5.nabble.com/file/n174138/boxer4.ly
 boxer4.pdf http://lilypond.1069038.n5.nabble.com/file/n174138/boxer4.pdf



 --
 View this message in context:
 http://lilypond.1069038.n5.nabble.com/box-around-notes-tp35581p174138.html
 Sent from the User mailing list archive at Nabble.com.

 ___
 lilypond-user mailing list
 lilypond-user@gnu.org
 https://lists.gnu.org/mailman/listinfo/lilypond-user

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-04-06 Thread Simon Albrecht

Am 07.04.2015 um 00:07 schrieb Pierre Perol-Schneider:
BTW, regarding the smiley up on the last rest, did you see this: 
http://lsr.di.unimi.it/LSR/Item?id=904
What’s your reason to not code that one with smiley = 
#(define-markup-function …)?

Just asking, it might be irrelevant to the output. But, good work :-)

Yours, Simon

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-04-06 Thread Pierre Perol-Schneider
Hi Simon,
Hmm interesting question...
Well, actually I don't remember, it's quite old now.
What I can imagine is that I didn't want to have to add '\markup'-s, e.g.:
title = \markup\smiley #size
instead of:
title = \smiley #size

But to be honest, there must be a reason, I simply don't remember it ;)

Thank you for your kind remark,
Cheers,
Pierre

2015-04-07 1:14 GMT+02:00 Simon Albrecht simon.albre...@mail.de:

 Am 07.04.2015 um 00:07 schrieb Pierre Perol-Schneider:

 BTW, regarding the smiley up on the last rest, did you see this:
 http://lsr.di.unimi.it/LSR/Item?id=904

 What’s your reason to not code that one with smiley =
 #(define-markup-function …)?
 Just asking, it might be irrelevant to the output. But, good work :-)

 Yours, Simon

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-04-06 Thread Pierre Perol-Schneider
I've add it as a markup, just in case.
Cheers
Pierre

2015-04-07 6:08 GMT+02:00 Pierre Perol-Schneider 
pierre.schneider.pa...@gmail.com:

 Hi Simon,
 Hmm interesting question...
 Well, actually I don't remember, it's quite old now.
 What I can imagine is that I didn't want to have to add '\markup'-s, e.g.:
 title = \markup\smiley #size
 instead of:
 title = \smiley #size

 But to be honest, there must be a reason, I simply don't remember it ;)

 Thank you for your kind remark,
 Cheers,
 Pierre


 2015-04-07 1:14 GMT+02:00 Simon Albrecht simon.albre...@mail.de:

 Am 07.04.2015 um 00:07 schrieb Pierre Perol-Schneider:

 BTW, regarding the smiley up on the last rest, did you see this:
 http://lsr.di.unimi.it/LSR/Item?id=904

 What’s your reason to not code that one with smiley =
 #(define-markup-function …)?
 Just asking, it might be irrelevant to the output. But, good work :-)

 Yours, Simon



___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-01-18 Thread David Nalesnik
Hi Klaus,

On Sat, Jan 17, 2015 at 9:54 AM, Klaus Blum benbigno...@gmx.de wrote:

  Hi David,

 one more big THANK YOU for your fast reply.


You're very welcome!


 Yes, it was very helpful.
 I have updated music-boxer-stencil so that it works again with the
 boxEngraver. Finally I did some cleanup to my messy code in make-box.d).


Looks great!  I like how you fixed the boundaries of the fill---looks much
better.

I've streamlined two of the variable definitions in music-boxer-stencil.  I
think you will also find it very helpful if you use line breaks and
indentation to clarify the structure of if-expressions and such.  As I was
looking at this, I went ahead and changed the formatting to help me follow
the code.  See attached excerpt.

Hope this helps!

David
#(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))
  ; (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)
 )
   )___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-01-17 Thread Klaus Blum

Hi David,

one more big THANK YOU for your fast reply. Yes, it was very helpful.
I have updated music-boxer-stencil so that it works again with the 
boxEngraver. Finally I did some cleanup to my messy code in make-box.


Greetings from Germany,
Klaus


Am 16.01.2015 um 20:30 schrieb David Nalesnik:

Hi Klaus,

In the attached, I simply added new properties: 
acknowledge-finger-interface and acknowledge-script-interface.  In the 
engraver, I used ly:grob-property to read the setting.  You'll notice 
that if something is ignored it doesn't get pushed out of the way, 
though.


Adding properties like this would get cumbersome.  It would be nice to 
have a property which takes a flexible list of interfaces to include 
(over and above interfaces which need to be acknowledged, like 
note-column-interface).


If a box is split due to a line break, it would be cool to have
those two
boxes open at the right/left side. For this, musicBoxerEngraver
would need
to tell if a box is started/stopped by a line break instead of a
manual
command.


This is not a problem.  I use the function ly:item-break-status on the 
spanner bounds to determine the state of brokenness, then add in the 
left or right vertical only if that bound has a break-status of 0 
(indicating an unbroken bound).


I tried to keep music-boxer-stencil and make-box separate.  In so 
doing, I had to add two more parameters to make-box.  (You may decide 
to merge the two functions in the end.)


Hope this is helpful,

David


\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 symbol?)))
 (set! ifaces-entry (cons 'grob-interface ifaces-entry))
 (set! meta-entry (assoc-set! meta-entry 'name grob-name))
 (set! meta-entry (assoc-set! meta-entry 'interfaces
ifaces-entry))
 (set! grob-entry (assoc-set! grob-entry 'meta meta-entry))
 (set! all-grob-descriptions
   (cons (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 

Re: box around notes

2015-01-16 Thread Klaus Blum
Hi David, 
thanks again. You're my hero: now it works.


I've added a few things so far:

- thickness property can be used to control frame thickness, can even be
set to zero (color property and layer property work by default)
- filled property (boolean) controls whether the box is to be filled with
a colored rectangle whose color can be set by fill-color property.

I've also added two global boolean variables acknowledge-finger-interface
and acknowledge-script-interface to control whether the boxes take care of
fingerings and dynamics. For example, if you want to mark themes and motifs,
you might only want to consider the notes and rests.
Unfortunately, these settings are valid for the whole score and therefore
cannot change during a piece. I'd prefer to use properties, because this
would allow \once \override etc. But I don't know how to access these
properties from within musicBoxerEngraver.
If a box is split due to a line break, it would be cool to have those two
boxes open at the right/left side. For this, musicBoxerEngraver would need
to tell if a box is started/stopped by a line break instead of a manual
command. 
Dear list members, can anybody help how to achieve that? Sorry for always
coming up with crazy ideas that go far beyond my scheme knowledge.  ;-)

Cheers, 
Klaus

boxer-attempt2.ly
http://lilypond.1069038.n5.nabble.com/file/n170575/boxer-attempt2.ly  


David Nalesnik-2 wrote
 
 You need to make LilyPond aware of the new property: what type does it
 have? does it have a documentation string?  (The latter is important
 because the documentation in the Internals Reference is generated
 automatically.)
 
 Add the following lines above the stencil function (make-box):
 
 %%%
 #(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?)
 ; add more properties here
   ))
 
 %





--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/box-around-notes-tp35581p170575.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-01-16 Thread David Nalesnik
Hi Klaus,

On Fri, Jan 16, 2015 at 11:35 AM, Klaus Blum benbigno...@gmx.de wrote:

 Hi David,
 thanks again. You're my hero: now it works.


 I've added a few things so far:

 - thickness property can be used to control frame thickness, can even be
 set to zero (color property and layer property work by default)
 - filled property (boolean) controls whether the box is to be filled with
 a colored rectangle whose color can be set by fill-color property.

 I've also added two global boolean variables acknowledge-finger-interface
 and acknowledge-script-interface to control whether the boxes take care
 of
 fingerings and dynamics. For example, if you want to mark themes and
 motifs,
 you might only want to consider the notes and rests.
 Unfortunately, these settings are valid for the whole score and therefore
 cannot change during a piece. I'd prefer to use properties, because this
 would allow \once \override etc. But I don't know how to access these
 properties from within musicBoxerEngraver.


In the attached, I simply added new properties:
acknowledge-finger-interface and acknowledge-script-interface.  In the
engraver, I used ly:grob-property to read the setting.  You'll notice that
if something is ignored it doesn't get pushed out of the way, though.

Adding properties like this would get cumbersome.  It would be nice to have
a property which takes a flexible list of interfaces to include (over and
above interfaces which need to be acknowledged, like note-column-interface).


 If a box is split due to a line break, it would be cool to have those two
 boxes open at the right/left side. For this, musicBoxerEngraver would need
 to tell if a box is started/stopped by a line break instead of a manual
 command.


This is not a problem.  I use the function ly:item-break-status on the
spanner bounds to determine the state of brokenness, then add in the left
or right vertical only if that bound has a break-status of 0 (indicating an
unbroken bound).

I tried to keep music-boxer-stencil and make-box separate.  In so doing, I
had to add two more parameters to make-box.  (You may decide to merge the
two functions in the end.)

Hope this is helpful,

David
\version 2.19.15

\header {
  tagline = ##f
}

%#(define acknowledge-finger-interface #t)
%#(define acknowledge-script-interface #t)

#(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 symbol?)))
 (set! ifaces-entry (cons 'grob-interface ifaces-entry))
 (set! meta-entry (assoc-set! meta-entry 'name grob-name))
 (set! meta-entry (assoc-set! meta-entry 'interfaces
ifaces-entry))
 (set! grob-entry (assoc-set! grob-entry 'meta meta-entry))
 (set! all-grob-descriptions
   (cons (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)  ; modified by KB
   (let ((xext (interval-widen xext padding))
 (yext (interval-widen yext padding))
 (temp-stil-inner empty-stencil)
 (temp-stil-outer empty-stencil))
 (if
  (eq? #t filled)
  (set! temp-stil-inner
(ly:make-stencil (list 'color fill-color
   (list 'round-filled-box (- (car 

Re: box around notes

2015-01-10 Thread Klaus Blum
Hi David, 

thanks for your work - this is a really great tool. 

I often work with things like this: 
http://lsr.di.unimi.it/LSR/Item?id=960
http://lsr.di.unimi.it/LSR/Item?id=960  
so what I found in this thread is very interesting for analysis purposes.

I started to try some modifications on color, thickness, solid background
etc:
http://lilypond.1069038.n5.nabble.com/file/n170307/boxer-attempt.png 

Unfortunately, I'm helpless with scheme, so I don't know how to get this to
an end...
I added two properties to the grob definition (and also made some additions
to the drawing procedures):

*
#(add-grob-definition
  'Box
  `(
 (stencil . ,box-stil)
 (thickness . 0.1)  ; added by KB
 (filled . #f)  ; added by KB
 (meta . ((class . Item)
  (interfaces . ())
*

Now I tried to modify these properties:

*
\override Score.Box.thickness = 0.5
\override Score.Box.filled = ##t
*
  
Changing the thickness property works well, but changing filled
obviously has no effect. Instead, I get this error: 
/Warnung: Eigenschafts-Typprüfung für »filled« (backend-type?) kann nicht
gefunden werden.  vielleicht ein Tippfehler? 
Warnung: Zuweisung wird übersprungen/
can't find property type-check for »filled« (backend-type?). perhaps a
typing error?
Warning: skipping assignment

Now I'm at an end... does anybody know what I'm doing wrong? :(
Thanks in advance for any hint!


Cheers, 
Klaus


boxer-attempt.ly
http://lilypond.1069038.n5.nabble.com/file/n170307/boxer-attempt.ly  
boxer-attempt.png
http://lilypond.1069038.n5.nabble.com/file/n170307/boxer-attempt.png  



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/box-around-notes-tp35581p170307.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-01-10 Thread David Nalesnik
Hi Klaus,



On Sat, Jan 10, 2015 at 7:03 PM, Klaus Blum benbigno...@gmx.de wrote:

 Hi David,

 thanks for your work - this is a really great tool.

 I often work with things like this:
 http://lsr.di.unimi.it/LSR/Item?id=960
 http://lsr.di.unimi.it/LSR/Item?id=960
 so what I found in this thread is very interesting for analysis purposes.

 I started to try some modifications on color, thickness, solid background
 etc:
 http://lilypond.1069038.n5.nabble.com/file/n170307/boxer-attempt.png


Now THAT looks cool!



 Unfortunately, I'm helpless with scheme, so I don't know how to get this to
 an end...
 I added two properties to the grob definition (and also made some additions
 to the drawing procedures):

 *
 #(add-grob-definition
   'Box
   `(
  (stencil . ,box-stil)
  (thickness . 0.1)  ; added by KB
  (filled . #f)  ; added by KB
  (meta . ((class . Item)
   (interfaces . ())
 *

 Now I tried to modify these properties:

 *
 \override Score.Box.thickness = 0.5
 \override Score.Box.filled = ##t
 *

 Changing the thickness property works well, but changing filled
 obviously has no effect. Instead, I get this error:
 /Warnung: Eigenschafts-Typprüfung für »filled« (backend-type?) kann nicht
 gefunden werden.  vielleicht ein Tippfehler?
 Warnung: Zuweisung wird übersprungen/
 can't find property type-check for »filled« (backend-type?). perhaps a
 typing error?
 Warning: skipping assignment


You need to make LilyPond aware of the new property: what type does it
have? does it have a documentation string?  (The latter is important
because the documentation in the Internals Reference is generated
automatically.)

Add the following lines above the stencil function (make-box):

%%%
#(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?)
; add more properties here
  ))

%

Now here is where you might run into a problem with the new grob.  Let's
say you decide to run a batch of files using this new grob:

lilypond file1.ly file2.ly [...]

You'll get an error about property redefined, but it will work.  (I
suppose you could remove the error warning in the definition above if the
errors in the log bother you.)

Hope this is helpful,
David
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-01-08 Thread David Nalesnik
Hi,

On Thu, Jan 8, 2015 at 7:58 AM, David Nalesnik david.nales...@gmail.com
wrote:

 Hi Marc,

 On Wed, Jan 7, 2015 at 7:43 PM, MarcM m...@mouries.net wrote:

 i tried examples in this old post but none of them compile in 2.19.15.


 [Visible at Nabble link at bottom of message]

 Yes, there have been a lot of changes to LilyPond internals since that was
 written.


I've rewritten that old file so that it will work with 2.19.15.   (There's
a note near the top explaining how to get it to work with current stable.)

I found that I needed to come up with separate grobs for the boxes in your
example--which encompass a single chord, a single note--and boxes which
encompass multiple chords, notes.  (This is because the first needs to be
an Item, the second a Spanner--to my understanding.)

There's a lot of code in this file.  I'd suggest that you move the
definitions to another file--say boxes.ily--and \include boxes.ily so you
don't have to see the mess.

I think the example should make usage pretty clear.  Note that you can do
overrides of the new grobs, just as you can with other grobs. I coopted
'padding to control the space about the box contexts.

Now, this really isn't infallible.  (For one thing, if you move the
engraver to the Staff context, dynamics get messed up.  Wish I knew why...)

Also, the boxes aren't accounted for in horizontal spacing.  You can still
fool with the bar line extent, though.

Hope you get some use out if this.

David

P.S. If anybody knows about the horizontal spacing and the issue with
dynamics, please chime in.  I'm really at a loss.  These are things that
prevent me from proposing actual LilyPond functionality :(
\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 symbol?)))
 (set! ifaces-entry (cons 'grob-interface ifaces-entry))
 (set! meta-entry (assoc-set! meta-entry 'name grob-name))
 (set! meta-entry (assoc-set! meta-entry 'interfaces
ifaces-entry))
 (set! grob-entry (assoc-set! grob-entry 'meta meta-entry))
 (set! all-grob-descriptions
   (cons (cons grob-name grob-entry)
 all-grob-descriptions

#(define (make-box thick padding xext yext)
   (let ((xext (interval-widen xext padding))
 (yext (interval-widen yext padding)))
   (ly:stencil-add
(make-filled-box-stencil xext (cons (- (car yext) thick) (car yext)))
(make-filled-box-stencil xext (cons (cdr yext) (+ (cdr yext) thick)))
(make-filled-box-stencil (cons (cdr xext) (+ (cdr xext) thick)) yext)
(make-filled-box-stencil (cons (- (car xext) thick) (car xext)) yext

#(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))
  (stil (make-box 0.1 padding X-ext Y-ext))
  (offset (ly:grob-relative-coordinate grob refp-X X)))
 (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
   '(
  (BoxEvent
   . ((description . A box encompassing music at a single timestep.)
  (types . (general-music box-event music-event event))
  ))
  ))

#(define music-boxer-types
   '(
  (MusicBoxerEvent
   . ((description . Used to signal where boxes encompassing music start and stop.)
  (types . (general-music 

Re: box around notes

2015-01-08 Thread David Nalesnik
Hi Marc,

On Wed, Jan 7, 2015 at 7:43 PM, MarcM m...@mouries.net wrote:

 i tried examples in this old post but none of them compile in 2.19.15.


[Visible at Nabble link at bottom of message]

Yes, there have been a lot of changes to LilyPond internals since that was
written.


 I created a sample example.

 Is it possible to set the box to wrap around the notes without having to
 set
 the dimensions?


The thread referenced points out that you can write a function for
NoteColumn.stencil.  However, this will only encompass noteheads and
stems.  To account for the fingering numbers I think you would need to go
the way of the custom grob.  (Which, so you know, is not orthodox
Lily-practice.)

(The NoteColumn.stencil route would handle the vertical aspect of your
particular example, at least.)



 How can we move the notes so the box does not overlap with the repeat sign
 in the second example?

 
 http://lilypond.1069038.n5.nabble.com/file/n170210/Screen_Shot_2015-01-07_at_8.png
 


Here you can change the horizontal extent of the barline:

 \once \override Score.BarLine.X-extent = #'(-1 . 3)

Hope this helps,
David
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2015-01-07 Thread MarcM
i tried examples in this old post but none of them compile in 2.19.15.

I created a sample example.

Is it possible to set the box to wrap around the notes without having to set
the dimensions?

How can we move the notes so the box does not overlap with the repeat sign
in the second example?

http://lilypond.1069038.n5.nabble.com/file/n170210/Screen_Shot_2015-01-07_at_8.png
 

\version 2.19.15

melody = \relative c'' {
  \set fingeringOrientations = #'(left)
  %1
  \repeat volta 2 {
g-3  c-2 f-11 -\markup {
  \with-dimensions #'( 0 . 0)#'(0 . 0)
  \box\with-dimensions #'(-2 . 2.5)  #'(0 . 5.5)
  \null
}
d8-4 g,-0 d' g,  d'-4 g,-0 d' g,
  }

  %2
  \repeat volta 2 {
d'-4  c'-2 f-11 -\markup {
 \with-dimensions #'( 0 . 0)#'(0 . 0)
  \box   \with-dimensions #'(-2 . 2.5)  #'(0 . 5.5)
  \null}
g8-3 d-0 g d  g8-4 d-0 g d
  }
}

\score {
  \new Staff { \melody }
}







--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/box-around-notes-tp35581p170210.html
Sent from the User mailing list archive at Nabble.com.

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2011-12-16 Thread m...@apollinemike.com
On Dec 16, 2011, at 6:27 AM, David Nalesnik wrote:

 Hi all,
 
 I'm trying to write a function to add a box around notes.  I've come up with 
 the following, and I'm wondering if anyone has any ideas how to improve it or 
 perhaps a different approach.
 
 Basically, the function creates a box as a TextSpanner.  The height of the 
 box is based on the highest and lowest stems.
 
 I'd like to automate all aspects of the function, but I've had to add a 
 correction factor for height.  This compensates for my inability to determine 
 the Y-position of the spanner. I can determine Y-values after the fact, but 
 all my attempts to determine them _within_ the function end up killing 
 parts of the box.  You can see this by uncommenting any of the display lines 
 in the function--you'll get values in the log . . . at the price of losing 
 the left and right text of the spanner--three sides of the box.  (To add to 
 the mystery for me, uncommenting single lines vs. more than one yields 
 different results.)
 
 The example uses a small correction, but even bigger numbers are needed when 
 articulations are added.
 
 Any suggestions?
 
 Thanks,
 David
 

Hey David,

It depends on what you want your box to go around.  If it's only ever notes and 
stems (i.e. not articulations, tremoli, etc.), you can add a stencil property 
to the NoteColumn grob that uses its extents for the parameters you need to 
draw your box.

Once articulations are in the game, I'd recommend creating a custom Scheme 
engraver that collects all the grobs you want, throws them into the elements 
grob array of a custom grob that implements the axis-group-interface (you can 
define your own grobs via the same procedure as grobs are defined in 
define-grobs.scm), and then use axis-group-interface::pure-height and 
axis-group-interface::height for the Y-extents (which will automatically search 
the elements grob array.

Cheers,
MS
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: box around notes

2011-12-16 Thread David Nalesnik
Hi Mike,

Thank you so much for pointing me in the right direction!

On Fri, Dec 16, 2011 at 2:06 AM, m...@apollinemike.com 
m...@apollinemike.com wrote:


 Hey David,

 Once articulations are in the game, I'd recommend creating a custom Scheme
 engraver that collects all the grobs you want, throws them into the
 elements grob array of a custom grob that implements the
 axis-group-interface (you can define your own grobs via the same procedure
 as grobs are defined in define-grobs.scm),


[...]

I do want to be able to encompass dynamics and articulations along with
note columns, so I've gone with your suggestion of a custom engraver . . .
or rather customizing someone else's beautiful example :)

I adapted the regression test scheme-text-spanner.ly (thank you to
whoever provided this!), and I've got something which mostly works.  There
are some problems, though, and I'm not sure I'm approaching this in the way
you've suggested.

First of all, is going after the stencil rather than the left and right
text (as I did originally) the tactic you had in mind for both approaches?

The first snippet looks fine (both the dynamic and the articulation are
encompassed), but the box won't expand to cover both the dynamic and the
articulation in the second example.  Also, the distance between the systems
doesn't change.  (Raising the last pitch a couple of octaves will cause an
overlap.)


 and then use axis-group-interface::pure-height and
 axis-group-interface::height for the Y-extents (which will automatically
 search the elements grob array.


This is the part that is way beyond me. . .  I'd be grateful if you could
give me some pointers here, because I've hit a dead end as far as blind
experimentation goes . . .

Best,
David


boxer-engraver02.ly
Description: Binary data
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


box around notes

2011-12-15 Thread David Nalesnik
Hi all,

I'm trying to write a function to add a box around notes.  I've come up
with the following, and I'm wondering if anyone has any ideas how to
improve it or perhaps a different approach.

Basically, the function creates a box as a TextSpanner.  The height of the
box is based on the highest and lowest stems.

I'd like to automate all aspects of the function, but I've had to add a
correction factor for height.  This compensates for my inability to
determine the Y-position of the spanner. I can determine Y-values after
the fact, but all my attempts to determine them _within_ the function end
up killing parts of the box.  You can see this by uncommenting any of the
display lines in the function--you'll get values in the log . . . at the
price of losing the left and right text of the spanner--three sides of
the box.  (To add to the mystery for me, uncommenting single lines vs. more
than one yields different results.)

The example uses a small correction, but even bigger numbers are needed
when articulations are added.

Any suggestions?

Thanks,
David


boxNotes01.ly
Description: Binary data
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user