Hello list,
to my grief I noticed that David Nalesnik's id-aware spanner
implementation in scheme no longer works in 2.39.48. It gives me errors
like "warning: No spanner to end!!" and "warning: incomplete spanner
removed!" if there are overlapping spanners. No
For reference, I again attach David N's (most recent) textspanner
implementation. The \score block is a minimal example.
Note: this worked fine with 2.19.39, and fails with 2.19.48. I didn't
look at intermediate versions.
Rutger
\version "2.19"
%% Incorporating some code from the rewrite in Scheme of
%% Text_spanner_engraver in input/regression/scheme-text-spanner.ly
#(define (add-bound-item spanner item)
(if (null? (ly:spanner-bound spanner LEFT))
(ly:spanner-set-bound! spanner LEFT item)
(ly:spanner-set-bound! spanner RIGHT item)))
#(define (axis-offset-symbol axis)
(if (eq? axis X) 'X-offset 'Y-offset))
#(define (set-axis! grob axis)
(if (not (number? (ly:grob-property grob 'side-axis)))
(begin
(set! (ly:grob-property grob 'side-axis) axis)
(ly:grob-chain-callback
grob
(if (eq? axis X)
ly:side-position-interface::x-aligned-side
side-position-interface::y-aligned-side)
(axis-offset-symbol axis)
#(define (assign-spanner-index spanner orig-ls)
"Determine the position of a new spanner in an ordered sequence
of spanners. The goal is for the sequence to begin with zero and
contain no gaps. Return the index representing the spanner's position."
(if (null? orig-ls)
0
(let loop ((ls orig-ls) (insert? #t) (result 0))
(cond
((null? ls) result)
;; position at head of list
((and insert? (> (caar orig-ls) 0))
(loop ls #f 0))
;; no gaps, put at end of list
((and insert? (null? (cdr ls)))
(loop (cdr ls) #f (1+ (caar ls
;; fill lowest position of gap
((and insert?
(> (caadr ls) (1+ (caar ls
(loop (cdr ls) #f (1+ (caar ls
(else (loop (cdr ls) insert? result))
alternateTextSpannerEngraver =
#(lambda (context)
(let (;; a list of pairs comprising a spanner index
;; (not spanner-id) and a spanner which has been begun
(spanners '())
(finished '()) ; list of spanners in completion stage
(start-events '()) ; list of START events
(stop-events '())) ; list of STOP events
(make-engraver
;; \startTextSpan, \stopTextSpan, and the like create events
;; which we collect here.
(listeners
((text-span-event engraver event)
(if (= START (ly:event-property event 'span-direction))
(set! start-events (cons event start-events))
(set! stop-events (cons event stop-events)
;; Populate 'note-columns property of spanners. Bounds are
;; set to note columns, and each spanner keeps a record of
;; the note columns it traverses.
(acknowledgers
((note-column-interface engraver grob source-engraver)
(for-each (lambda (s)
(ly:pointer-group-interface::add-grob
(cdr s) 'note-columns grob)
(if (null? (ly:spanner-bound (cdr s) LEFT))
(add-bound-item (cdr s) grob)))
spanners)
;; finished only contains spanners, no indices
(for-each (lambda (f)
(ly:pointer-group-interface::add-grob
f 'note-columns grob)
(if (null? (ly:spanner-bound f RIGHT))
(add-bound-item f grob)))
finished)))
((process-music trans)
;; Move begun spanners from 'span' to 'finished'. We do this
;; on the basis of 'spanner-id. If we find a match--either
;; the strings are the same, or both are unset--a transfer
;; can be made. Return a warning if we find no match: spanner
;; hasn't been properly begun.
(for-each
(lambda (es)
(let ((es-id (ly:event-property es 'spanner-id)))
(let loop ((sp spanners))
(if (null? sp)
(ly:warning "No spanner to end!!")
(let ((sp-id (ly:event-property
(event-cause (cdar sp)) 'spanner-id)))
(cond
((or
(and
(string? sp-id)
(string? es-id)
(string=? sp-id es-id))
;; deal with \startTextSpan, \stopTextSpan
(and
(null? sp-id)
(null? es-id)))
(set! finished (cons (cdar sp) finished))
(set! spanners (remove (lambda (s) (eq? s (car sp))) spanners)))
(else (loop (cdr sp)
stop-events)
;; The