]> git.donarmstrong.com Git - lilypond.git/blob - scm/layout-beam.scm
9f1840dd33d3197007467a45f7f2f0e374651b1e
[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--2007 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;;;
8
9 (define ((check-beam-quant posl posr) beam posns)
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) 
12
13 "
14   (let* ((thick (ly:grob-property beam 'thickness))
15          (layout (ly:grob-layout beam))
16          (lthick (ly:output-def-lookup layout 'line-thickness))
17          (staff-thick lthick) ; fixme.
18          (quant->coord (lambda (p q)
19                          (if (= 2 (abs q))
20                              (+ p (/ q 4.0))
21                              (+ p (- (* 0.5 q thick) (* 0.5 q lthick))))))
22          (want-l (quant->coord (car posl) (cdr posl))) 
23          (want-r (quant->coord (car posr) (cdr posr)))
24          (almost-equal (lambda (x y) (< (abs (- x y)) 1e-3))))
25     
26     (if (or (not (almost-equal want-l (car posns)))
27             (not (almost-equal want-r (cdr posns))))
28         (begin
29           (ly:warning (_ "Error in beam quanting.  Expected (~S,~S) found ~S.")
30                       want-l want-r posns)
31           (set! (ly:grob-property beam 'annotation)
32                 (format "(~S,~S)" want-l want-r))))
33     posns
34     ))
35
36
37 (define ((check-beam-slope-sign comparison) beam posns)
38   "Check whether the slope of BEAM is correct wrt. COMPARISON."
39   (let* ((slope-sign (- (cdr posns) (car posns)))
40          (correct (comparison slope-sign 0)))
41     (if (not correct)
42         (begin
43           (ly:warning (_ "Error in beam quanting.  Expected ~S 0, found ~S.")
44                       (procedure-name comparison) slope-sign)
45           (set! (ly:grob-property beam 'annotation)
46                 (format "~S 0" (procedure-name comparison))))
47         (set! (ly:grob-property beam 'annotation) ""))
48     posns))
49
50
51 (define-public (check-quant-callbacks l r)
52   (list ly:beam::calc-least-squares-positions
53         ly:beam::slope-damping
54         ly:beam::shift-region-to-valid
55         ly:beam::quanting
56         (check-beam-quant l r)
57         ))
58
59
60 (define-public (check-slope-callbacks comparison)
61   (list ly:beam::calc-least-squares-positions
62         ly:beam::slope-damping
63         ly:beam::shift-region-to-valid
64         ly:beam::quanting
65         (check-beam-slope-sign comparison)      
66         ))
67