]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-helper.cc
132e7c303cb7494baa50e0ebb77c0642056c8a98
[lilypond.git] / lily / tie-helper.cc
1 /*
2   tie-helper.cc -- implement Tie_configuration, Tie_details
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include <math.h>
11
12 #include "tie.hh"
13 #include "bezier.hh"
14 #include "grob.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "warn.hh"
17
18 int
19 Tie_configuration::compare (Tie_configuration const &a,
20                             Tie_configuration const &b)
21 {
22   if (a.position_ - b.position_)
23     return sign (a.position_ - b.position_);
24   return sign (a.dir_ - b.dir_);
25 }
26                             
27
28 Tie_configuration::Tie_configuration ()
29 {
30   dir_ = CENTER;
31   position_ = 0;
32   delta_y_ = 0.0;
33 }
34
35
36 void
37 Tie_configuration::center_tie_vertically (Tie_details const &details)
38 {
39   Bezier b = get_bezier (details);
40   Offset middle = b.curve_point (0.5);
41   Offset edge = b.curve_point (0.0);
42
43   Real center = (edge[Y_AXIS] + middle[Y_AXIS])/2.0;
44
45   delta_y_ = - dir_ * center;
46 }
47
48
49 /*
50   Get bezier with left control at (0,0)
51  */
52 Bezier
53 Tie_configuration::get_bezier (Tie_details const &details) const
54 {
55   Real l = attachment_x_.length();
56   if (isnan (l) || isnan (l))
57     {
58       programming_error ("Inf or NaN encountered");
59       l = 1.0;
60     }
61   return slur_shape (l,
62                      details.height_limit_,
63                      details.ratio_);
64 }
65
66 Real
67 Tie_configuration::distance (Tie_configuration const &a,
68                              Tie_configuration const &b)
69 {
70
71   Real d = 3 * (a.position_ - b.position_);
72   if (d < 0)
73     return d + (2 + (b.dir_ - a.dir_));
74   else
75     return d + (2 + (a.dir_ - b.dir_));
76 }
77
78 Real
79 Tie_configuration::height (Tie_details const &details) const
80 {
81   Real l = attachment_x_.length();
82
83   return slur_shape (l,
84                      details.height_limit_,
85                      details.ratio_).curve_point (0.5)[Y_AXIS]; 
86 }
87
88
89 void
90 Tie_details::init (Grob *me)
91 {
92   staff_space_ = Staff_symbol_referencer::staff_space (me);
93   SCM details = me->get_property ("details");
94   SCM limit
95     = scm_assq (ly_symbol2scm ("height-limit"), details);
96   height_limit_ = robust_scm2double (scm_cdr (limit), 0.75) * staff_space_;
97   ratio_ = robust_scm2double (scm_cdr (scm_assq (ly_symbol2scm ("ratio"), details)),
98                               .333);
99
100   x_gap_ = robust_scm2double (me->get_property ("x-gap"), 0.2);
101
102 }
103
104 Tie_details::Tie_details ()
105 {
106   staff_space_ = 1.0; 
107   height_limit_ = 1.0;
108   ratio_ = .333;   
109 }
110