[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Code pointer from end-BarLine to previous NoteHead.?
From: |
Thomas Morley |
Subject: |
Re: Code pointer from end-BarLine to previous NoteHead.? |
Date: |
Sat, 16 Jul 2022 20:47:05 +0200 |
Am Sa., 16. Juli 2022 um 14:05 Uhr schrieb Jean Abou Samra <jean@abou-samra.fr>:
>
>
>
> > Le 16 juil. 2022 à 13:01, Thomas Morley <thomasmorley65@gmail.com> a écrit :
> >
> > Hi,
> >
> > I'm trying to code an engraver setting a pointer from BarLine to
> > previous NoteHead and an override for BarLine.Y-offset acting upon
> > that pointer.
> > It does not work, if the BarLine is at end.
> >
> > Here a stripped down example (every security is removed and all is
> > heavily simplified):
> >
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> >
> > \version "2.23.9"
> >
> > tst =
> > #(lambda (ctx)
> > (let ((nc #f)
> > (bar #f))
> > (make-engraver
> > (acknowledgers
> > ((bar-line-interface engraver grob source-engraver)
> > (set! bar grob))
> > ((note-head-interface engraver grob source-engraver)
> > (set! nc grob)))
> > ((stop-translation-timestep engraver)
> > (if (and nc bar)
> > (ly:grob-set-object! bar 'element nc))))))
> >
> > moveBarLineToPrevHead =
> > \override Staff.BarLine.Y-offset =
> > #(lambda (grob)
> > (let* ((prev-head (ly:grob-object grob 'element))
> > (staff-pos
> > (if (ly:grob? prev-head)
> > (ly:grob-property prev-head 'staff-position #f)
> > #f)))
> > (pretty-print
> > (list
> > (cons 'prev-head prev-head)
> > (cons 'staff-pos staff-pos)))
> > (/ (or staff-pos 10) 2)))
> >
> > \layout {
> > \context {
> > \Staff
> > \consists \tst
> > \moveBarLineToPrevHead
> > }
> > }
> >
> > \new Staff { b4 \bar "." b }
> > \new Staff { b4 \bar "." }
> >
> > %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> >
> > I'm aware the (main) difference between the two staves is the
> > break-direction of the BarLine.
> >
> > Though, how to catch it ?
> > Or how to do it different?
> >
> > Thanks,
> > Harm
>
>
> In a given timestep, the currentCommandColumn is at the _left_ of the
> currentMusicalColumn. You’re storing a pointer to the next note head, not the
> previous.
>
> Jean
>
>
Hi Jean,
thanks for the hint.
Alas, the code below _ensures_ the NoteHead _before_ the BarLine is
taken (if I'm wrong here, I am completely lost), and again the
override for BarLine.Y-offset fails.
tst =
#(lambda (ctx)
(let ((nhds '())
(bar #f))
(make-engraver
(acknowledgers
((bar-line-interface engraver grob source-engraver)
(set! bar grob))
((note-head-interface engraver grob source-engraver)
(set! nhds (cons (cons (ly:context-current-moment ctx) grob) nhds))))
((stop-translation-timestep engraver)
(let* ((curr (ly:context-current-moment ctx))
(nhds-to-consider
(remove
(lambda (x)
(equal? (car x) curr))
nhds))
(sorted-nhds
(reverse
(sort
nhds-to-consider
(lambda (x y)
(ly:moment<? (car x) (car y)))))))
(if (and (ly:grob? bar) (pair? nhds))
(begin
(ly:grob-set-property! (cdr (car sorted-nhds)) 'color red)
(ly:grob-set-object! bar 'element (car sorted-nhds))
(set! bar #f))))))))
moveBarLineToPrevHead =
\override Staff.BarLine.Y-offset =
#(lambda (grob)
(let* ((bar-elt (ly:grob-object grob 'element))
(prev-head (cdr bar-elt))
(staff-pos
(if (ly:grob? prev-head)
(ly:grob-property prev-head 'staff-position #f)
#f)))
(pretty-print bar-elt)
(/ (or staff-pos 10) 2)))
\layout {
\context {
\Staff
\consists \tst
\moveBarLineToPrevHead
}
}
%\new Staff { b4 \bar "." b }
\new Staff { b4 b \bar "." }
Further hints are much appreciated.
Cheers,
Harm
- Code pointer from end-BarLine to previous NoteHead.?, Thomas Morley, 2022/07/16
- Re: Code pointer from end-BarLine to previous NoteHead.?, Jean Abou Samra, 2022/07/16
- Re: Code pointer from end-BarLine to previous NoteHead.?,
Thomas Morley <=
- Re: Code pointer from end-BarLine to previous NoteHead.?, Jean Abou Samra, 2022/07/16
- Re: Code pointer from end-BarLine to previous NoteHead.?, Thomas Morley, 2022/07/16
- Re: Code pointer from end-BarLine to previous NoteHead.?, Jean Abou Samra, 2022/07/17
- Re: Code pointer from end-BarLine to previous NoteHead.?, Thomas Morley, 2022/07/17
- Re: Code pointer from end-BarLine to previous NoteHead.?, Thomas Morley, 2022/07/17
- Re: Code pointer from end-BarLine to previous NoteHead.?, Jean Abou Samra, 2022/07/17
- Re: Code pointer from end-BarLine to previous NoteHead.?, David Kastrup, 2022/07/17
- Re: Code pointer from end-BarLine to previous NoteHead.?, Jean Abou Samra, 2022/07/17
- Re: Code pointer from end-BarLine to previous NoteHead.?, David Kastrup, 2022/07/17
- Re: Code pointer from end-BarLine to previous NoteHead.?, Jean Abou Samra, 2022/07/18