lilypond-user
[Top][All Lists]
Advanced

[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:17:19 -0600

Hi Harm,

On Wed, Mar 3, 2021 at 6:56 AM Thomas Morley <thomasmorley65@gmail.com> wrote:
>
> Hi,
>
> please have a look at the following minimal, producing three staves,
> the middle one with consecutive TextSpanners:
>
> mus = { bes \startTextSpan b\stopTextSpan \startTextSpan bis\stopTextSpan }
> << { a4 a a } \mus { c' c' c' } >>
>
> Now I want to know the starting and ending NoteColumns of the _first_
> TextSpanner.
> Though, the first TextSpanner is left-bounded by NoteColumn and
> right-bounded by PaperColumn.
>
> How to get the NoteColumn at first TextSpanner's end?
>
> Below some test-code.
> Obviously I can filter PaperColumn's elements for NoteColumns, but
> PaperColumn is a Score-grob, thus I get all three.
> How to select?
> (I may not know the position of the Staff with the TextSpanners)
>
> #(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))
>                )
>     (pretty-print
>       (list
>         left-bound
>         right-bound
>         ncs-from-grob
>         (equal? left-bound (car ncs-from-grob))
>         ncs-from-right-bound
>         )))))
>
> mus = {
>   bes4-\tweak #'after-line-breaking #tst
>    \startTextSpan
>   b\stopTextSpan
>    \startTextSpan
>   bis\stopTextSpan
> }
>
> <<
>   { a4 a a }
>   \mus
>   { c' c' c' }
> >>
>
> Thanks,
>   Harm
>

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' }
>>



reply via email to

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