lilypond-user
[Top][All Lists]
Advanced

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

Re: bug in magnetic snapping lyrics engraver


From: Jean Abou Samra
Subject: Re: bug in magnetic snapping lyrics engraver
Date: Wed, 6 Apr 2022 20:17:30 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0

Le 06/04/2022 à 14:33, Werner LEMBERG a écrit :
Is someone taking care of bugs in the magnetic snapping lyrics
engraver?  Here is an example where it fails to position lyrics
correctly (see last system in the image).


     Werner


PS: I've attached a version of `magnetic-lyrics.ily` that actually
     works with the current development version (using an updated
     `add-grob-definition` routine).



To be honest, I don't know why the snippet is so complicated.
I'd just have done:

\version "2.23.7"

#(define (Left_hyphen_pointer_engraver context)
   (let ((hyphen #f)
         (text #f))
     (make-engraver
      (acknowledgers
       ((lyric-syllable-interface engraver grob source-engraver)
          (set! text grob)))
      (end-acknowledgers
       ((lyric-hyphen-interface engraver grob source-engraver)
          (when (not (grob::has-interface grob 'lyric-space-interface))
                (set! hyphen grob))))
      ((stop-translation-timestep engraver)
         (when (and text hyphen)
               (ly:grob-set-object! text 'left-hyphen hyphen))
         (set! text #f)
         (set! hyphen #f)))))

#(define (lyric-text::apply-magnetic-offset! grob)
   (let ((hyphen (ly:grob-object grob 'left-hyphen #f)))
     (when hyphen
       (let* ((left-text (ly:spanner-bound hyphen LEFT))
              (common (ly:grob-common-refpoint grob left-text X))
              (my-x-ext (ly:grob-extent grob common X))
              (left-x-ext (begin
                            ;; Trigger magnetism for left-text
                            (ly:grob-property left-text 'after-line-breaking)
                            (ly:grob-extent left-text common X)))
              (delta (- (interval-start my-x-ext)
                        (interval-end left-x-ext)))
              (details (ly:grob-property grob 'details))
              (threshold (assoc-get 'squash-threshold details 0.2)))
         (when (< delta threshold)
           (ly:grob-translate-axis! grob
                                    (- delta)
                                    X))))))

#(define (lyric-hyphen::displace-bounds-first grob)
   ;; Make very sure this callback isn't triggered too early.
   (let ((left (ly:spanner-bound grob LEFT))
         (right (ly:spanner-bound grob RIGHT)))
     (ly:grob-property left 'after-line-breaking)
     (ly:grob-property right 'after-line-breaking)
     (ly:lyric-hyphen::print grob)))

\layout {
  \context {
    \Lyrics
    \consists #Left_hyphen_pointer_engraver
    \override LyricText.after-line-breaking = 
#lyric-text::apply-magnetic-offset!
    \override LyricHyphen.stencil = #lyric-hyphen::displace-bounds-first
    \override LyricText.details.squash-threshold = 0.7
    \override LyricHyphen.minimum-distance = 0
    \override LyricHyphen.minimum-length = 0
    \override LyricSpace.minimum-distance = 1
  }
}
<<
  \new Voice = "foo" \relative c' {
    \repeat unfold 16 { a8 b a2 a8 b }
  }
  \new Lyrics \lyricsto "foo" {
    \repeat unfold 10 { foo }
    \repeat unfold 10 { foo -- \markup \caps bar }
    \repeat unfold 10 { \markup \bold syl -- la -- ble }
    a \markup \with-color #red ran -- \markup \box dom string of mo -- no -- 
syl -- la -- bic
    and mul -- ti -- \markup \fontsize #5 syl -- la -- bic
    \markup \bold \underline ver -- \markup \italic bi -- age
    \markup {
      \stencil #(make-circle-stencil 0.5 0 #f)
    }
  }



Which seems to work, and doesn't have your first bug.

Did I miss something?

The second bug is super hard to fix: when you tell LilyPond about
spacing constraints between lyrics, before line breaking, you need
to assume a lyric syllable won't be moved to the left by 'magnetism',
because if you do, the spacer might think it can space its right neighbor
more to the left due to the space left by moving the syllable to the
left, and if the compression cannot actually be done, it will collide.
But when the compression does get done, and the room is left empty,
horizontal spacing has already been done and it is too late to tell
the right neighbor that it would have room on its left. Am I making
sense?


Jean




reply via email to

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