1 ; Definition of backend properties (aka. element properties).
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)))
12 (define mark-visibility end-of-line-invisible)
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20 (define (default-beam-space-function multiplicity)
21 (if (<= multiplicity 3) 0.816 0.844)
25 ; width in staff space.
27 (define (default-beam-flag-width-function type)
35 ; This is a mess : global namespace pollution. We should wait
36 ; till guile has proper toplevel environment support.
39 ;; Beams should be prevented to conflict with the stafflines,
40 ;; especially at small slopes
41 ;; ----------------------------------------------------------
45 ;; --------------########------------------------------------
48 ;; hang straddle sit inter hang
50 ;; inter seems to be a modern quirk, we don't use that
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))
60 (list 0 (mean thick stafflinethick) (+ thick stafflinethick) 1)
63 ;; two popular veritcal beam quantings
64 ;; see params.ly: #'beam-vertical-quants
66 ; (todo: merge these 2 funcs ? )
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))
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))))))
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)))
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))))))
100 ;; There are several ways to calculate the direction of a beam
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
106 (define (dir-compare up down)
109 ;; arguments are in the form (up . down)
110 (define (beam-dir-majority count total)
111 (dir-compare (car count) (cdr count)))
113 (define (beam-dir-mean count total)
114 (dir-compare (car total) (cdr total)))
116 (define (beam-dir-median count total)
117 (if (and (> (car count) 0)
119 (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
120 (dir-compare (car count) (cdr count))))
124 ;; [Ross] states that the majority of the notes dictates the
125 ;; direction (and not the mean of "center distance")
127 ;; But is that because it really looks better, or because he wants
128 ;; to provide some real simple hands-on rules?
130 ;; We have our doubts, so we simply provide all sensible alternatives.
132 ;; array index multiplicity, last if index>size
137 ;; - take #forced stems into account (now done in C++)?
138 ;; - take y-position of chord or beam into account
141 ; todo: clean this up a bit: the list is getting rather long.
143 (define basic-beam-properties
145 (interfaces . (beam-interface))
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)
157 (flag-width-function . ,default-beam-flag-width-function)
158 (space-function . ,default-beam-space-function)
165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170 ; How should a bar line behave at a break?
172 (define (default-break-barline glyph dir)
173 (let ((result (assoc glyph
174 '((":|:" . (":|" . "|:"))
177 ("|:" . ("|" . "|:"))
178 ("|." . ("|." . nil))
179 (".|" . (nil . ".|"))
180 (":|" . (":|" . nil))
181 ("||" . ("||" . nil))
182 (".|." . (".|." . nil))
183 ("brace" . (nil . "brace"))
184 ("bracket" . (nil . "bracket"))
188 (if (equal? result #f)
189 (ly-warn (string-append "Unknown bar glyph: `" glyph "'"))
190 (index-cell (cdr result) dir))
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ; Prefatory matter: break align item.
196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
199 ;; rules for this spacing are much more complicated than this.
200 ;; See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147
203 ;; (Measured in staff space)
204 (define default-break-align-space-alist
206 ((none Instrument_name) . (extra-space 1.0))
207 ((Instrument_name Left_edge_item) . (extra-space 1.0))
208 ((Left_edge_item Clef_item) . (extra-space 1.0))
209 ((Left_edge_item Key_item) . (extra-space 0.0))
210 ((Left_edge_item begin-of-note) . (extra-space 1.0))
211 ((none Left_edge_item) . (extra-space 0.0))
212 ((Left_edge_item Staff_bar) . (extra-space 0.0))
213 ; ((none Left_edge_item) . (extra-space -15.0))
214 ; ((none Left_edge_item) . (extra-space -15.0))
215 ((none Clef_item) . (minimum-space 1.0))
216 ((none Staff_bar) . (minimum-space 0.0))
217 ((none Clef_item) . (minimum-space 1.0))
218 ((none Key_item) . (minimum-space 0.5))
219 ((none Time_signature) . (extra-space 0.0))
220 ((none begin-of-note) . (minimum-space 1.5))
221 ((Clef_item Key_item) . (minimum-space 4.0))
222 ((Key_item Time_signature) . (extra-space 1.0))
223 ((Clef_item Time_signature) . (minimum-space 3.5))
224 ((Staff_bar Clef_item) . (minimum-space 1.0))
225 ((Clef_item Staff_bar) . (minimum-space 3.7))
226 ((Time_signature Staff_bar) . (minimum-space 2.0))
227 ((Key_item Staff_bar) . (extra-space 1.0))
228 ((Staff_bar Time_signature) . (minimum-space 1.5))
229 ((Time_signature begin-of-note) . (extra-space 2.0))
230 ((Key_item begin-of-note) . (extra-space 2.5))
231 ((Staff_bar begin-of-note) . (extra-space 1.0))
232 ((Clef_item begin-of-note) . (minimum-space 5.0))
233 ((none Breathing_sign) . (minimum-space 0.0))
234 ((Breathing_sign Key_item) . (minimum-space 1.5))
235 ((Breathing_sign begin-of-note) . (minimum-space 1.0))
236 ((Breathing_sign Staff_bar) . (minimum-space 1.5))
237 ((Breathing_sign Clef_item) . (minimum-space 2.0))