1 ;;; paper.scm -- scm paper variables and functions
3 ;;; source file of the GNU LilyPond music typesetter
5 ;;; (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;; All dimensions are measured in staff-spaces
11 ;; Beams should be prevented to conflict with the stafflines,
12 ;; especially at small slopes
13 ;; ----------------------------------------------------------
17 ;; --------------########------------------------------------
20 ;; hang straddle sit inter hang
22 ;; inter seems to be a modern quirk, we don't use that
24 (define staff-line 0.10)
25 (define beam-thickness (* 0.52 (- 1 staff-line)))
26 (define beam-straddle 0)
27 (define beam-sit (/ (+ beam-thickness staff-line) 2))
28 (define beam-hang (- 1 (/ (- beam-thickness staff-line) 2)))
30 ;; Note: quanting period is take as quants.top () - quants[0],
31 ;; which should be 1 (== 1 interline)
33 (define beam-normal-dy-quants
34 (list 0 (/ (+ beam-thickness staff-line) 2) (+ beam-thickness staff-line) 1))
36 ;; two popular veritcal beam quantings
37 ;; see params.ly: #'beam-vertical-quants
38 (define (beam-normal-y-quants multiplicity dy)
39 (let ((quants (list beam-hang)))
40 (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2)))
41 (set! quants (cons beam-sit quants)))
42 (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
43 (set! quants (cons beam-straddle quants)))
44 ;; period: 1 (interline)
45 (append quants (list (+ 1 (car quants))))))
47 (define (beam-traditional-y-quants multiplicity dy)
49 (if (>= dy (/ staff-line -2))
50 (set! quants (cons beam-hang quants)))
51 (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
52 (set! quants (cons beam-sit quants)))
53 (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
54 (set! quants (cons beam-straddle quants)))
55 ;; period: 1 (interline)
56 (append quants (list (+ 1 (car quants))))))
59 ;; There are several ways to calculate the direction of a beam
61 ;; * majority: number count of up or down notes
62 ;; * mean : mean centre distance of all notes
63 ;; * median : mean centre distance weighted per note
65 (define (dir-compare up down)
73 (define (beam-dir-majority count total)
74 (dir-compare (car count) (cdr count)))
76 (define (beam-dir-mean count total)
77 (dir-compare (car total) (cdr total)))
79 (define (beam-dir-median count total)
80 (if (and (> (car count) 0)
82 (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
83 (dir-compare (car count) (cdr count))))
86 ;;; Default variables and settings
88 (define beam-height-quants beam-normal-dy-quants)
89 (define beam-vertical-position-quants beam-normal-y-quants)
92 ;; [Ross] states that the majority of the notes dictates the
93 ;; direction (and not the mean of "center distance")
95 ;; But is that because it really looks better, or because he wants
96 ;; to provide some real simple hands-on rules?
98 ;; We have our doubts, so we simply provide all sensible alternatives.
99 (define beam-dir-algorithm beam-dir-majority)
102 ;; array index flag-2 (what a name!!), last if index>size
104 (define stem-length '(3.5 3.5 3.5 4.5 5.0))
105 (define grace-length-factor 0.8)
106 (define grace-stem-length
107 (map (lambda (x) (* grace-length-factor x)) stem-length))
109 ;; array index multiplicity, last if index>size
111 (define beamed-stem-shorten '(0.5))
112 (define beamed-stem-length '(0.0 2.5 2.0 1.5))
113 (define grace-beamed-stem-length '(0.0 2.5 2.0 1.5))
114 (define beamed-stem-minimum-length '(0.0 1.5 1.25 1.0))
115 (define grace-beamed-stem-minimum-length
116 (map (lambda (x) (* grace-length-factor x)) beamed-stem-minimum-length))
118 ;; Stems in unnatural (forced) direction should be shortened,
119 ;; according to [Roush & Gourlay]. Their suggestion to knock off
120 ;; a whole staffspace seems a bit drastical: we'll do half.
123 ;; - take #forced stems into account (now done in C++)?
124 ;; - take y-position of chord or beam into account
126 (define stem-shorten '(0.5))
127 (define grace-stem-shorten '(0.0))
130 (define pi (* 2 (acos 0)))
132 (define (slur-default-height h-inf r-0 b)
133 (let ((alpha (/ (* 2.0 h-inf) pi))
134 (beta (/ (* pi r-0) (* 2.0 h-inf))))
135 (* alpha (atan (* beta b)))))