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