lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Code pointer from end-BarLine to previous NoteHead.?


From: Jean Abou Samra
Subject: Re: Code pointer from end-BarLine to previous NoteHead.?
Date: Sun, 17 Jul 2022 09:26:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0



Le 17/07/2022 à 01:25, Thomas Morley a écrit :
Thanks for your explanations, right now I had only a quick glance over them.
I'll hopefully have some time soon to dive into it...
Nevertheless, before I posted the problem I searched for an
'original'-BarLine-grob, as we have for broken spanners.
For (maybe broken) spanners I sometimes switch to that
'original'-grob, would it improve the situation if we had some
'original' for items as well?



D'oh, why didn't think about that? It does solve the problem too
(and more elegantly):


\version "2.23.11"

tst =
#(lambda (ctx)
  (let ((nhd #f)
        (previous-nhd #f)
        (bar #f))
  (make-engraver
    (acknowledgers
      ((bar-line-interface engraver grob source-engraver)
        (set! bar grob))
      ((note-head-interface engraver grob source-engraver)
        (set! nhd grob)))
    ((stop-translation-timestep engraver)
     (when (and bar previous-nhd)
       ;; for debugging
       (ly:grob-set-property! previous-nhd 'color red)
       (ly:grob-set-object! bar 'element previous-nhd)
       (set! (ly:grob-property bar 'details)
             (acons 'previous-note-head
                    previous-nhd
                    (ly:grob-property bar 'details))))
       (when nhd
       ;; Move the next line out of (when ...) if you only want the
       ;; note head from the time step right before, and not the last
       ;; note head seen before the bar line.
       (set! previous-nhd nhd)
       (set! nhd #f))
     (set! bar #f)))))

moveBarLineToPrevHead = {
  \override Staff.BarLine.Y-offset =
    #(lambda (grob)
      (let* ((prev-head (ly:grob-object (ly:grob-original grob)
                                        'element
                                        #f))
             (staff-pos (and prev-head (ly:grob-property prev-head 'staff-position))))
       (/ (or staff-pos 0) 2)))
}

\layout {
  \context {
      \Staff
      \consists \tst
      \moveBarLineToPrevHead
  }
}

\new Staff { s4 s \bar "." b s c' d' e' f' g' a' b' c'' \bar "|." }



Not sure why it didn't work when you tried?



Jean



reply via email to

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