]> git.donarmstrong.com Git - lilypond.git/blob - scm/layout-beam.scm
Run grand-replace for 2010.
[lilypond.git] / scm / layout-beam.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2000--2010 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;;
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
9 ;;;;
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ;;;; GNU General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
17
18 (define ((check-beam-quant posl posr) beam posns)
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* ((thick (ly:grob-property beam 'beam-thickness))
24          (layout (ly:grob-layout beam))
25          (lthick (ly:output-def-lookup layout 'line-thickness))
26          (staff-thick lthick) ; fixme.
27          (quant->coord (lambda (p q)
28                          (if (= 2 (abs q))
29                              (+ p (/ q 4.0))
30                              (+ p (- (* 0.5 q thick) (* 0.5 q lthick))))))
31          (want-l (quant->coord (car posl) (cdr posl))) 
32          (want-r (quant->coord (car posr) (cdr posr)))
33          (almost-equal (lambda (x y) (< (abs (- x y)) 1e-3))))
34     
35     (if (or (not (almost-equal want-l (car posns)))
36             (not (almost-equal want-r (cdr posns))))
37         (begin
38           (ly:warning (_ "Error in beam quanting.  Expected (~S,~S) found ~S.")
39                       want-l want-r posns)
40           (set! (ly:grob-property beam 'annotation)
41                 (format "(~S,~S)" want-l want-r))))
42     posns
43     ))
44
45
46 (define ((check-beam-slope-sign comparison) beam posns)
47   "Check whether the slope of BEAM is correct wrt. COMPARISON."
48   (let* ((slope-sign (- (cdr posns) (car posns)))
49          (correct (comparison slope-sign 0)))
50     (if (not correct)
51         (begin
52           (ly:warning (_ "Error in beam quanting.  Expected ~S 0, found ~S.")
53                       (procedure-name comparison) slope-sign)
54           (set! (ly:grob-property beam 'annotation)
55                 (format "~S 0" (procedure-name comparison))))
56         (set! (ly:grob-property beam 'annotation) ""))
57     posns))
58
59
60 (define-public (check-quant-callbacks l r)
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-quant l r)
66         ))
67
68
69 (define-public (check-slope-callbacks comparison)
70   (list ly:beam::calc-least-squares-positions
71         ly:beam::slope-damping
72         ly:beam::shift-region-to-valid
73         ly:beam::quanting
74         (check-beam-slope-sign comparison)      
75         ))
76