lilypond-user
[Top][All Lists]
Advanced

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

Re: How to catch the current height of a StaffGroup?


From: Thomas Morley
Subject: Re: How to catch the current height of a StaffGroup?
Date: Wed, 23 May 2012 20:48:01 +0200

2012/5/23 address@hidden <address@hidden>:

> Try the buddy engraver!
(...)
> If you do something like \override Staff.BarLine #'my-name = #'foo in one 
> staff and \override Staff.BarLine #'my-name = #'bar in another and then 
> \override BreathingSign #'searching = #'(foo bar) then BreathingSign will 
> have a property 'buddies set with two buddies (the two barlines). You can 
> then find their positions via the normal grob-relative-position-finding 
> functions.

Hi Mike,

thanks for your suggestion!

As a first step I tried to display 'buddies via
BreathingSign-override. No success.
Am I doing sth wrong?

BTW, to get rid of the loads of warnings I added some more code,
trying to integrate the new properties.


\version "2.15.38"

#(define (define-grob-custom-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)

#(define all-user-grob-custom-properties
  (map
   (lambda (x)
     (apply define-grob-custom-property x))

   `(
     (buddies ,list? "Grobs for function-call")
     (searching ,list? "Looks for buddies")
     (my-name ,symbol? "general custom-grob-property-name")
     )))

#(define all-custom-grob-descriptions
   (for-each
     (lambda (x)
       (let ((interfaces
               (ly:assoc-get 'interfaces
                 (ly:assoc-get 'meta
                   (cdr x)))))
         (set! interfaces (append! interfaces '(grob-marker-interface)))))
     all-grob-descriptions))

buddyEngraver =
   #(let ((match-list '())
          (name-list '()))
      (list
        (cons 'acknowledgers
              (list
                (cons 'grob-interface
                      (lambda (engraver grob source-engraver)
                              (let ((name (ly:grob-property grob 'my-name))
                                    (searching (ly:grob-property grob
'searching)))
                                   (set! name-list (cons (cons name
grob) name-list))
                                   (set! match-list (append (map
(lambda (x) (cons name x)) searching) match-list)))))))
        (cons 'finalize
             (lambda (trans)
               (for-each
                 (lambda (x) ;(format #t "MATCHING ~a\n" x)
                   (let ((grob1 (assoc-get (car x) name-list))
                         (grob2 (assoc-get (cdr x) name-list)))
                   (ly:grob-set-property! grob2 'buddies (cons (cons
(car x) grob1) (ly:grob-property grob2 'buddies)))
                   (ly:grob-set-property! grob1 'buddies (cons (cons
(cdr x) grob2) (ly:grob-property grob1 'buddies)))))
                 match-list)))))

#(define ((staff-group-height number) grob)
     (let* ((stil (ly:text-interface::print grob))
            (par1 (ly:grob-parent grob Y))      ;; #<Grob VerticalAxisGroup >
            (par2 (ly:grob-parent par1 Y))      ;; #<Grob VerticalAlignment >
            (par3 (ly:grob-parent par2 Y))      ;; #<Grob System >
            (buddies (ly:grob-property grob 'buddies))
            )

     (newline)(display "buddies ")(display buddies)

     (ly:grob-set-property! grob 'stencil
       (grob-interpret-markup grob
           (make-line-markup
             (list
                 (make-with-dimensions-markup '(0 . 0) '(0 . 0)
                   (make-with-color-markup blue
                     (make-draw-line-markup (cons 0 number))))))))))

%--------- Test

one = {
        \relative c' {
                a2 b
                \override Score.BreathingSign #'after-line-breaking =
                        #(staff-group-height -13)
                \override Score.BreathingSign #'searching = #'(foo bar)
                \override Staff.BarLine #'my-name = #'foo
                c\breathe
                d \break
                a,, b''
                
                \override Score.BreathingSign #'after-line-breaking =
                        #(staff-group-height -22.5)
                
                c\breathe d
        }
}

two = {
        \relative c {
                \clef bass
                a2 b \override Staff.BarLine #'my-name = #'bar
                c d a'' b,, c d
        }
}

\score {
        \new StaffGroup <<
           \new Staff \one
           \new Staff \two
           >>
        \layout {
                \context {
                \Staff
                \consists \buddyEngraver
                }
        }
}

Thanks,
  Harm



reply via email to

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