Quoting Joe Neeman <joenee...@gmail.com>:

On Fri, Feb 24, 2012 at 3:04 PM, Pavel Roskin <pro...@gnu.org> wrote:
I tried writing an engraver that could be added to the StaffGroup
context.  Collecting stems is not a problem.  The problem is that even
the finalize handler is called to early.  I'm getting a warning:

programming error: vertical alignment called before line breaking
continuing, cross fingers


It's a little hard to guess what's going wrong without knowing exactly what
you've tried. Are you trying to do layout logic in the engraver (ie. by
collecting stems, reading their properties, doing calculations and then
setting more properties)?

Yes, except that I'm not setting anything yet.  The current file is attached.

If you are, the first step is to move the layout
logic into grob callbacks.

I guess I'll need to redefine the stencil for stems. Or maybe you mean some other callback?

I did a similar thing before. I put all the logic into a function that was used to redefine the length property of the stem. It worked for a simple case of two stems, but failed when three stems needed to be connected. The Y-extent for at least one of the stems wasn't calculated yet.

I also tried setting Y-extent, but it's read-only.

--
Regards,
Pavel Roskin

\version "2.14.0"

#(define ((connectableStem? xref yref stemone dir below?) stemtwo)
   (cond
    ((not (memq 'stem-interface (ly:grob-interfaces stemtwo))) #f)
    ((equal? stemone stemtwo) #f)
    ((inf? (car (ly:grob-extent stemtwo xref X))) #f)
    ((not (equal? (ly:grob-extent stemone xref X) (ly:grob-extent stemtwo xref X))) #f)
    ((not (equal? dir (ly:grob-property stemtwo 'direction))) #f)
    ((below? (car (ly:grob-extent stemtwo yref Y)) (car (ly:grob-extent stemone yref Y))) #f)
    (else #t)))

#(define ((lowerStem? ref below?) lower upper)
   (below? (car (ly:grob-extent lower ref Y)) (car (ly:grob-extent upper ref Y))))

#(define (crossStaffLength grob ctx stems)
   (let* ((papercolumn (ly:context-property ctx 'currentMusicalColumn))
          (foo (ly:message "papercolumn: ~a" papercolumn))
          (xref (ly:grob-common-refpoint grob (car stems) X))
          (foo (ly:message "xref: ~a" xref))
          (yref (ly:grob-common-refpoint grob (car stems) Y))
          (foo (ly:message "yref: ~a" yref))
          (dir (ly:grob-property grob 'direction))
          (below? (if (= dir UP) < >))
          (foo (ly:message "stems: ~a" stems))
          (goodstems (filter (connectableStem? xref yref grob dir below?) stems))
          (foo (ly:message "stems1: ~a" stems))
          (beststems (sort goodstems (lowerStem? yref below?)))
          (foo (ly:message "stems2: ~a" stems))
          (peer (car (append beststems (list grob))))
          (foo (ly:message "peer: ~a" peer)))
     (ly:message "grob: ~a" (ly:grob-extent grob yref Y))
     (ly:message "peer: ~a" (ly:grob-extent peer yref Y))
     (if (equal? grob peer)
         (begin (ly:programming-error "No suitable stem to connect to") 4)
         (if (> dir 0)
             (* 2 (- (car (ly:grob-extent peer yref Y))
                     (car (ly:grob-extent grob yref Y))))
             (* 2 (- (cdr (ly:grob-extent grob yref Y))
                     (cdr (ly:grob-extent peer yref Y))))))))

#(define (connectStems ctx stems)
   (ly:message "stems: ~a" stems)
   (if (and (pair? stems) (pair? (cdr stems)))
       (let ((stem (car stems))
             (otherstems (cdr stems)))
         (ly:message "otherstems: ~a" otherstems)
         (ly:message "length: ~a"
           (crossStaffLength stem ctx otherstems)))))

#(define (Cross_staff_stem_engraver ctx)
  (let ((stems '()))

    `((acknowledgers
       (stem-interface
        . ,(lambda (trans grob source)
             (ly:message "acknowledger: ~a" grob)
             (set! stems (cons grob stems))))

       (note-column-interface
        . ,(lambda (trans grob source)
             (ly:message "acknowledger: ~a" grob))))

      (process-music
       . ,(lambda (trans) (ly:message "process-music") (connectStems ctx stems)))

      (process-acknowledged
       . ,(lambda (trans) (ly:message "process-acknowledged")))

      (stop-translation-timestep
       . ,(lambda (trans) (ly:message "stop-translation-timestep") (connectStems ctx stems)))

      (finalize
       . ,(lambda (trans) (ly:message "finalize") (connectStems ctx stems))))))

\layout {
  \context {
    \StaffGroup
    \consists #Cross_staff_stem_engraver
  }
}

\new StaffGroup <<
  \new Staff { g' }
  \new Staff { c' }
>>
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to