]> git.donarmstrong.com Git - lilypond.git/blob - lily/tie-configuration.cc
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / lily / tie-configuration.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "tie-configuration.hh"
22
23 #include "warn.hh"
24 #include "tie-formatting-problem.hh"
25 #include "bezier.hh"
26
27 int
28 Tie_configuration::compare (Tie_configuration const &a,
29                             Tie_configuration const &b)
30 {
31   if (a.position_ - b.position_)
32     return sign (a.position_ - b.position_);
33   return sign (a.dir_ - b.dir_);
34 }
35                             
36
37 Tie_configuration::Tie_configuration ()
38 {
39   dir_ = CENTER;
40   position_ = 0;
41   delta_y_ = 0.0;
42   score_ = 0.0;
43   scored_ = false;
44   column_ranks_ = Drul_array<int> (0, 0);
45 }
46
47
48 void
49 Tie_configuration::center_tie_vertically (Tie_details const &details)
50 {
51   Bezier b = get_untransformed_bezier (details);
52   Offset middle = b.curve_point (0.5);
53   Offset edge = b.curve_point (0.0);
54   Real center = (edge[Y_AXIS] + middle[Y_AXIS])/2.0;
55
56   delta_y_ = - dir_ * center;
57 }
58
59
60 Bezier
61 Tie_configuration::get_transformed_bezier (Tie_details const &details) const
62 {
63   Bezier b (get_untransformed_bezier (details));
64
65   b.scale (1, dir_);
66   b.translate (Offset (attachment_x_[LEFT],
67                        delta_y_ + details.staff_space_ * 0.5 * position_));
68
69   return b;
70 }
71
72 /*
73   Get bezier with left control at (0,0)
74  */
75 Bezier
76 Tie_configuration::get_untransformed_bezier (Tie_details const &details) const
77 {
78   Real l = attachment_x_.length ();
79   if (isinf (l) || isnan (l))
80     {
81       programming_error ("Inf or NaN encountered");
82       l = 1.0;
83     }
84   return slur_shape (l,
85                      details.height_limit_,
86                      details.ratio_);
87 }
88
89 int
90 Tie_configuration::column_span_length () const
91 {
92   return column_ranks_[RIGHT] - column_ranks_[LEFT];
93 }
94
95 Real
96 Tie_configuration::distance (Tie_configuration const &a,
97                              Tie_configuration const &b)
98 {
99
100   Real d = 3 * (a.position_ - b.position_);
101   if (d < 0)
102     return d + (2 + (b.dir_ - a.dir_));
103   else
104     return d + (2 + (a.dir_ - b.dir_));
105 }
106
107
108 void
109 Tie_configuration::add_score (Real s, string desc)
110 {
111   assert (!scored_);
112   score_ += s;
113   if (s)
114     score_card_ += to_string ("%s=%.2f ", desc.c_str (), s);
115 }
116
117 Real
118 Tie_configuration::height (Tie_details const &details) const
119 {
120   Real l = attachment_x_.length ();
121
122   return slur_shape (l,
123                      details.height_limit_,
124                      details.ratio_).curve_point (0.5)[Y_AXIS]; 
125 }
126
127 Ties_configuration::Ties_configuration ()
128 {
129   score_ = 0.0;
130   scored_ = false;
131 }
132
133 void
134 Ties_configuration::reset_score ()
135 {
136   score_ = 0.0;
137   scored_ = false;
138   score_card_ = "";
139   tie_score_cards_.clear ();
140 }
141
142 void
143 Ties_configuration::add_tie_score (Real s, int i, string desc)
144 {
145   assert (!scored_);
146   score_ += s;
147   if (s)
148     {
149       while (tie_score_cards_.size () < size ())
150         tie_score_cards_.push_back ("");
151
152       tie_score_cards_[i] += to_string ("%s=%.2f ", desc.c_str (), s);
153     }
154 }
155
156 void
157 Ties_configuration::add_score (Real s, string desc)
158 {
159   assert (!scored_);
160   score_ += s;
161   if (s)
162     score_card_ += to_string ("%s=%.2f ", desc.c_str (), s);
163 }
164
165 Real
166 Ties_configuration::score () const
167 {
168   return score_;
169 }
170
171
172 string
173 Ties_configuration::complete_tie_card (vsize i) const
174 {
175   string s;
176   s += to_string ("%d (%.2f) %c: ", (*this)[i].position_, (*this)[i].delta_y_,
177                   ((*this)[i].dir_ == UP ? 'u' : 'd'))
178     + (*this)[i].card () + (*this).tie_card (i);
179   
180   /*
181     this is a little awkward, but we must decide where to put
182     aggregrates.
183    */
184   if (i == 0)
185     s += card ();
186
187   if (i + 1 == size ())
188     s += to_string ("TOTAL=%.2f", score ());
189   
190   return s;
191 }
192
193 /* for use inside GDB */
194 string
195 Ties_configuration::complete_score_card () const
196 {
197   string s; 
198   for (vsize i = 0; i < size (); i++)
199     {
200       s += complete_tie_card (i);
201     }
202
203   return s;
204 }
205
206
207
208 string
209 Ties_configuration::card () const
210 {
211   return score_card_;
212 }
213