-
-(define (volta-bracket-interface::pure-height grob start end)
- (let ((edge-height (ly:grob-property grob 'edge-height)))
- (if (number-pair? edge-height)
- (let ((smaller (min (car edge-height) (cdr edge-height)))
- (larger (max (car edge-height) (cdr edge-height))))
- (interval-union '(0 . 0) (cons smaller larger)))
- '(0 . 0))))
-
-(define pure-print-callbacks
- (list
- fret-board::calc-stencil
- note-head::brew-ez-stencil
- print-circled-text-callback
- laissez-vibrer::print
- lyric-text::print
- ly:bar-line::print
- ly:mensural-ligature::brew-ligature-primitive
- ly:note-head::print
- ly:dots::print
- ly:clef::print
- ly:flag::print
- ly:time-signature::print
- default-flag
- normal-flag
- mensural-flag
- no-flag
- modern-straight-flag
- old-straight-flag
- ly:key-signature-interface::print
- ly:percent-repeat-item-interface::beat-slash
- ly:text-interface::print
- ly:script-interface::print
- ly:sustain-pedal::print))
-
-;; Sometimes we have grobs with (Y-extent . ,ly:grob::stencil-height)
-;; and the print function is not pure, but there is a easy way to
-;; figure out the Y-extent from the print function.
-(define pure-print-to-height-conversions
- `(
- (,ly:arpeggio::print . ,ly:arpeggio::pure-height)
- (,ly:arpeggio::brew-chord-bracket . ,ly:arpeggio::pure-height)
- (,ly:arpeggio::brew-chord-slur . ,ly:arpeggio::pure-height)
- (,ly:hairpin::print . ,ly:hairpin::pure-height)
- (,ly:stem-tremolo::print . ,ly:stem-tremolo::pure-height)
- (,ly:volta-bracket-interface::print . ,volta-bracket-interface::pure-height)))
-
-;; ly:grob::stencil-extent is safe if the print callback is safe too
-(define (pure-stencil-height grob start stop)
- (let* ((sten (ly:grob-property-data grob 'stencil))
- (pure-height-callback (assoc-get sten pure-print-to-height-conversions)))
- (cond ((or
- (ly:stencil? sten)
- (memq sten pure-print-callbacks))
- (ly:grob::stencil-height grob))
- ((procedure? pure-height-callback)
- (pure-height-callback grob start stop))
- (else
- '(0 . 0)))))
-
-;; Sometimes, a pure callback will be chained to a non-pure callback via
-;; chain_offset_callback, in which case this provides a default by simply
-;; passing through the value from the pure callback.
-(define (pure-chain-offset-callback grob start end prev-offset) prev-offset)
-
-(define pure-conversions-alist
- `(
- (,ly:accidental-interface::height . ,ly:accidental-interface::pure-height)
- (,ly:axis-group-interface::calc-staff-staff-spacing . ,ly:axis-group-interface::calc-pure-staff-staff-spacing)
- (,ly:axis-group-interface::height . ,ly:axis-group-interface::pure-height)
- (,ly:beam::rest-collision-callback . ,ly:beam::pure-rest-collision-callback)
- (,ly:grob::stencil-height . ,pure-stencil-height)
- (,ly:hara-kiri-group-spanner::y-extent . ,ly:hara-kiri-group-spanner::pure-height)
- (,ly:rest-collision::force-shift-callback-rest . ,pure-chain-offset-callback)
- (,ly:rest::height . ,ly:rest::pure-height)
- (,ly:self-alignment-interface::y-aligned-on-self . ,ly:self-alignment-interface::pure-y-aligned-on-self)
- (,ly:side-position-interface::y-aligned-side . ,ly:side-position-interface::pure-y-aligned-side)
- (,ly:slur::height . ,ly:slur::pure-height)
- (,ly:slur::outside-slur-callback . ,ly:slur::pure-outside-slur-callback)
- (,ly:stem::calc-stem-begin-position . ,ly:stem::pure-calc-stem-begin-position)
- (,ly:stem::calc-stem-end-position . ,ly:stem::pure-calc-stem-end-position)
- (,stem::length . ,stem::pure-length)
- (,ly:stem::height . ,ly:stem::pure-height)
- (,ly:stem-tremolo::calc-y-offset . ,ly:stem-tremolo::pure-calc-y-offset)
- (,ly:system::height . ,ly:system::calc-pure-height)))
-
-(define pure-functions
- (list
- parenthesize-elements
- laissez-vibrer::print
- ly:flag::calc-y-offset
- ly:rest::y-offset-callback
- ly:staff-symbol-referencer::callback
- ly:staff-symbol::height))
-
-(define-public (pure-relevant? grob)
- (let ((extent-callback (ly:grob-property-data grob 'Y-extent)))
- (not (eq? #f
- (or
- (ly:unpure-pure-container? extent-callback)
- (pair? extent-callback)
- (memq extent-callback pure-functions)
- (and
- (pair? (assq extent-callback pure-conversions-alist))
- (let ((stencil (ly:grob-property-data grob 'stencil)))
- (or
- (not (eq? extent-callback ly:grob::stencil-height))
- (memq stencil pure-print-callbacks)
- (assq stencil pure-print-to-height-conversions)
- (ly:stencil? stencil)))))))))
-
-;; hideous code dup below - to be cleaned up when call pure functino
-;; is eliminated and lilypond works entirely from unpure-pure-containers
-
-(define-public (call-pure-function unpure args start end)
- (if (ly:unpure-pure-container? unpure)
- (let ((unpure (ly:unpure-pure-container-pure-part unpure)))
- (if (ly:simple-closure? unpure)
- (ly:eval-simple-closure (car args) unpure start end)
- (if (not (procedure? unpure))
- unpure
- (apply unpure
- (append
- (list (car args) start end)
- (cdr args))))))
- (if (ly:simple-closure? unpure)
- (ly:eval-simple-closure (car args) unpure start end)
- (if (not (procedure? unpure))
- unpure
- (if (memq unpure pure-functions)
- (apply unpure args)
- (let ((pure (assq unpure pure-conversions-alist)))
- (if pure
- (apply (cdr pure)
- (append
- (list (car args) start end)
- (cdr args))))))))))