]> git.donarmstrong.com Git - lilypond.git/blob - scm/beam.scm
release: 1.3.138
[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         )
44     
45     (list 0 (mean thick stafflinethick) (+ thick stafflinethick) 1)
46     ))
47
48 ;; two popular veritcal beam quantings
49 ;; see params.ly: #'beam-vertical-quants
50
51 ; (todo: merge these 2 funcs ? )
52
53 (define (default-beam-y-quants beam multiplicity dy staff-line)
54   (let* ((beam-straddle 0)
55          (thick (ly-get-grob-property beam 'thickness))
56          (beam-sit (/ (+ thick staff-line) 2))
57          (beam-hang (- 1 (/ (- thick staff-line) 2)))
58          (quants (list beam-hang))
59          )
60     
61     (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2)))
62         (set! quants (cons beam-sit quants)))
63     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
64         (set! quants (cons beam-straddle quants)))
65     ;; period: 1 (interline)
66     (append quants (list (+ 1 (car quants))))))
67
68 (define (beam-traditional-y-quants beam multiplicity dy staff-line)
69   (let* ((beam-straddle 0)
70         (thick (ly-get-grob-property beam 'thickness))
71         (beam-sit (/ (+ thick staff-line) 2))
72         (beam-hang (- 1 (/ (- thick staff-line) 2)))
73         (quants '())
74         )
75     (if (>= dy (/ staff-line -2))
76         (set! quants (cons beam-hang quants)))
77     (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
78         (set! quants (cons beam-sit quants)))
79     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
80         (set! quants (cons beam-straddle quants)))
81     ;; period: 1 (interline)
82     (append quants (list (+ 1 (car quants))))))
83
84
85 ;; There are several ways to calculate the direction of a beam
86 ;;
87 ;; * majority: number count of up or down notes
88 ;; * mean    : mean centre distance of all notes
89 ;; * median  : mean centre distance weighted per note
90
91 (define (dir-compare up down)
92   (sign (- up down)))
93
94 ;; arguments are in the form (up . down)
95 (define (beam-dir-majority count total)
96   (dir-compare (car count) (cdr count)))
97
98 (define (beam-dir-mean count total)
99   (dir-compare (car total) (cdr total)))
100
101 (define (beam-dir-median count total)
102   (if (and (> (car count) 0)
103            (> (cdr count) 0))
104       (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
105       (dir-compare (car count) (cdr count))))
106             
107
108
109 ;; [Ross] states that the majority of the notes dictates the
110 ;; direction (and not the mean of "center distance")
111 ;;
112 ;; But is that because it really looks better, or because he wants
113 ;; to provide some real simple hands-on rules?
114 ;;     
115 ;; We have our doubts, so we simply provide all sensible alternatives.
116
117 ;; array index multiplicity, last if index>size
118 ;; beamed stems
119
120
121 ;; TODO
122 ;;  - take #forced stems into account (now done in C++)?
123 ;;  - take staff-position of chord or beam into account
124