2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 (define (default-beam-space-function multiplicity)
7 (if (<= multiplicity 3) 0.816 0.844)
11 ; width in staff space.
13 (define (default-beam-flag-width-function type)
16 ((eq? type 1) 1.65) ;; FIXME: check what this should be and why
21 ; This is a mess : global namespace pollution. We should wait
22 ; till guile has proper toplevel environment support.
25 ;; Beams should be prevented to conflict with the stafflines,
26 ;; especially at small slopes
27 ;; ----------------------------------------------------------
31 ;; --------------########------------------------------------
34 ;; hang straddle sit inter hang
36 ;; inter seems to be a modern quirk, we don't use that
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))
46 (list 0 (mean thick stafflinethick) (+ thick stafflinethick) 1)
49 ;; two popular veritcal beam quantings
50 ;; see params.ly: #'beam-vertical-quants
52 ; (todo: merge these 2 funcs ? )
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))
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))))))
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)))
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))))))
86 ;; There are several ways to calculate the direction of a beam
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
92 (define (dir-compare up down)
95 ;; arguments are in the form (up . down)
96 (define (beam-dir-majority count total)
97 (dir-compare (car count) (cdr count)))
99 (define (beam-dir-mean count total)
100 (dir-compare (car total) (cdr total)))
102 (define (beam-dir-median count total)
103 (if (and (> (car count) 0)
105 (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
106 (dir-compare (car count) (cdr count))))
110 ;; [Ross] states that the majority of the notes dictates the
111 ;; direction (and not the mean of "center distance")
113 ;; But is that because it really looks better, or because he wants
114 ;; to provide some real simple hands-on rules?
116 ;; We have our doubts, so we simply provide all sensible alternatives.
118 ;; array index multiplicity, last if index>size
123 ;; - take #forced stems into account (now done in C++)?
124 ;; - take y-position of chord or beam into account
127 ; todo: clean this up a bit: the list is getting rather long.
129 (define basic-beam-properties
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)
142 (flag-width-function . ,default-beam-flag-width-function)
143 (space-function . ,default-beam-space-function)
145 (meta . ,(element-description "Beam" beam-interface))