Fix flag snippet in NEWS.tely.
[lilypond.git] / lily / tie-configuration.cc
blob9cccd505b9daea335b02b10d2feeaf2053f4b649
1 /*
2 tie-configuration.cc -- implement Tie_configuration
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
10 #include "tie-configuration.hh"
12 #include "warn.hh"
13 #include "tie-formatting-problem.hh"
14 #include "bezier.hh"
16 int
17 Tie_configuration::compare (Tie_configuration const &a,
18 Tie_configuration const &b)
20 if (a.position_ - b.position_)
21 return sign (a.position_ - b.position_);
22 return sign (a.dir_ - b.dir_);
26 Tie_configuration::Tie_configuration ()
28 dir_ = CENTER;
29 position_ = 0;
30 delta_y_ = 0.0;
31 score_ = 0.0;
32 scored_ = false;
33 column_ranks_ = Drul_array<int> (0, 0);
37 void
38 Tie_configuration::center_tie_vertically (Tie_details const &details)
40 Bezier b = get_untransformed_bezier (details);
41 Offset middle = b.curve_point (0.5);
42 Offset edge = b.curve_point (0.0);
43 Real center = (edge[Y_AXIS] + middle[Y_AXIS])/2.0;
45 delta_y_ = - dir_ * center;
49 Bezier
50 Tie_configuration::get_transformed_bezier (Tie_details const &details) const
52 Bezier b (get_untransformed_bezier (details));
54 b.scale (1, dir_);
55 b.translate (Offset (attachment_x_[LEFT],
56 delta_y_ + details.staff_space_ * 0.5 * position_));
58 return b;
62 Get bezier with left control at (0,0)
64 Bezier
65 Tie_configuration::get_untransformed_bezier (Tie_details const &details) const
67 Real l = attachment_x_.length ();
68 if (isinf (l) || isnan (l))
70 programming_error ("Inf or NaN encountered");
71 l = 1.0;
73 return slur_shape (l,
74 details.height_limit_,
75 details.ratio_);
78 int
79 Tie_configuration::column_span_length () const
81 return column_ranks_[RIGHT] - column_ranks_[LEFT];
84 Real
85 Tie_configuration::distance (Tie_configuration const &a,
86 Tie_configuration const &b)
89 Real d = 3 * (a.position_ - b.position_);
90 if (d < 0)
91 return d + (2 + (b.dir_ - a.dir_));
92 else
93 return d + (2 + (a.dir_ - b.dir_));
97 void
98 Tie_configuration::add_score (Real s, string desc)
100 assert (!scored_);
101 score_ += s;
102 if (s)
103 score_card_ += to_string ("%s=%.2f ", desc.c_str (), s);
106 Real
107 Tie_configuration::height (Tie_details const &details) const
109 Real l = attachment_x_.length ();
111 return slur_shape (l,
112 details.height_limit_,
113 details.ratio_).curve_point (0.5)[Y_AXIS];
116 Ties_configuration::Ties_configuration ()
118 score_ = 0.0;
119 scored_ = false;
122 void
123 Ties_configuration::reset_score ()
125 score_ = 0.0;
126 scored_ = false;
127 score_card_ = "";
128 tie_score_cards_.clear ();
131 void
132 Ties_configuration::add_tie_score (Real s, int i, string desc)
134 assert (!scored_);
135 score_ += s;
136 if (s)
138 while (tie_score_cards_.size () < size ())
139 tie_score_cards_.push_back ("");
141 tie_score_cards_[i] += to_string ("%s=%.2f ", desc.c_str (), s);
145 void
146 Ties_configuration::add_score (Real s, string desc)
148 assert (!scored_);
149 score_ += s;
150 if (s)
151 score_card_ += to_string ("%s=%.2f ", desc.c_str (), s);
154 Real
155 Ties_configuration::score () const
157 return score_;
161 string
162 Ties_configuration::complete_tie_card (vsize i) const
164 string s;
165 s += to_string ("%d (%.2f) %c: ", (*this)[i].position_, (*this)[i].delta_y_,
166 ((*this)[i].dir_ == UP ? 'u' : 'd'))
167 + (*this)[i].card () + (*this).tie_card (i);
170 this is a little awkward, but we must decide where to put
171 aggregrates.
173 if (i == 0)
174 s += card ();
176 if (i + 1 == size ())
177 s += to_string ("TOTAL=%.2f", score ());
179 return s;
182 /* for use inside GDB */
183 string
184 Ties_configuration::complete_score_card () const
186 string s;
187 for (vsize i = 0; i < size (); i++)
189 s += complete_tie_card (i);
192 return s;
197 string
198 Ties_configuration::card () const
200 return score_card_;