1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5 (define (default-beam-space-function multiplicity)
6 (if (<= multiplicity 3) 0.816 0.844)
10 ; width in staff space.
12 (define (default-beam-flag-width-function type)
15 ((eq? type 1) 1.65) ;; FIXME: check what this should be and why
20 ; This is a mess : global namespace pollution. We should wait
21 ; till guile has proper toplevel environment support.
24 ;; Beams should be prevented to conflict with the stafflines,
25 ;; especially at small slopes
26 ;; ----------------------------------------------------------
30 ;; --------------########------------------------------------
33 ;; hang straddle sit inter hang
35 ;; inter seems to be a modern quirk, we don't use that
38 ;; Note: quanting period is take as quants.top () - quants[0],
39 ;; which should be 1 (== 1 interline)
40 (define (mean a b) (* 0.5 (+ a b)))
41 (define (default-beam-dy-quants beam stafflinethick)
42 (let ((thick (ly-get-grob-property beam 'thickness)))
43 ;; amazing. this is wrong:
44 (list 0 (mean thick stafflinethick) (+ thick stafflinethick) 1)
45 ;; it should be this: but the visual effect is even uglier,
46 ;; because dy quants are not synchronised with left y
47 ;; (list 0 (/ (- thick stafflinethick) 2) (- thick stafflinethick) 1)
50 ;; two popular veritcal beam quantings
51 ;; see params.ly: #'beam-vertical-quants
53 ; (todo: merge these 2 funcs ? )
55 (define (default-beam-y-quants beam multiplicity dy staff-line)
56 (let* ((beam-straddle 0)
57 (thick (ly-get-grob-property beam 'thickness))
58 (beam-sit (/ (- thick staff-line) 2))
59 (beam-hang (- 1 (/ (- thick staff-line) 2)))
60 (quants (list beam-hang))
63 (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2)))
64 (set! quants (cons beam-sit quants)))
65 (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
66 (set! quants (cons beam-straddle quants)))
67 ;; period: 1 (interline)
68 (append quants (list (+ 1 (car quants))))))
70 (define (beam-traditional-y-quants beam multiplicity dy staff-line)
71 (let* ((beam-straddle 0)
72 (thick (ly-get-grob-property beam 'thickness))
73 (beam-sit (/ (- thick staff-line) 2))
74 (beam-hang (- 1 (/ (- thick staff-line) 2)))
77 (if (>= dy (/ staff-line -2))
78 (set! quants (cons beam-hang quants)))
79 (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
80 (set! quants (cons beam-sit quants)))
81 (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
82 (set! quants (cons beam-straddle quants)))
83 ;; period: 1 (interline)
84 (append quants (list (+ 1 (car quants))))))
87 ;; There are several ways to calculate the direction of a beam
89 ;; * majority: number count of up or down notes
90 ;; * mean : mean centre distance of all notes
91 ;; * median : mean centre distance weighted per note
93 (define (dir-compare up down)
96 ;; arguments are in the form (up . down)
97 (define (beam-dir-majority count total)
98 (dir-compare (car count) (cdr count)))
100 (beam-dir-majority '(0 . 0) '(0 . 0))
102 (define (beam-dir-mean count total)
103 (dir-compare (car total) (cdr total)))
105 (define (beam-dir-median count total)
106 (if (and (> (car count) 0)
108 (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
109 (dir-compare (car count) (cdr count))))
113 ;; [Ross] states that the majority of the notes dictates the
114 ;; direction (and not the mean of "center distance")
116 ;; But is that because it really looks better, or because he wants
117 ;; to provide some real simple hands-on rules?
119 ;; We have our doubts, so we simply provide all sensible alternatives.
121 ;; array index multiplicity, last if index>size
126 ;; - take #forced stems into account (now done in C++)?
127 ;; - take staff-position of chord or beam into account