]> git.donarmstrong.com Git - lilypond.git/blob - scm/beam.scm
patch::: 1.3.103.jcn3
[lilypond.git] / scm / beam.scm
1
2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;                  BEAMS
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5
6 (define (default-beam-space-function multiplicity)
7   (if (<= multiplicity 3) 0.816 0.844)
8   )
9
10 ;
11 ; width in staff space.
12 ;
13 (define (default-beam-flag-width-function type)
14   (cond
15    ((eq? type 1) 1.98) 
16    ((eq? type 1) 1.65) ;; FIXME: check what this should be and why
17    (else 1.32)
18    ))
19
20
21 ; This is a mess : global namespace pollution. We should wait
22 ;  till guile has proper toplevel environment support.
23
24
25 ;; Beams should be prevented to conflict with the stafflines, 
26 ;; especially at small slopes
27 ;;    ----------------------------------------------------------
28 ;;                                                   ########
29 ;;                                        ########
30 ;;                             ########
31 ;;    --------------########------------------------------------
32 ;;       ########
33 ;;
34 ;;       hang       straddle   sit        inter      hang
35
36 ;; inter seems to be a modern quirk, we don't use that
37
38   
39 ;; Note: quanting period is take as quants.top () - quants[0], 
40 ;; which should be 1 (== 1 interline)
41 (define (mean a b) (* 0.5 (+ a  b)))
42 (define (default-beam-dy-quants beam stafflinethick)
43   (let ((thick (ly-get-elt-property beam 'thickness))
44         )
45     
46     (list 0 (mean thick stafflinethick) (+ thick stafflinethick) 1)
47     ))
48
49 ;; two popular veritcal beam quantings
50 ;; see params.ly: #'beam-vertical-quants
51
52 ; (todo: merge these 2 funcs ? )
53
54 (define (default-beam-y-quants beam multiplicity dy staff-line)
55   (let* ((beam-straddle 0)
56          (thick (ly-get-elt-property beam 'thickness))
57          (beam-sit (/ (+ thick staff-line) 2))
58          (beam-hang (- 1 (/ (- thick staff-line) 2)))
59          (quants (list beam-hang))
60          )
61     
62     (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2)))
63         (set! quants (cons beam-sit quants)))
64     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
65         (set! quants (cons beam-straddle quants)))
66     ;; period: 1 (interline)
67     (append quants (list (+ 1 (car quants))))))
68
69 (define (beam-traditional-y-quants beam multiplicity dy staff-line)
70   (let* ((beam-straddle 0)
71         (thick (ly-get-elt-property beam 'thickness))
72         (beam-sit (/ (+ thick staff-line) 2))
73         (beam-hang (- 1 (/ (- thick staff-line) 2)))
74         (quants '())
75         )
76     (if (>= dy (/ staff-line -2))
77         (set! quants (cons beam-hang quants)))
78     (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
79         (set! quants (cons beam-sit quants)))
80     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
81         (set! quants (cons beam-straddle quants)))
82     ;; period: 1 (interline)
83     (append quants (list (+ 1 (car quants))))))
84
85
86 ;; There are several ways to calculate the direction of a beam
87 ;;
88 ;; * majority: number count of up or down notes
89 ;; * mean    : mean centre distance of all notes
90 ;; * median  : mean centre distance weighted per note
91
92 (define (dir-compare up down)
93   (sign (- up down)))
94
95 ;; arguments are in the form (up . down)
96 (define (beam-dir-majority count total)
97   (dir-compare (car count) (cdr count)))
98
99 (define (beam-dir-mean count total)
100   (dir-compare (car total) (cdr total)))
101
102 (define (beam-dir-median count total)
103   (if (and (> (car count) 0)
104            (> (cdr count) 0))
105       (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
106       (dir-compare (car count) (cdr count))))
107             
108
109
110 ;; [Ross] states that the majority of the notes dictates the
111 ;; direction (and not the mean of "center distance")
112 ;;
113 ;; But is that because it really looks better, or because he wants
114 ;; to provide some real simple hands-on rules?
115 ;;     
116 ;; We have our doubts, so we simply provide all sensible alternatives.
117
118 ;; array index multiplicity, last if index>size
119 ;; beamed stems
120
121
122 ;; TODO
123 ;;  - take #forced stems into account (now done in C++)?
124 ;;  - take y-position of chord or beam into account
125
126 ;
127 ; todo: clean this up a bit: the list is getting rather long.
128
129 (define basic-beam-properties
130   `(
131     (molecule-callback . ,Beam::brew_molecule)
132     (thickness . 0.42) ; in staff-space, should use stafflinethick?
133     (before-line-breaking-callback . ,Beam::before_line_breaking)
134     (after-line-breaking-callback . ,Beam::after_line_breaking)
135     (default-neutral-direction . 1)
136     (dir-function . ,beam-dir-majority)
137     (height-quants .  ,default-beam-dy-quants)
138     (vertical-position-quant-function . ,default-beam-y-quants)
139     (beamed-stem-shorten . (0.5))
140     (outer-stem-length-limit . 0.2)
141     (slope-limit . 0.2)
142     (flag-width-function . ,default-beam-flag-width-function)
143     (space-function . ,default-beam-space-function)
144     (damping . 1)
145     (meta . ,(element-description "Beam" beam-interface))
146     )
147   )
148