]> git.donarmstrong.com Git - lilypond.git/blob - scm/paper.scm
release: 1.3.16
[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 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 (define beam-normal-dy-quants
31   (list 0 (/ (+ beam-thickness staff-line) 2) (+ beam-thickness staff-line) 1))
32
33 ;; two popular veritcal beam quantings
34 ;; see params.ly: #'beam-vertical-quants
35 (define (beam-normal-y-quants multiplicity dy)
36   (let ((quants (list beam-hang 1)))
37     (if (or (<= multiplicity 1) (>= (abs dy) (/ staff-line 2)))
38         (set! quants (cons beam-sit quants)))
39     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
40         (set! quants (cons beam-straddle quants)))
41     quants))
42
43 (define (beam-traditional-y-quants multiplicity dy)
44   (let ((quants '(1)))
45     (if (>= dy (/ staff-line -2))
46         (set! quants (cons beam-hang quants)))
47     (if (and (<= multiplicity 1) (<= dy (/ staff-line 2)))
48         (set! quants (cons beam-sit quants)))
49     (if (or (<= multiplicity 2) (>= (abs dy) (/ staff-line 2)))
50         (set! quants (cons beam-straddle quants)))
51     quants))
52
53
54 ;; There are several ways to calculate the direction of a beam
55 ;;
56 ;; * majority: number count of up or down notes
57 ;; * mean    : mean centre distance of all notes
58 ;; * median  : mean centre distance weighted per note
59
60 (define (dir-compare up down)
61   (if (= up down)
62       0
63       (if (> up down)
64           1
65           -1)))
66
67 ;; (up . down)
68 (define (beam-dir-majority count total)
69   (dir-compare (car count) (cdr count)))
70
71 (define (beam-dir-mean count total)
72   (dir-compare (car total) (cdr total)))
73
74 (define (beam-dir-median count total)
75   (if (and (> (car count) 0)
76            (> (cdr count) 0))
77       (dir-compare (/ (car total) (car count)) (/ (cdr total) (cdr count)))
78       (dir-compare (car count) (cdr count))))
79             
80
81 ;;; Default variables and settings
82
83 (define beam-height-quants beam-normal-dy-quants)
84 (define beam-vertical-position-quants beam-normal-y-quants)
85
86
87 ;; [Ross] states that the majority of the notes dictates the
88 ;; direction (and not the mean of "center distance")
89 ;;
90 ;; But is that because it really looks better, or because he wants
91 ;; to provide some real simple hands-on rules?
92 ;;     
93 ;; We have our doubts, so we simply provide all sensible alternatives.
94 (define beam-dir-algorithm beam-dir-majority)
95
96
97 ;; array index flag-2 (what a name!!), last if index>size
98 ;; unbeamed stems
99 (define stem-length '(3.5 3.5 3.5 4.5 5.0))
100 (define grace-length-factor 0.8)
101 (define grace-stem-length
102   (map (lambda (x) (* grace-length-factor x)) stem-length))
103
104 ;; array index multiplicity, last if index>size
105 ;; beamed stems
106 (define beamed-stem-shorten '(0.5))
107 (define beamed-stem-length '(0.0 2.5 2.0 1.5))
108 (define grace-beamed-stem-length '(0.0 2.5 2.0 1.5))
109 (define beamed-stem-minimum-length '(0.0 1.5 1.25 1.0))
110 (define grace-beamed-stem-minimum-length
111   (map (lambda (x) (* grace-length-factor x)) beamed-stem-minimum-length))
112
113 ;;  Stems in unnatural (forced) direction should be shortened,
114 ;;  according to [Roush & Gourlay].  Their suggestion to knock off
115 ;;  a whole staffspace seems a bit drastical: we'll do half.
116
117 ;; TODO
118 ;;  - take #forced stems into account (now done in C++)?
119 ;;  - take y-position of chord or beam into account
120
121 (define stem-shorten '(0.5))
122 (define grace-stem-shorten '(0.0))