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