]> git.donarmstrong.com Git - lilypond.git/blob - scm/beam.scm
patch::: 1.5.39.jcn2
[lilypond.git] / scm / beam.scm
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;                  BEAMS
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
5 (define (default-beam-space-function multiplicity)
6   (if (<= multiplicity 3) 0.816 0.844)
7   )
8
9 ;
10 ; width in staff space.
11 ;
12 (define (default-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
19
20 ; This is a mess : global namespace pollution. We should wait
21 ;  till guile has proper toplevel environment support.
22
23
24 ;; Beams should be prevented to conflict with the stafflines, 
25 ;; especially at small slopes
26 ;;    ----------------------------------------------------------
27 ;;                                                   ########
28 ;;                                        ########
29 ;;                             ########
30 ;;    --------------########------------------------------------
31 ;;       ########
32 ;;
33 ;;       hang       straddle   sit        inter      hang
34
35 ;; inter seems to be a modern quirk, we don't use that
36
37   
38 ;; Note: quanting period is take as quants.top () - quants[0], 
39 ;; which should be 1 (== 1 interline)
40  (define (mean a b) (* 0.5 (+ a  b)))
41 (define (default-beam-dy-quants beam stafflinethick)
42   (let ((thick (ly-get-grob-property beam 'thickness)))
43     ;; amazing.  this is wrong:
44     (list 0 (mean thick stafflinethick) (+ thick stafflinethick) 1)
45     ;; it should be this: but the visual effect is even uglier,
46     ;; because dy quants are not synchronised with left y
47     ;; (list 0 (/ (- thick stafflinethick) 2) (- thick stafflinethick) 1)
48     ))
49
50 ;; two popular veritcal beam quantings
51 ;; see params.ly: #'beam-vertical-quants
52
53 ; (todo: merge these 2 funcs ? )
54
55 (define (default-beam-y-quants beam multiplicity dy staff-line)
56   (let* ((beam-straddle 0)
57          (thick (ly-get-grob-property beam 'thickness))
58          (beam-sit (/ (- thick staff-line) 2))
59          (beam-hang (- 1 (/ (- thick staff-line) 2)))
60          (quants (list beam-hang))
61          )
62     
63     (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2)))
64         (set! quants (cons beam-sit quants)))
65     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
66         (set! quants (cons beam-straddle quants)))
67     ;; period: 1 (interline)
68     (append quants (list (+ 1 (car quants))))))
69
70 (define (beam-traditional-y-quants beam multiplicity dy staff-line)
71   (let* ((beam-straddle 0)
72         (thick (ly-get-grob-property beam 'thickness))
73         (beam-sit (/ (- thick staff-line) 2))
74         (beam-hang (- 1 (/ (- thick staff-line) 2)))
75         (quants '())
76         )
77     (if (>= dy (/ staff-line -2))
78         (set! quants (cons beam-hang quants)))
79     (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
80         (set! quants (cons beam-sit quants)))
81     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
82         (set! quants (cons beam-straddle quants)))
83     ;; period: 1 (interline)
84     (append quants (list (+ 1 (car quants))))))
85
86
87 ;; There are several ways to calculate the direction of a beam
88 ;;
89 ;; * majority: number count of up or down notes
90 ;; * mean    : mean centre distance of all notes
91 ;; * median  : mean centre distance weighted per note
92
93 (define (dir-compare up down)
94   (sign (- up down)))
95
96 ;; arguments are in the form (up . down)
97 (define (beam-dir-majority count total)
98   (dir-compare (car count) (cdr count)))
99
100 (beam-dir-majority '(0 . 0) '(0 . 0))
101
102 (define (beam-dir-mean count total)
103   (dir-compare (car total) (cdr total)))
104
105 (define (beam-dir-median count total)
106   (if (and (> (car count) 0)
107            (> (cdr count) 0))
108       (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
109       (dir-compare (car count) (cdr count))))
110             
111
112
113 ;; [Ross] states that the majority of the notes dictates the
114 ;; direction (and not the mean of "center distance")
115 ;;
116 ;; But is that because it really looks better, or because he wants
117 ;; to provide some real simple hands-on rules?
118 ;;     
119 ;; We have our doubts, so we simply provide all sensible alternatives.
120
121 ;; array index multiplicity, last if index>size
122 ;; beamed stems
123
124
125 ;; TODO
126 ;;  - take #forced stems into account (now done in C++)?
127 ;;  - take staff-position of chord or beam into account
128