]> git.donarmstrong.com Git - lilypond.git/blob - scm/beam.scm
patch::: 1.5.40.jcn1
[lilypond.git] / scm / beam.scm
1 ;;;;
2 ;;;; beam.scm -- Beam scheme stuff
3 ;;;;
4 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; 
6 ;;;; (c) 2000--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;;;
8
9 (define (default-beam-space-function multiplicity)
10   (if (<= multiplicity 3) 0.816 0.844)
11   )
12
13 ;;
14 ;; width in staff space.
15 ;;
16 (define (default-beam-flag-width-function type)
17   (cond
18    ((eq? type 1) 1.98) 
19    ((eq? type 1) 1.65) ;; FIXME: check what this should be and why
20    (else 1.32)
21    ))
22
23
24 ;; This is a mess : global namespace pollution. We should wait
25 ;;  till guile has proper toplevel environment support.
26
27
28 ;; Beams should be prevented to conflict with the stafflines, 
29 ;; especially at small slopes
30 ;;    ----------------------------------------------------------
31 ;;                                                   ########
32 ;;                                        ########
33 ;;                             ########
34 ;;    --------------########------------------------------------
35 ;;       ########
36 ;;
37 ;;       hang       straddle   sit        inter      hang
38
39 ;; inter seems to be a modern quirk, we don't use that
40
41 ;; two popular veritcal beam quantings
42 ;; see params.ly: #'beam-vertical-quants
43
44
45 (define (default-beam-pos-quants beam multiplicity dy staff-line)
46   (let* ((beam-straddle 0)
47          (thick (ly-get-grob-property beam 'thickness))
48          (beam-sit (/ (- thick staff-line) 2))
49          (beam-hang (- 1 (/ (- thick staff-line) 2)))
50          (quants (list beam-hang))
51          )
52     
53     (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2)))
54         (set! quants (cons beam-sit quants)))
55     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
56         (set! quants (cons beam-straddle quants)))
57     ;; period: 1 (staff-space)
58     (append quants (list (+ 1 (car quants))))))
59
60 (define (beam-traditional-pos-quants beam multiplicity dy staff-line)
61   (let* ((beam-straddle 0)
62         (thick (ly-get-grob-property beam 'thickness))
63         (beam-sit (/ (- thick staff-line) 2))
64         (beam-hang (- 1 (/ (- thick staff-line) 2)))
65         (quants '())
66         )
67     (if (>= dy (/ staff-line -2))
68         (set! quants (cons beam-hang quants)))
69     (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
70         (set! quants (cons beam-sit quants)))
71     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
72         (set! quants (cons beam-straddle quants)))
73     ;; period: 1 (staff-space)
74     (append quants (list (+ 1 (car quants))))))
75
76
77 ;; There are several ways to calculate the direction of a beam
78 ;;
79 ;; * majority: number count of up or down notes
80 ;; * mean    : mean centre distance of all notes
81 ;; * median  : mean centre distance weighted per note
82
83 (define (dir-compare up down)
84   (sign (- up down)))
85
86 ;; arguments are in the form (up . down)
87 (define (beam-dir-majority count total)
88   (dir-compare (car count) (cdr count)))
89
90 (beam-dir-majority '(0 . 0) '(0 . 0))
91
92 (define (beam-dir-mean count total)
93   (dir-compare (car total) (cdr total)))
94
95 (define (beam-dir-median count total)
96   (if (and (> (car count) 0)
97            (> (cdr count) 0))
98       (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
99       (dir-compare (car count) (cdr count))))
100             
101
102
103 ;; [Ross] states that the majority of the notes dictates the
104 ;; direction (and not the mean of "center distance")
105 ;;
106 ;; But is that because it really looks better, or because he wants
107 ;; to provide some real simple hands-on rules?
108 ;;     
109 ;; We have our doubts, so we simply provide all sensible alternatives.
110
111 ;; array index multiplicity, last if index>size
112 ;; beamed stems
113
114
115 ;; TODO
116 ;;  - take #forced stems into account (now done in C++)?
117 ;;  - take staff-position of chord or beam into account
118