~ubuntu-branches/ubuntu/precise/lilypond/precise

« back to all changes in this revision

Viewing changes to lily/bezier-bow.cc

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Bushnell, BSG
  • Date: 2006-12-19 10:18:12 UTC
  • mfrom: (3.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061219101812-7awtjkp0i393wxty
Tags: 2.8.7-3
scripts/midi2ly.py: When setting DATADIR, find Lilypond python files
in the @TOPLEVEL_VERSION@ directory, not 'current'.  Patch thanks to
Chris Lamb (chris@chris-lamb.co.uk).  (Closes: #400550)

Show diffs side-by-side

added added

removed removed

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