Le 22/05/2022 à 10:52, Valentin Petzel a écrit :
Hello Werner,

after some testing I've concluded that the broken slur only starts after the 
mark, which in this case leads to negative length and thus suicide.

While I still think that this is questionable behaviour by the tie stencil, I 
think I can solve this by delaying the timestep this Mark is created in.


I've opened https://gitlab.com/lilypond/lilypond/-/issues/6349
about that. Meanwhile, how about using a spanner rather than
an item? See attached.

Best,
Jean

\version "2.23.9"

#(set-object-property! 'staffAnnotation 'translation-type? markup?)

#(define (Staff_annotation_engraver context)
   (let* ((last-annot (make-symbol "unique"))
          (spanner #f))
    (make-engraver
     ((process-music engraver)
      (let* ((raw-annot (ly:context-property context 'staffAnnotation))
             (annot (if (markup? raw-annot)
                        raw-annot
                        ""))
             (parenthesized-annot (if (markup? raw-annot)
                                      (make-concat-markup (list "(" raw-annot ")"))
                                      ""))
             (bracketed-annot (if (markup? raw-annot)
                                  (make-concat-markup (list "[" raw-annot "]"))
                                  "")))
        (if (not (equal? annot last-annot))
            (let ((musical-column
                   (ly:context-property context 'currentMusicalColumn))
                  (non-musical-column
                   (ly:context-property context 'currentCommandColumn))
                  (previous-spanner spanner))
             (set! last-annot annot)
             (if spanner
                 (begin
                  (ly:spanner-set-bound! spanner RIGHT non-musical-column)
                  (ly:engraver-announce-end-grob engraver spanner '())
                  (set! spanner #f)))
             (set! spanner (ly:engraver-make-grob engraver 'TextSpanner '()))
             (ly:spanner-set-bound! spanner LEFT musical-column)
             (ly:grob-set-property! spanner
                                    'bound-details
                                    `((left (text . ,annot))
                                      (left-broken
                                       (text . ,(make-general-align-markup X CENTER parenthesized-annot))
                                       (end-on-note . #t))
                                      (right)
                                      (right-broken (text))))
             (if previous-spanner
                 (ly:grob-set-property! previous-spanner
                                        'after-line-breaking
                                        (lambda (broken-previous-spanner)
                                          (let ((broken-non-musical-column
                                                 (ly:spanner-bound broken-previous-spanner RIGHT)))
                                            (if (eqv? LEFT (ly:item-break-dir broken-non-musical-column))
                                                (ly:grob-set-nested-property!
                                                 broken-previous-spanner
                                                 '(bound-details right text)
                                                 (make-general-align-markup X RIGHT bracketed-annot)))))))
             (ly:grob-set-property! spanner 'font-shape '())
             (ly:grob-set-property! spanner 'style 'none)))))
     (acknowledgers
      ((note-column-interface engraver grob source-engraver)
       (ly:pointer-group-interface::add-grob spanner 'note-columns grob)))
     ((finalize engraver)
      (if spanner
          (let ((non-musical-column (ly:context-property context 'currentCommandColumn)))
            (ly:spanner-set-bound! spanner RIGHT non-musical-column)))))))

\layout {
  \context {
    \Staff
    \consists #Staff_annotation_engraver
  }
}

<<
  \new Staff {
    \repeat unfold 14 { c'1 }
  }
  \new Staff {
    \set Staff.staffAnnotation = "a 2" c'1 1 \break 1 1 1 ~ \break 1 1
    \key c\minor \time 2/2 
    \set Staff.staffAnnotation = "a 3" 1 \break 1 
    \set Staff.staffAnnotation = "a 4" \break 1 2
    \set Staff.staffAnnotation = "a 42" 2 1
    \unset Staff.staffAnnotation \break 1 \break
    \set Staff.staffAnnotation = "a laturca" 1
  }
>>

Reply via email to