]> git.donarmstrong.com Git - lilypond.git/blob - lily/bezier-bow.cc
* lily/include/slur-scoring.hh (struct Slur_score_state): new file
[lilypond.git] / lily / bezier-bow.cc
1 /*
2   bezier.cc -- implement Bezier and Bezier_bow
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <math.h>
10
11 #include "misc.hh"
12 #include "bezier.hh"
13
14
15 static Real
16 F0_1 (Real x)
17 {
18   return 2 / M_PI * atan (M_PI * x / 2);
19 }
20
21 Real
22 slur_height (Real width, Real h_inf, Real r_0)
23 {
24   return F0_1 (width * r_0 / h_inf) * h_inf;
25 }
26
27   /*
28
29
30   ^              x                    x                  
31   |
32 height   <indent>
33   |
34   v      x                                    x
35
36   
37   
38   For small w, the height should be proportional to w, for w ->
39   infinity, the height should rise to a limit asymptotically.
40
41   Hence we take F (x) such that
42   F (0) = 0 , F' (0) = 1, and F (infty) = 1
43
44   and use
45
46   h = h_infinity * F (x * r_0 / h_infinity)
47
48   
49   Examples:
50
51   * F (x) = 2/pi * atan (pi x/2)
52
53   * F (x) = 1/alpha * x^alpha / (1 + x^alpha)
54
55   * (etc.)
56
57   [with the 2nd recipe you can determine how quickly the conversion from
58   `small' slurs to `big' slurs occurs.]
59
60   Although this might seem cand_idates to SCM-ify, it is not all clear
61   which parameters (ie. h_inf, r_0, F (.)) should be candidates for
62   this.  At present h_inf and r_0 come from paper settings, but we did
63   no experiments for determining the best combinations of F, h_inf and
64   r_0.
65
66
67   The indent is proportional to the height of the slur for small
68   slurs.  For large slurs, this gives a certain hookiness at the end,
69   so we increase the indent.
70
71   indent = G(w)
72
73   w -> 0,  G(w) -> .33 w
74
75   
76   (due to derivative constraints, we cannot have indent > len/3)
77
78   w -> inf, G(w) -> 2*h_inf
79
80   i.e.
81
82
83   G(0) = 0 , G'(0) 1/3, G(infty) = 2h_inf
84
85   solve from
86
87    G(w) = r  + p/(w+q)
88
89   yields
90
91    G(w) = 2 h_inf - max_fraction * q^2/ (w + q)
92
93   with q = 2 h_inf 
94   
95   
96   */
97
98 void
99 get_slur_indent_height (Real *indent, Real *height,
100                         Real width, Real h_inf, Real r_0)
101 {
102   Real max_fraction = 1.0 / 3.1;
103   *height =  slur_height (width, h_inf, r_0);
104
105   Real q = 2 * h_inf / max_fraction; 
106   *indent =
107     2 *h_inf - sqr (q) * max_fraction / (width + q);
108 }
109
110 Bezier
111 slur_shape (Real width, Real h_inf, Real r_0)
112 {
113   Real indent;
114   Real height;
115   
116   get_slur_indent_height (&indent, &height,
117                           width,  h_inf,  r_0);
118
119   Bezier curve;
120   curve.control_[0] = Offset (0, 0);
121   curve.control_[1] = Offset (indent, height);
122   curve.control_[2] = Offset (width - indent, height);
123   curve.control_[3] = Offset (width, 0);
124   return curve;
125 }