]> git.donarmstrong.com Git - lilypond.git/blob - scm/paper.scm
release: 1.3.29
[lilypond.git] / scm / paper.scm
1 ;;; paper.scm -- scm paper variables and functions
2 ;;;
3 ;;;  source file of the GNU LilyPond music typesetter
4 ;;; 
5 ;;; (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
6
7 ;;; All dimensions are measured in staff-spaces
8
9
10
11 ;; Beams should be prevented to conflict with the stafflines, 
12 ;; especially at small slopes
13 ;;    ----------------------------------------------------------
14 ;;                                                   ########
15 ;;                                        ########
16 ;;                             ########
17 ;;    --------------########------------------------------------
18 ;;       ########
19 ;;
20 ;;       hang       straddle   sit        inter      hang
21
22 ;; inter seems to be a modern quirk, we don't use that
23
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)))
29
30 ;; Note: quanting period is take as quants.top () - quants[0], 
31 ;; which should be 1 (== 1 interline)
32
33 (define beam-normal-dy-quants
34   (list 0 (/ (+ beam-thickness staff-line) 2) (+ beam-thickness staff-line) 1))
35
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))))))
46
47 (define (beam-traditional-y-quants multiplicity dy)
48   (let ((quants '()))
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))))))
57
58
59 ;; There are several ways to calculate the direction of a beam
60 ;;
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
64
65 (define (dir-compare up down)
66   (if (= up down)
67       0
68       (if (> up down)
69           1
70           -1)))
71
72 ;; (up . down)
73 (define (beam-dir-majority count total)
74   (dir-compare (car count) (cdr count)))
75
76 (define (beam-dir-mean count total)
77   (dir-compare (car total) (cdr total)))
78
79 (define (beam-dir-median count total)
80   (if (and (> (car count) 0)
81            (> (cdr count) 0))
82       (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
83       (dir-compare (car count) (cdr count))))
84             
85
86 ;;; Default variables and settings
87
88 (define beam-height-quants beam-normal-dy-quants)
89 (define beam-vertical-position-quants beam-normal-y-quants)
90
91
92 ;; [Ross] states that the majority of the notes dictates the
93 ;; direction (and not the mean of "center distance")
94 ;;
95 ;; But is that because it really looks better, or because he wants
96 ;; to provide some real simple hands-on rules?
97 ;;     
98 ;; We have our doubts, so we simply provide all sensible alternatives.
99 (define beam-dir-algorithm beam-dir-majority)
100
101
102 ;; array index flag-2 (what a name!!), last if index>size
103 ;; unbeamed stems
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))
108
109 ;; array index multiplicity, last if index>size
110 ;; beamed stems
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))
117
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.
121
122 ;; TODO
123 ;;  - take #forced stems into account (now done in C++)?
124 ;;  - take y-position of chord or beam into account
125
126 (define stem-shorten '(0.5))
127 (define grace-stem-shorten '(0.0))
128
129 ;; urg
130 (define pi (* 2 (acos 0)))
131
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)))))
136