+(define-public (grob::unpure-Y-extent-from-stencil pure-function)
+ "The unpure height will come from a stencil whereas the pure
+ height will come from @code{pure-function}."
+ (ly:make-unpure-pure-container ly:grob::stencil-height pure-function))
+
+(define-public grob::unpure-horizontal-skylines-from-stencil
+ (ly:make-unpure-pure-container
+ ly:grob::horizontal-skylines-from-stencil
+ ly:grob::pure-simple-horizontal-skylines-from-extents))
+
+(define-public grob::always-horizontal-skylines-from-stencil
+ (ly:make-unpure-pure-container
+ ly:grob::horizontal-skylines-from-stencil))
+
+(define-public grob::unpure-vertical-skylines-from-stencil
+ (ly:make-unpure-pure-container
+ ly:grob::vertical-skylines-from-stencil
+ ly:grob::pure-simple-vertical-skylines-from-extents))
+
+(define-public grob::always-vertical-skylines-from-stencil
+ (ly:make-unpure-pure-container
+ ly:grob::vertical-skylines-from-stencil))
+
+(define-public grob::always-vertical-skylines-from-element-stencils
+ (ly:make-unpure-pure-container
+ ly:grob::vertical-skylines-from-element-stencils
+ ly:grob::pure-vertical-skylines-from-element-stencils))
+
+(define-public grob::always-horizontal-skylines-from-element-stencils
+ (ly:make-unpure-pure-container
+ ly:grob::horizontal-skylines-from-element-stencils
+ ly:grob::pure-horizontal-skylines-from-element-stencils))
+
+;; Using this as a callback for a grob's Y-extent promises
+;; that the grob's stencil does not depend on line-spacing.
+;; We use this promise to figure the space required by Clefs
+;; and such at the note-spacing stage.
+
+(define-public grob::always-Y-extent-from-stencil
+ (ly:make-unpure-pure-container ly:grob::stencil-height))
+
+(define-public (layout-line-thickness grob)
+ "Get the line thickness of the @var{grob}'s corresponding layout."
+ (let* ((layout (ly:grob-layout grob))
+ (line-thickness (ly:output-def-lookup layout 'line-thickness)))
+
+ line-thickness))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; beam slope
+
+;; even though kievan noteheads do not have stems, their
+;; invisible stems help with beam placement
+;; this assures that invisible stems for kievan notes are aligned
+;; to the center of kievan noteheads. that is thus where the beams'
+;; x extrema will fall
+(define-public (stem::kievan-offset-callback grob)
+ (let* ((note-heads (ly:grob-object grob 'note-heads))
+ (note-heads-grobs (if (not (null? note-heads))
+ (ly:grob-array->list note-heads)
+ '()))
+ (first-note-head (if (not (null? note-heads-grobs))
+ (car note-heads-grobs)
+ '()))
+ (note-head-w (if (not (null? first-note-head))
+ (ly:grob-extent first-note-head first-note-head X)
+ '(0 . 0))))
+ (interval-center note-head-w)))
+
+
+;; sets position of beams for Kievan notation
+(define-public (beam::get-kievan-positions grob)
+ (let* ((stems (ly:grob-object grob 'stems))
+ (stems-grobs (if (not (null? stems))
+ (ly:grob-array->list stems)
+ '()))
+ (first-stem (if (not (null? stems-grobs))
+ (car stems-grobs)
+ '()))
+ (note-heads (if (not (null? first-stem))
+ (ly:grob-object first-stem 'note-heads)
+ '()))
+ (note-heads-grobs (if (not (null? note-heads))
+ (ly:grob-array->list note-heads)
+ '()))
+ (first-note-head (if (not (null? note-heads-grobs))
+ (car note-heads-grobs)
+ '()))
+ (next-stem (if (not (null? stems))
+ (cadr stems-grobs)
+ '()))
+ (next-note-heads (if (not (null? next-stem))
+ (ly:grob-object next-stem 'note-heads)
+ '()))
+ (next-note-heads-grobs (if (not (null? next-note-heads))
+ (ly:grob-array->list next-note-heads)
+ '()))
+ (next-note-head (if (not (null? next-note-heads-grobs))
+ (car next-note-heads-grobs)
+ '()))
+ (left-pos (ly:grob-property first-note-head 'Y-offset))
+ (right-pos (ly:grob-property next-note-head 'Y-offset))
+ (direction (ly:grob-property grob 'direction))
+ (first-nh-height (ly:grob::stencil-height first-note-head))
+ (next-nh-height (ly:grob::stencil-height next-note-head))
+ (left-height (if (= direction DOWN)
+ (+ (car first-nh-height) 0.75)
+ (- (cdr first-nh-height) 0.75)))
+ (right-height (if (= direction DOWN)
+ (+ (car next-nh-height) 0.75)
+ (- (cdr next-nh-height) 0.75))))
+ (cons (+ left-pos left-height) (+ right-pos right-height))))
+
+(define-public (beam::get-kievan-quantized-positions grob)
+ (let* ((pos (ly:grob-property grob 'positions))
+ (stems (ly:grob-object grob 'stems))
+ (stems-grobs (if (not (null? stems))
+ (ly:grob-array->list stems)
+ '())))
+ (for-each
+ (lambda (g)
+ (ly:grob-set-property! g 'stem-begin-position 0)
+ (ly:grob-set-property! g 'length 0))
+ stems-grobs)
+ pos))
+
+;; calculates each slope of a broken beam individually
+(define-public (beam::place-broken-parts-individually grob)
+ (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
+
+;; calculates the slope of a beam as a single unit,
+;; even if it is broken. this assures that the beam
+;; will pick up where it left off after a line break
+(define-public (beam::align-with-broken-parts grob)
+ (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
+
+;; uses the broken beam style from edition peters combines the
+;; values of place-broken-parts-individually and align-with-broken-parts above,
+;; favoring place-broken-parts-individually when the beam naturally has a steeper
+;; incline and align-with-broken-parts when the beam is flat
+(define-public (beam::slope-like-broken-parts grob)
+ (define (slope y x)
+ (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
+ (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
+ (original (ly:grob-original grob))
+ (siblings (if (ly:grob? original)
+ (ly:spanner-broken-into original)
+ '())))
+ (if (null? siblings)
+ quant1
+ (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
+ (x-span (ly:grob-property grob 'X-positions))
+ (slope1 (slope quant1 x-span))
+ (slope2 (slope quant2 x-span))
+ (quant2 (if (not (= (sign slope1) (sign slope2)))
+ '(0 . 0)
+ quant2))
+ (factor (/ (atan (abs slope1)) PI-OVER-TWO))
+ (base (cons-map
+ (lambda (x)
+ (+ (* (x quant1) (- 1 factor))
+ (* (x quant2) factor)))
+ (cons car cdr))))
+ (ly:beam::quanting grob base #f)))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; cross-staff stuff
+
+(define-public (script-or-side-position-cross-staff g)
+ (or
+ (ly:script-interface::calc-cross-staff g)
+ (ly:side-position-interface::calc-cross-staff g)))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; side-position stuff
+
+(define-public (only-if-beamed g)
+ (any (lambda (x) (ly:grob? (ly:grob-object x 'beam)))
+ (ly:grob-array->list (ly:grob-object g 'side-support-elements))))
+
+(define-public side-position-interface::y-aligned-side
+ (ly:make-unpure-pure-container
+ ly:side-position-interface::y-aligned-side
+ ly:side-position-interface::pure-y-aligned-side))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; self-alignment stuff
+
+(define-public self-alignment-interface::y-aligned-on-self
+ (ly:make-unpure-pure-container
+ ly:self-alignment-interface::y-aligned-on-self
+ ly:self-alignment-interface::pure-y-aligned-on-self))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; staff symbol
+
+(define staff-symbol-referencer::callback
+ (ly:make-unpure-pure-container ly:staff-symbol-referencer::callback))