2 ;;;; beam.scm -- Beam scheme stuff
4 ;;;; source file of the GNU LilyPond music typesetter
6 ;;;; (c) 2000--2001 Jan Nieuwenhuizen <janneke@gnu.org>
9 (define (default-beam-space-function multiplicity)
10 (if (<= multiplicity 3) 0.816 0.844)
14 ;; width in staff space.
16 (define (default-beam-flag-width-function type)
19 ((eq? type 1) 1.65) ;; FIXME: check what this should be and why
24 ;; This is a mess : global namespace pollution. We should wait
25 ;; till guile has proper toplevel environment support.
28 ;; Beams should be prevented to conflict with the stafflines,
29 ;; especially at small slopes
30 ;; ----------------------------------------------------------
34 ;; --------------########------------------------------------
37 ;; hang straddle sit inter hang
39 ;; inter seems to be a modern quirk, we don't use that
41 ;; two popular veritcal beam quantings
42 ;; see params.ly: #'beam-vertical-quants
45 (define (default-beam-pos-quants beam multiplicity dy staff-line)
46 (let* ((beam-straddle 0)
47 (thick (ly-get-grob-property beam 'thickness))
48 (beam-sit (/ (- thick staff-line) 2))
49 (beam-hang (- 1 (/ (- thick staff-line) 2)))
50 (quants (list beam-hang))
53 (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2)))
54 (set! quants (cons beam-sit quants)))
55 (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
56 (set! quants (cons beam-straddle quants)))
57 ;; period: 1 (staff-space)
58 (append quants (list (+ 1 (car quants))))))
60 (define (beam-traditional-pos-quants beam multiplicity dy staff-line)
61 (let* ((beam-straddle 0)
62 (thick (ly-get-grob-property beam 'thickness))
63 (beam-sit (/ (- thick staff-line) 2))
64 (beam-hang (- 1 (/ (- thick staff-line) 2)))
67 (if (>= dy (/ staff-line -2))
68 (set! quants (cons beam-hang quants)))
69 (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
70 (set! quants (cons beam-sit quants)))
71 (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
72 (set! quants (cons beam-straddle quants)))
73 ;; period: 1 (staff-space)
74 (append quants (list (+ 1 (car quants))))))
77 ;; There are several ways to calculate the direction of a beam
79 ;; * majority: number count of up or down notes
80 ;; * mean : mean centre distance of all notes
81 ;; * median : mean centre distance weighted per note
83 (define (dir-compare up down)
86 ;; arguments are in the form (up . down)
87 (define (beam-dir-majority count total)
88 (dir-compare (car count) (cdr count)))
90 (beam-dir-majority '(0 . 0) '(0 . 0))
92 (define (beam-dir-mean count total)
93 (dir-compare (car total) (cdr total)))
95 (define (beam-dir-median count total)
96 (if (and (> (car count) 0)
98 (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
99 (dir-compare (car count) (cdr count))))
103 ;; [Ross] states that the majority of the notes dictates the
104 ;; direction (and not the mean of "center distance")
106 ;; But is that because it really looks better, or because he wants
107 ;; to provide some real simple hands-on rules?
109 ;; We have our doubts, so we simply provide all sensible alternatives.
111 ;; array index multiplicity, last if index>size
116 ;; - take #forced stems into account (now done in C++)?
117 ;; - take staff-position of chord or beam into account