Hi Harm,

On Sat, Oct 22, 2011 at 11:35 AM, harm6 <[email protected]>wrote:

>
> Hi,
>
> the following function should rebuild a beam.
>
> \version "2.14.2"
>
> #(set-global-staff-size 20)
>
> #(define (test-stencil grob)
>  (let* ((beam (ly:beam::print grob))
>        (beam-extent-x (ly:stencil-extent beam X))
>        (beam-length-x (interval-length beam-extent-x))
>        (single-beam-thickness (ly:grob-property grob 'beam-thickness))
>        (beam-positions (ly:grob-property grob 'positions))
>        (mrkp (markup #:beam    (* beam-length-x 0.97)  ;; why??
>                        0               ;; level Beams only!
>                        single-beam-thickness))
>        (new-Beam (ly:stencil-in-color
>                    (ly:stencil-translate-axis
>                      (ly:stencil-translate-axis
>                        (grob-interpret-markup grob mrkp)
>                        -0.025 X)               ;; why??
>                      (car beam-positions)
>                      Y)
>                      1 0 0)))
>
>   new-Beam))
>
> \relative c' {
>  \override Beam #'layer = #-4
>  \once \override Beam #'stencil = #test-stencil
>  e'8 [e]
>  \override Beam #'color = #green
>  f8 [f]
> }
>
> But I noticed two problems:
> First I have to adjust the beam-length. (This needs to be done in addiction
> to the global-staff-size.) Seems that ly:stencil-extent gives not the exact
> value!?
> What am I missing?
>

I'm guessing that it's an issue with the markup command \beam.  Looking at
the definition in define-markup-commands.scm, it seems that 'blot-diameter
isn't taken into account in the calculation of width and thickness.   (Is
this intentional or a defect?)  The following fixes the problem with the
beam's length and thickness, and will work when you change the staff size:

\version "2.14.2"

#(set-global-staff-size 24)

#(define (test-stencil grob)
 (let* ((beam (ly:beam::print grob))
        (b-d (ly:output-def-lookup (ly:grob-layout grob) 'blot-diameter))
        (beam-extent-x (ly:stencil-extent beam X))
        (beam-length-x (interval-length beam-extent-x))
        (single-beam-thickness (ly:grob-property grob 'beam-thickness))
        (beam-positions (ly:grob-property grob 'positions))
        (mrkp (markup #:beam (- beam-length-x b-d)
                             0               ;; level Beams only!
                             (- single-beam-thickness b-d)))
        (new-Beam (ly:stencil-in-color
                    (ly:stencil-translate-axis
                      (ly:stencil-translate-axis
                        (grob-interpret-markup grob mrkp)
                        -0.024 X)               ;; why??
                      (car beam-positions)
                      Y)
                    1 0 0)))
    new-Beam))

\relative c' {
 \override Beam #'layer = #-4
 \once \override Beam #'stencil = #test-stencil
 e'8 [e]
 \once \override Beam #'color = #red
 e [e]
 \override Beam #'color = #green
 f8 [f]
}


> And second there's need to use ly:stencil-translate-axis to move the new
> beam a little in X-axis-direction. But why?
>

I can't figure this one out...

HTH,
David
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to