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.
136 ;; array index multiplicity, last if index>size
141 ;; - take #forced stems into account (now done in C++)?
142 ;; - take y-position of chord or beam into account
144 ;;;;;;;;;;;;;;;;;;;;;;;
148 ; todo: clean this up a bit: the list is getting rather long.
150 (define basic-beam-properties
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)
164 (flag-width-function . ,default-beam-flag-width-function)
165 (space-function . ,default-beam-space-function)