Le 19 nov. 2022 à 02:37, Gregory Evans <gregoryrowlandevans@gmail.com> a écrit :
Hello Jean,
thank you for the information about after-line-breaking and the timing of skyline computing. Is there an equivalent property to trigger callback after the skylines are calculated?
I’m afraid not. There are lower-level techniques you can use for that though, but see below for why you won’t need them.
I am trying to use (ly:stencil-add ...)
to add to the stencil of a notehead by drawing a line from one notehead in one staff to a notehead in another staff.
Have you seen the VoiceFollower grob? Try using that instead.
By reading things in 'left-bound-info and 'right-bound-info, you can also spare yourself quite some code.
The notehead grob does not appear to have a cross-staff property to delay stencil callback.
NoteHead is a very fundamental grob at the heart of a lot of code (note collision handling, beams, note spacing, etc.). That code makes reasonable assumptions about the note heads and doesn’t expect cross-staff note heads.
\language "english"
\version "2.23.14"
#(set-global-staff-size 12)
\score {
<<
\new Staff {
\override NoteHead.cross-staff = ##t
\once \override NoteHead.after-line-breaking = #(lambda (grob)
(let*
(
(sys (ly:grob-system grob))
(x-extent (ly:grob-extent grob sys X))
(y-extent (ly:grob-extent grob sys Y))
)
(display (list x-extent ))
)
)
c'1
c'1
c'1
c'1
}
\new Staff {
c'1
c'1
c'1
c'1
}
>>
}
A larger example of the function (without a great deal of context) looks like this:
interrupt = #(define-music-function (value) (number?)
#{
\once \override Staff.NoteHead.after-line-breaking = #(lambda (grob)
(let* (
(stem (ly:grob-object grob 'stem))
(stem-dir (ly:grob-property stem 'direction))
(stem-thickness (ly:grob-property stem 'thickness))
(thickness (/ stem-thickness 10))
(notecol (ly:grob-parent grob X))
(meta (assoc 'other-grob (ly:grob-property notecol 'meta)))
Have you seen ly:grob-object and ly:grob-set-object! ?
That would be way cleaner than abusing 'meta for this purpose. There is also 'details you can use instead of 'meta.
(other (if meta
(cdr meta)
grob
))
(notehead-width (cdr (ly:grob-property grob 'X-extent)))
(sys (ly:grob-system grob))
(now-pos (ly:grob-extent grob sys X))
(next-pos (ly:grob-extent other sys X))
;;the offending lines
(now-pos-y (ly:grob-extent grob common Y))
(next-pos-y (ly:grob-extent other common Y))
(x-distance
(if (= stem-dir -1)
(+ (- (get-distance now-pos next-pos) notehead-width ) (/ thickness 2))
(- (get-distance now-pos next-pos) (/ thickness 2))
))
(y-distance
(if (= stem-dir -1)
(+ (- (get-distance now-pos-y next-pos-y) notehead-width ) (/ thickness 2))
(- (get-distance now-pos-y next-pos-y) (/ thickness 2))
))
;; alternative which takes input number
;(ps-bracket
; (if (= stem-dir -1)
; (draw-ps-bracket x-distance notehead-width (- value 0.5) thickness)
; (draw-ps-bracket x-distance notehead-width value thickness)
; ))
(ps-bracket
Does 'ps' stand for PostScript?
Best,
Jean