lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New grob-stencil needs to look at Beam-dimensions


From: Thomas Morley
Subject: New grob-stencil needs to look at Beam-dimensions
Date: Sat, 1 Jun 2019 13:39:34 +0200

Hi,

currently I continue my work to create a Slash-grob for automatic slashed Beams.
The Slash-stencil needs to know Beam-properties (X-positions,
positions) to be adjusted. If I call those beam-properties directly
the Beam collopses, because this call is done before the Beam is
ready.
But if I wrap the Slash-stencil in another procedure like
(define slash-stil (lambda (grob) (lambda (grob) ...)))
all works.

Questions:
- Why does it work? (it seems the outer procedure is called
before-line-breaking, the inner after-line-breaking)
- Is this something I can rely on (I'm thinking of patch) or am I
doing bug-using?
- Is there a better/different method?

Below some code to play around with, heavily stripped down but still working.

Thanks,
  Harm

#(define slash-stil
  (lambda (grob)
    (pretty-print "second lambda")
    (pretty-print (ly:grob-property (ly:grob-parent grob Y) 'X-positions))
    (grob-interpret-markup grob "buzz")))

#(define slash-stencil
  (lambda (grob)
    (pretty-print "first lambda")
    ;(pretty-print (ly:grob-property (ly:grob-parent grob Y) 'X-positions))
    slash-stil))

#(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)))
    (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))))

#(add-grob-definition
  'Slash
  `((meta . ((class . Item)
             (interfaces . ())))))

#(define-public (Slash_engraver context)
    (make-engraver
      (acknowledgers
        ((beam-interface engraver grob source-engraver)
         (let ((slash-grob (ly:engraver-make-grob engraver 'Slash '())))
           (set! (ly:grob-parent slash-grob Y) grob))))))

\layout {
  \context {
    \Global
    \grobdescriptions #all-grob-descriptions
  }
  \context {
    \Voice
    \consists #Slash_engraver
    \override Slash.stencil = #slash-stencil
    %\override Slash.stencil = #slash-stil
  }
}

{
  b8[ b]
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]