]> git.donarmstrong.com Git - lilypond.git/blob - scm/basic-properties.scm
release: 1.3.101
[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 (end-of-line-visible d) (if (= d -1) '(#f . #f) '(#t . #t)))
6 (define (spanbar-begin-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
7 (define (all-visible d) '(#f . #f))
8 (define (all-invisible d) '(#t . #t))
9 (define (begin-of-line-invisible d) (if (= d 1) '(#t . #t) '(#f . #f)))
10 (define (end-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
11
12
13 (define mark-visibility end-of-line-invisible)
14
15
16
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 ;                  BEAMS
19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20
21 (define (default-beam-space-function multiplicity)
22   (if (<= multiplicity 3) 0.816 0.844)
23   )
24
25 ;
26 ; width in staff space.
27 ;
28 (define (default-beam-flag-width-function type)
29   (cond
30    ((eq? type 1) 1.98) 
31    ((eq? type 1) 1.65) ;; FIXME: check what this should be and why
32    (else 1.32)
33    ))
34
35
36 ; This is a mess : global namespace pollution. We should wait
37 ;  till guile has proper toplevel environment support.
38
39
40 ;; Beams should be prevented to conflict with the stafflines, 
41 ;; especially at small slopes
42 ;;    ----------------------------------------------------------
43 ;;                                                   ########
44 ;;                                        ########
45 ;;                             ########
46 ;;    --------------########------------------------------------
47 ;;       ########
48 ;;
49 ;;       hang       straddle   sit        inter      hang
50
51 ;; inter seems to be a modern quirk, we don't use that
52
53   
54 ;; Note: quanting period is take as quants.top () - quants[0], 
55 ;; which should be 1 (== 1 interline)
56 (define (mean a b) (* 0.5 (+ a  b)))
57 (define (default-beam-dy-quants beam stafflinethick)
58   (let ((thick (ly-get-elt-property beam 'thickness))
59         )
60     
61     (list 0 (mean thick stafflinethick) (+ thick stafflinethick) 1)
62     ))
63
64 ;; two popular veritcal beam quantings
65 ;; see params.ly: #'beam-vertical-quants
66
67 ; (todo: merge these 2 funcs ? )
68
69 (define (default-beam-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 (list beam-hang))
75          )
76     
77     (if (or (<= multiplicity 1) (>= (abs 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 (define (beam-traditional-y-quants beam multiplicity dy staff-line)
85   (let* ((beam-straddle 0)
86         (thick (ly-get-elt-property beam 'thickness))
87         (beam-sit (/ (+ thick staff-line) 2))
88         (beam-hang (- 1 (/ (- thick staff-line) 2)))
89         (quants '())
90         )
91     (if (>= dy (/ staff-line -2))
92         (set! quants (cons beam-hang quants)))
93     (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
94         (set! quants (cons beam-sit quants)))
95     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
96         (set! quants (cons beam-straddle quants)))
97     ;; period: 1 (interline)
98     (append quants (list (+ 1 (car quants))))))
99
100
101 ;; There are several ways to calculate the direction of a beam
102 ;;
103 ;; * majority: number count of up or down notes
104 ;; * mean    : mean centre distance of all notes
105 ;; * median  : mean centre distance weighted per note
106
107 (define (dir-compare up down)
108   (sign (- up down)))
109
110 ;; arguments are in the form (up . down)
111 (define (beam-dir-majority count total)
112   (dir-compare (car count) (cdr count)))
113
114 (define (beam-dir-mean count total)
115   (dir-compare (car total) (cdr total)))
116
117 (define (beam-dir-median count total)
118   (if (and (> (car count) 0)
119            (> (cdr count) 0))
120       (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
121       (dir-compare (car count) (cdr count))))
122             
123
124
125 ;; [Ross] states that the majority of the notes dictates the
126 ;; direction (and not the mean of "center distance")
127 ;;
128 ;; But is that because it really looks better, or because he wants
129 ;; to provide some real simple hands-on rules?
130 ;;     
131 ;; We have our doubts, so we simply provide all sensible alternatives.
132
133 ;; array index multiplicity, last if index>size
134 ;; beamed stems
135
136
137 ;; TODO
138 ;;  - take #forced stems into account (now done in C++)?
139 ;;  - take y-position of chord or beam into account
140
141 ;
142 ; todo: clean this up a bit: the list is getting rather long.
143
144 (define basic-beam-properties
145   `(
146     (molecule-callback . ,Beam::brew_molecule)
147     (thickness . 0.42) ; in staff-space, should use stafflinethick?
148     (before-line-breaking-callback . ,Beam::before_line_breaking)
149     (after-line-breaking-callback . ,Beam::after_line_breaking)
150     (default-neutral-direction . 1)
151     (dir-function . ,beam-dir-majority)
152     (height-quants .  ,default-beam-dy-quants)
153     (vertical-position-quant-function . ,default-beam-y-quants)
154     (beamed-stem-shorten . (0.5))
155     (outer-stem-length-limit . 0.2)
156     (slope-limit . 0.2)
157     (flag-width-function . ,default-beam-flag-width-function)
158     (space-function . ,default-beam-space-function)
159     (damping . 1)
160     (meta . ,(element-description "Beam" beam-interface))
161     )
162   )
163
164
165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
166 ; Bar lines.
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168
169 ;
170 ; How should a  bar line behave at a break? 
171 ;
172 (define (default-break-barline glyph dir)
173    (let ((result (assoc glyph 
174                         '((":|:" . (":|" . "|:"))
175                           ("|" . ("|" . ""))
176                           ("|s" . (nil . "|"))
177                           ("|:" . ("|" . "|:"))
178                           ("|." . ("|." . nil))
179                           (".|" . (nil . ".|"))
180                           (":|" . (":|" . nil))
181                           ("||" . ("||" . nil))
182                           (".|." . (".|." . nil))
183                           ("empty" . ("nil" . nil))
184                           ("brace" . (nil . "brace"))
185                           ("bracket" . (nil . "bracket"))  
186                           )
187                         )))
188
189      (if (equal? result #f)
190          (ly-warn (string-append "Unknown bar glyph: `" glyph "'"))
191          (index-cell (cdr result) dir))
192      )
193    )
194      
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 ;  Prefatory matter: break align item.
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
198 ;; Spacing constants 
199 ;;
200 ;; rules for this spacing are much more complicated than this. 
201 ;; See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147
202 ;;
203
204 ;; (Measured in staff space)
205 (define default-break-align-space-alist
206  '(
207    ((Staff_bar Custos) . (minimum-space 2.0))
208    ((Custos begin-of-note) . (minimum-space 0.0))
209    ((none Instrument_name) . (extra-space 1.0))
210    ((Instrument_name Left_edge_item) . (extra-space 1.0))
211    ((Left_edge_item Clef_item) . (extra-space 1.0))
212    ((Left_edge_item Key_item) . (extra-space 0.0))   
213    ((Left_edge_item begin-of-note) . (extra-space 1.0))
214    ((none Left_edge_item) . (extra-space 0.0))
215    ((Left_edge_item Staff_bar) . (extra-space 0.0))
216 ;   ((none Left_edge_item) . (extra-space -15.0))
217 ;   ((none Left_edge_item) . (extra-space -15.0))
218    ((none Clef_item) . (minimum-space 1.0))
219    ((none Staff_bar) . (minimum-space 0.0))
220    ((none Clef_item) . (minimum-space 1.0))
221    ((none Key_item) . (minimum-space 0.5))
222    ((none Time_signature) . (extra-space 0.0))
223    ((none begin-of-note) . (minimum-space 1.5))
224    ((Clef_item Key_item) . (minimum-space 4.0))
225    ((Key_item Time_signature) . (extra-space 1.0))
226    ((Clef_item  Time_signature) . (minimum-space 3.5))
227    ((Staff_bar Clef_item) .   (minimum-space 1.0))
228    ((Clef_item  Staff_bar) .  (minimum-space 3.7))
229    ((Time_signature Staff_bar) .  (minimum-space 2.0))
230    ((Key_item  Staff_bar) .  (extra-space 1.0))
231    ((Staff_bar Time_signature) . (minimum-space 1.5)) 
232    ((Time_signature begin-of-note) . (extra-space 2.0)) 
233    ((Key_item begin-of-note) . (extra-space 2.5))
234    ((Staff_bar begin-of-note) . (extra-space 1.0))
235    ((Clef_item begin-of-note) . (minimum-space 5.0))
236    ((none Breathing_sign) . (minimum-space 0.0))
237    ((Breathing_sign Key_item) . (minimum-space 1.5))
238    ((Breathing_sign begin-of-note) . (minimum-space 1.0))
239    ((Breathing_sign Staff_bar) . (minimum-space 1.5))
240    ((Breathing_sign Clef_item) . (minimum-space 2.0))
241    )
242 )