2 ;;;; beam.scm -- Beam scheme stuff
4 ;;;; source file of the GNU LilyPond music typesetter
6 ;;;; (c) 2000--2005 Jan Nieuwenhuizen <janneke@gnu.org>
10 ;; width in staff space.
12 (define (beam-flag-width-function type)
15 ((eq? type 1) 1.65) ;; FIXME: check what this should be and why
18 (define ((check-beam-quant posl posr) beam)
19 "Check whether BEAM has POSL and POSR quants. POSL are (POSITION
20 . QUANT) pairs, where QUANT is -1 (hang), 0 (center), 1 (sit) or -2/ 2 (inter)
23 (let* ((posns (ly:grob-property beam 'positions))
24 (thick (ly:grob-property beam 'thickness))
25 (layout (ly:grob-layout beam))
26 (lthick (ly:output-def-lookup layout 'linethickness))
27 (staff-thick lthick) ; fixme.
28 (quant->coord (lambda (p q)
31 (+ p (- (* 0.5 q thick) (* 0.5 q lthick))))))
32 (want-l (quant->coord (car posl) (cdr posl)))
33 (want-r (quant->coord (car posr) (cdr posr)))
34 (almost-equal (lambda (x y) (< (abs (- x y)) 1e-3))))
36 (if (or (not (almost-equal want-l (car posns)))
37 (not (almost-equal want-r (cdr posns))))
39 (ly:warning (_ "Error in beam quanting. Expected (~S,~S) found ~S.")
41 (set! (ly:grob-property beam 'quant-score)
42 (format "(~S,~S)" want-l want-r)))
43 (set! (ly:grob-property beam 'quant-score) ""))))
45 (define ((check-beam-slope-sign comparison) beam)
46 "Check whether the slope of BEAM is correct wrt. COMPARISON."
47 (let* ((posns (ly:grob-property beam 'positions))
48 (slope-sign (- (cdr posns) (car posns)))
49 (correct (comparison slope-sign 0)))
53 (ly:warning (_ "Error in beam quanting. Expected ~S 0, found ~S.")
54 (procedure-name comparison) "0" slope-sign)
55 (set! (ly:grob-property beam 'quant-score)
56 (format "~S 0" (procedure-name comparison))))
57 (set! (ly:grob-property beam 'quant-score) ""))))
59 (define-public (check-quant-callbacks l r)
60 (list Beam::least_squares
63 Beam::shift_region_to_valid
65 (check-beam-quant l r)))
68 (define-public (check-slope-callbacks comparison)
69 (list Beam::least_squares
72 Beam::shift_region_to_valid
74 (check-beam-slope-sign comparison)))