[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get bounding NoteColumns of the first of consecutive TextSpan
From: |
David Nalesnik |
Subject: |
Re: How to get bounding NoteColumns of the first of consecutive TextSpanners |
Date: |
Wed, 3 Mar 2021 15:52:06 -0600 |
On Wed, Mar 3, 2021 at 3:17 PM David Nalesnik <david.nalesnik@gmail.com> wrote:
>
> The only thing I can think of at the moment is to compare the
> StaffSymbol of the left bound with that of each of the NoteColumns on
> the right. Of course, I realize right away that that will break down
> if the spanner crosses a line break. (Use an override of
> 'before-line-breaking?)
>
> Here's the code I hacked up. I'll keep thinking about this.
>
> Best,
> David
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
> #(define tst
> (lambda (grob)
> (let* ((left-bound (ly:spanner-bound grob LEFT))
> (right-bound (ly:spanner-bound grob RIGHT))
> (ncs-from-grob
> (ly:grob-array->list (ly:grob-object grob 'note-columns)))
> (right-bound-elts
> (ly:grob-array->list
> (ly:grob-object right-bound 'elements)))
> (ncs-from-right-bound
> (filter
> (lambda (elt) (grob::has-interface elt 'note-column-interface))
> right-bound-elts))
> (left-bound-staff-symbol (ly:grob-object left-bound
> 'staff-symbol))
> (same-staff-right-bound-nc
> (filter
> (lambda (nc)
> (eq? (ly:grob-object nc 'staff-symbol)
> left-bound-staff-symbol))
> ncs-from-right-bound))
> )
> (ly:grob-set-property!
> (ly:grob-array-ref
> (ly:grob-object (car same-staff-right-bound-nc) 'note-heads)
> 0)
> 'color red)
> (pretty-print
> (list
> left-bound
> right-bound
> ncs-from-grob
> (equal? left-bound (car ncs-from-grob))
> ncs-from-right-bound
> same-staff-right-bound-nc
> )))))
>
> mus = {
> bes4-\tweak #'after-line-breaking #tst
> \startTextSpan
> b\stopTextSpan
> \startTextSpan
> bis\stopTextSpan
> }
>
> <<
> { a4 a a }
> \mus
> { c' c' c' }
> >>
Rather than comparing with the StaffSymbol of the left bound, it would
be better to look at the StaffSymbol of the TextSpanner:
#(define tst
(lambda (grob)
(let* ((left-bound (ly:spanner-bound grob LEFT))
(right-bound (ly:spanner-bound grob RIGHT))
(ncs-from-grob
(ly:grob-array->list (ly:grob-object grob 'note-columns)))
(right-bound-elts
(ly:grob-array->list
(ly:grob-object right-bound 'elements)))
(ncs-from-right-bound
(filter
(lambda (elt) (grob::has-interface elt 'note-column-interface))
right-bound-elts))
(spanner-staff-symbol (ly:grob-object grob 'staff-symbol))
(same-staff-right-nc
(filter
(lambda (nc)
(eq? (ly:grob-object nc 'staff-symbol)
spanner-staff-symbol))
ncs-from-right-bound))
)
(ly:grob-set-property!
(ly:grob-array-ref
(ly:grob-object (car same-staff-right-nc) 'note-heads)
0)
'color red)
(pretty-print
(list
left-bound
right-bound
ncs-from-grob
(equal? left-bound (car ncs-from-grob))
ncs-from-right-bound
same-staff-right-nc
)))))
mus = {
bes4-\tweak #'after-line-breaking #tst
\startTextSpan
b\stopTextSpan
\startTextSpan
bis\stopTextSpan
}
<<
{ a4 a a }
\mus
{ c' c' c' }
>>
%%%%%%%%%%%
HTH,
David