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>
10 #include "tie-configuration.hh"
13 #include "tie-formatting-problem.hh"
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 ()
33 column_ranks_
= Drul_array
<int> (0, 0);
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
;
50 Tie_configuration::get_transformed_bezier (Tie_details
const &details
) const
52 Bezier
b (get_untransformed_bezier (details
));
55 b
.translate (Offset (attachment_x_
[LEFT
],
56 delta_y_
+ details
.staff_space_
* 0.5 * position_
));
62 Get bezier with left control at (0,0)
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");
74 details
.height_limit_
,
79 Tie_configuration::column_span_length () const
81 return column_ranks_
[RIGHT
] - column_ranks_
[LEFT
];
85 Tie_configuration::distance (Tie_configuration
const &a
,
86 Tie_configuration
const &b
)
89 Real d
= 3 * (a
.position_
- b
.position_
);
91 return d
+ (2 + (b
.dir_
- a
.dir_
));
93 return d
+ (2 + (a
.dir_
- b
.dir_
));
98 Tie_configuration::add_score (Real s
, string desc
)
103 score_card_
+= to_string ("%s=%.2f ", desc
.c_str (), s
);
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 ()
123 Ties_configuration::reset_score ()
128 tie_score_cards_
.clear ();
132 Ties_configuration::add_tie_score (Real s
, int i
, string desc
)
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
);
146 Ties_configuration::add_score (Real s
, string desc
)
151 score_card_
+= to_string ("%s=%.2f ", desc
.c_str (), s
);
155 Ties_configuration::score () const
162 Ties_configuration::complete_tie_card (vsize i
) const
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
176 if (i
+ 1 == size ())
177 s
+= to_string ("TOTAL=%.2f", score ());
182 /* for use inside GDB */
184 Ties_configuration::complete_score_card () const
187 for (vsize i
= 0; i
< size (); i
++)
189 s
+= complete_tie_card (i
);
198 Ties_configuration::card () const