Hello Werner,

I’ve changed it up so that the a2 is always aligned to the note when it is 
set. This also solves the first one not being printed.

I’m not yet sure about the thing with the tie, but it seems to me that this is 
a bug in the tie engraver. My code does not touch ties in any way, and it is 
reasonable that the tie engraver should be able to handle other engravers 
maybe adding stuff in between.

I will need to look into this some more.

Cheers,
Valentin

Am Sonntag, 22. Mai 2022, 08:18:21 CEST schrieb Werner LEMBERG:
> > Basically, it works great, but there are two problems (tested with
> > 2.23.9).
> > 
> > * It doesn't print 'a 2' at the very beginning.
> > 
> > * Contrary to `\mark`, the 'a 2' should always be horizontally
> > 
> >   aligned to a note column and not to prefatory matter like time or
> >   key signatures.
> 
> And I've just found a third, serious problem:
> 
> * Broken ties disappear.  The attached image shows the previous
>   example with an inserted tie, with and without all annotations
>   removed.
> 
> 
>     Werner

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

#(define (staff-annotation-engraver context)
   (let* ((last-annot '()))
    (make-engraver
     (acknowledgers
      ((bar-line-interface engraver grob source-engraver)
       (let* ((annot (ly:context-property context 'staffAnnotation))
              (break-visibility (ly:context-property context 'staffAnnotationBreakVisibility begin-of-line-visible)))
         (if (and (markup? annot) (equal? annot last-annot))
             (let ((grob (ly:engraver-make-grob engraver 'RehearsalMark '())))
               (ly:grob-set-property! grob 'break-visibility break-visibility)
               (ly:grob-set-property! grob 'text (markup #:concat ("(" annot ")")))
               (ly:grob-set-property! grob 'self-alignment-X LEFT))))))
     ((process-music engraver)
      (let* ((annot (ly:context-property context 'staffAnnotation)))
        (if (and (markup? annot) (not (equal? annot last-annot)))
            (let ((grob (ly:engraver-make-grob engraver 'RehearsalMark '()))
                  (br-grob (ly:engraver-make-grob engraver 'RehearsalMark '())))
              (ly:grob-set-property! grob 'text annot)
              (ly:grob-set-property! grob 'self-alignment-X LEFT)
              (ly:grob-set-property! grob 'non-musical #f)
              (ly:grob-set-property! br-grob 'break-visibility end-of-line-visible)
              (ly:grob-set-property! br-grob 'text (markup #:concat ("[" annot "]")))
              (ly:grob-set-property! br-grob 'self-alignment-X RIGHT)))))
     ((stop-translation-timestep engraver)
      (set! last-annot (ly:context-property context 'staffAnnotation))))))

\layout {
  \context {
    \Staff
    \consists #staff-annotation-engraver
  }
}

{
  \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
}

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to