]> git.donarmstrong.com Git - lilypond.git/blob - scm/layout-beam.scm
6c790e02b5e3f37aafb4b0a071fbe71be41b410c
[lilypond.git] / scm / layout-beam.scm
1 ;;;;
2 ;;;; beam.scm -- Beam scheme stuff
3 ;;;;
4 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; 
6 ;;;; (c) 2000--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;;;
8
9 ;;
10 ;; width in staff space.
11 ;;
12 (define (beam-flag-width-function type)
13   (cond
14    ((eq? type 1) 1.98) 
15    ((eq? type 1) 1.65) ;; FIXME: check what this should be and why
16    (else 1.32)))
17
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) 
21
22 "
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)
29                          (if (= 2 (abs q))
30                              (+ p (/ q 4.0))
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))))
35     
36     (if (or (not (almost-equal want-l (car posns)))
37             (not (almost-equal want-r (cdr posns))))
38         (begin
39           (ly:warning (_ "Error in beam quanting.  Expected (~S,~S) found ~S.")
40                       want-l want-r posns)
41           (set! (ly:grob-property beam 'quant-score)
42                 (format "(~S,~S)" want-l want-r)))
43         (set! (ly:grob-property beam 'quant-score) ""))))
44
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)))
50
51     (if (not correct)
52         (begin
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) ""))))
58
59 (define-public (check-quant-callbacks l r)
60   (list Beam::least_squares
61         Beam::check_concave
62         Beam::slope_damping
63         Beam::shift_region_to_valid
64         Beam::quanting
65         (check-beam-quant l r)))
66
67
68 (define-public (check-slope-callbacks comparison)
69   (list Beam::least_squares
70         Beam::check_concave
71         Beam::slope_damping
72         Beam::shift_region_to_valid
73         Beam::quanting
74         (check-beam-slope-sign comparison)))
75