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