2 ;;;; beam.scm -- Beam scheme stuff
4 ;;;; source file of the GNU LilyPond music typesetter
6 ;;;; (c) 2000--2005 Jan Nieuwenhuizen <janneke@gnu.org>
9 (define ((check-beam-quant posl posr) beam)
10 "Check whether BEAM has POSL and POSR quants. POSL are (POSITION
11 . QUANT) pairs, where QUANT is -1 (hang), 0 (center), 1 (sit) or -2/ 2 (inter)
14 (let* ((posns (ly:grob-property beam 'positions))
15 (thick (ly:grob-property beam 'thickness))
16 (layout (ly:grob-layout beam))
17 (lthick (ly:output-def-lookup layout 'linethickness))
18 (staff-thick lthick) ; fixme.
19 (quant->coord (lambda (p q)
22 (+ p (- (* 0.5 q thick) (* 0.5 q lthick))))))
23 (want-l (quant->coord (car posl) (cdr posl)))
24 (want-r (quant->coord (car posr) (cdr posr)))
25 (almost-equal (lambda (x y) (< (abs (- x y)) 1e-3))))
27 (if (or (not (almost-equal want-l (car posns)))
28 (not (almost-equal want-r (cdr posns))))
30 (ly:warning (_ "Error in beam quanting. Expected (~S,~S) found ~S.")
32 (set! (ly:grob-property beam 'quant-score)
33 (format "(~S,~S)" want-l want-r)))
34 (set! (ly:grob-property beam 'quant-score) ""))))
36 (define ((check-beam-slope-sign comparison) beam)
37 "Check whether the slope of BEAM is correct wrt. COMPARISON."
38 (let* ((posns (ly:grob-property beam 'positions))
39 (slope-sign (- (cdr posns) (car posns)))
40 (correct (comparison slope-sign 0)))
44 (ly:warning (_ "Error in beam quanting. Expected ~S 0, found ~S.")
45 (procedure-name comparison) "0" slope-sign)
46 (set! (ly:grob-property beam 'quant-score)
47 (format "~S 0" (procedure-name comparison))))
48 (set! (ly:grob-property beam 'quant-score) ""))))
50 (define-public (check-quant-callbacks l r)
51 (list Beam::least_squares
54 Beam::shift_region_to_valid
56 (check-beam-quant l r)))
59 (define-public (check-slope-callbacks comparison)
60 (list Beam::least_squares
63 Beam::shift_region_to_valid
65 (check-beam-slope-sign comparison)))