- (c) 2004--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ LilyPond is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LilyPond is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
Grob *staff = state.extremes_[LEFT].staff_;
Real p = 2 * (y - staff->relative_coordinate (state.common_[Y_AXIS], Y_AXIS))
Grob *staff = state.extremes_[LEFT].staff_;
Real p = 2 * (y - staff->relative_coordinate (state.common_[Y_AXIS], Y_AXIS))
- && (int) fabs (my_round (p))
- <= 2 * Staff_symbol_referencer::staff_radius (staff) + 0.1
- && (int (fabs (my_round (p))) % 2
- != Staff_symbol_referencer::line_count (staff) % 2))
- {
- Direction resolution_dir
- = (distance ? state.dir_ : Direction (sign (p - my_round (p))));
-
- // TODO: parameter
- Real newp = my_round (p) + resolution_dir
- * 5 * state.thickness_;
-
- Real dy = (newp - p) * state.staff_space_ / 2.0;
-
- bez.control_[1][Y_AXIS] += dy;
- bez.control_[2][Y_AXIS] += dy;
- }
+ && (int) fabs (my_round (p))
+ <= 2 * Staff_symbol_referencer::staff_radius (staff) + 0.1
+ && (int (fabs (my_round (p))) % 2
+ != Staff_symbol_referencer::line_count (staff) % 2))
+ {
+ Direction resolution_dir
+ = (distance ? state.dir_ : Direction (sign (p - my_round (p))));
+
+ // TODO: parameter
+ Real newp = my_round (p) + resolution_dir
+ * 5 * state.thickness_;
+
+ Real dy = (newp - p) * state.staff_space_ / 2.0;
+
+ bez.control_[1][Y_AXIS] += dy;
+ bez.control_[2][Y_AXIS] += dy;
+ }
-fit_factor (Offset dz_unit, Offset dz_perp,
- Bezier curve, Direction d, vector<Offset> const &avoid)
+fit_factor (Offset dz_unit, Offset dz_perp, Real close_to_edge_length,
+ Bezier curve, Direction d, vector<Offset> const &avoid)
{
Offset z = (avoid[i] - x0);
Offset p (dot_product (z, dz_unit),
{
Offset z = (avoid[i] - x0);
Offset p (dot_product (z, dz_unit),
- d * dot_product (z, dz_perp));
+ d * dot_product (z, dz_perp));
+
+ bool close_to_edge = false;
+ Direction d = LEFT;
+ do
+ close_to_edge = close_to_edge || -d * (p[X_AXIS] - curve_xext[d]) < close_to_edge_length;
+ while (flip (&d) != LEFT);
+
+ if (close_to_edge)
+ continue;
Offset dz_unit = dz;
dz_unit *= 1 / dz.length ();
Offset dz_perp = dz_unit * Offset (0, 1);
Offset dz_unit = dz;
dz_unit *= 1 / dz.length ();
Offset dz_perp = dz_unit * Offset (0, 1);
- Real ff = fit_factor (dz_unit, dz_perp, curve, state.dir_, avoid);
+ Real ff = fit_factor (dz_unit, dz_perp, state.parameters_.close_to_edge_length_,
+ curve, state.dir_, avoid);
height = max (height, min (height * ff, max_h));
curve.control_[0] = attachment_[LEFT];
curve.control_[1] = attachment_[LEFT] + dz_perp * height * state.dir_
height = max (height, min (height * ff, max_h));
curve.control_[0] = attachment_[LEFT];
curve.control_[1] = attachment_[LEFT] + dz_perp * height * state.dir_
curve.control_[3] = attachment_[RIGHT];
curve_ = avoid_staff_line (state, curve);
curve.control_[3] = attachment_[RIGHT];
curve_ = avoid_staff_line (state, curve);
- {
- Real head_dy = (y - state.encompass_infos_[j].head_);
- if (state.dir_ * head_dy < 0)
- {
- demerit += state.parameters_.head_encompass_penalty_;
- convex_head_distances.push_back (0.0);
- }
- else
- {
- Real hd = (head_dy)
- ? (1 / fabs (head_dy) - 1 / state.parameters_.free_head_distance_)
- : state.parameters_.head_encompass_penalty_;
- hd = min (max (hd, 0.0), state.parameters_.head_encompass_penalty_);
-
- demerit += hd;
- }
-
- Real line_y = linear_interpolate (x,
- attachment_[RIGHT][X_AXIS],
- attachment_[LEFT][X_AXIS],
- attachment_[RIGHT][Y_AXIS],
- attachment_[LEFT][Y_AXIS]);
-
- if (1) // state.dir_ * state.encompass_infos_[j].get_point (state.dir_) > state.dir_ *line_y )
- {
-
- Real closest
- = state.dir_ * max (state.dir_ * state.encompass_infos_[j].get_point (state.dir_), state.dir_ * line_y);
- Real d = fabs (closest - y);
-
- convex_head_distances.push_back (d);
- }
- }
+ {
+ Real head_dy = (y - state.encompass_infos_[j].head_);
+ if (state.dir_ * head_dy < 0)
+ {
+ demerit += state.parameters_.head_encompass_penalty_;
+ convex_head_distances.push_back (0.0);
+ }
+ else
+ {
+ Real hd = (head_dy)
+ ? (1 / fabs (head_dy) - 1 / state.parameters_.free_head_distance_)
+ : state.parameters_.head_encompass_penalty_;
+ hd = min (max (hd, 0.0), state.parameters_.head_encompass_penalty_);
+
+ demerit += hd;
+ }
+
+ Real line_y = linear_interpolate (x,
+ attachment_[RIGHT][X_AXIS],
+ attachment_[LEFT][X_AXIS],
+ attachment_[RIGHT][Y_AXIS],
+ attachment_[LEFT][Y_AXIS]);
+
+ if (1) // state.dir_ * state.encompass_infos_[j].get_point (state.dir_) > state.dir_ *line_y )
+ {
+
+ Real closest
+ = state.dir_ * max (state.dir_ * state.encompass_infos_[j].get_point (state.dir_), state.dir_ * line_y);
+ Real d = fabs (closest - y);
+
+ convex_head_distances.push_back (d);
+ }
+ }
- {
- Real stem_dem = state.parameters_.stem_encompass_penalty_;
- if ((l_edge && state.dir_ == UP)
- || (r_edge && state.dir_ == DOWN))
- stem_dem /= 5;
-
- demerit += stem_dem;
- }
+ {
+ Real stem_dem = state.parameters_.stem_encompass_penalty_;
+ if ((l_edge && state.dir_ == UP)
+ || (r_edge && state.dir_ == DOWN))
+ stem_dem /= 5;
+
+ demerit += stem_dem;
+ }
- {
- Interval ext;
- ext.add_point (state.encompass_infos_[j].stem_);
- ext.add_point (state.encompass_infos_[j].head_);
-
- // ?
- demerit += -state.parameters_.closeness_factor_
- * min (state.dir_
- * (y - (ext[state.dir_] + state.dir_ * state.parameters_.free_head_distance_)), 0.0)
- / state.encompass_infos_.size ();
- }
+ {
+ Interval ext;
+ ext.add_point (state.encompass_infos_[j].stem_);
+ ext.add_point (state.encompass_infos_[j].head_);
+
+ // ?
+ demerit += -state.parameters_.closeness_factor_
+ * min (state.dir_
+ * (y - (ext[state.dir_] + state.dir_ * state.parameters_.free_head_distance_)), 0.0)
+ / state.encompass_infos_.size ();
+ }
if (convex_head_distances.size ())
{
Real avg_distance = 0.0;
Real min_dist = infinity_f;
for (vsize j = 0; j < convex_head_distances.size (); j++)
if (convex_head_distances.size ())
{
Real avg_distance = 0.0;
Real min_dist = infinity_f;
for (vsize j = 0; j < convex_head_distances.size (); j++)
- {
- min_dist = min (min_dist, convex_head_distances[j]);
- avg_distance += convex_head_distances[j];
- }
+ {
+ min_dist = min (min_dist, convex_head_distances[j]);
+ avg_distance += convex_head_distances[j];
+ }
variance_penalty = max (variance_penalty, 0.0);
variance_penalty *= state.parameters_.head_slur_distance_factor_;
variance_penalty = max (variance_penalty, 0.0);
variance_penalty *= state.parameters_.head_slur_distance_factor_;
- {
- /*
- We need to check for the bound explicitly, since the
- slur-ending can be almost vertical, making the Y
- coordinate a bad approximation of the object-slur
- distance.
- */
- Item *as_item = dynamic_cast<Item *> (state.extra_encompass_infos_[j].grob_);
- if (!as_item)
- continue;
-
- Interval item_x = as_item->extent (state.common_[X_AXIS], X_AXIS);
- item_x.intersect (state.extremes_[d].slur_head_x_extent_);
- if (!item_x.is_empty ())
- {
- y = attachment[d][Y_AXIS];
- found = true;
- }
-
- }
+ {
+ /*
+ We need to check for the bound explicitly, since the
+ slur-ending can be almost vertical, making the Y
+ coordinate a bad approximation of the object-slur
+ distance.
+ */
+ Item *as_item = dynamic_cast<Item *> (state.extra_encompass_infos_[j].grob_);
+ if (!as_item)
+ continue;
+
+ Interval item_x = as_item->extent (state.common_[X_AXIS], X_AXIS);
+ item_x.intersect (state.extremes_[d].slur_head_x_extent_);
+ if (!item_x.is_empty ())
+ {
+ y = attachment[d][Y_AXIS];
+ found = true;
+ }
+
+ }
- Have to score too: the curve enumeration is limited in its
- shape, and may produce curves which collide anyway.
+ Have to score too: the curve enumeration is limited in its
+ shape, and may produce curves which collide anyway.
Real factor = state.parameters_.edge_attraction_factor_;
Real demerit = factor * dy;
if (state.extremes_[d].stem_
Real factor = state.parameters_.edge_attraction_factor_;
Real demerit = factor * dy;
if (state.extremes_[d].stem_
- && state.extremes_[d].stem_dir_ == state.dir_
- && !Stem::get_beaming (state.extremes_[d].stem_, -d))
- demerit /= 5;
+ && state.extremes_[d].stem_dir_ == state.dir_
+ // TODO - Stem::get_beaming() should be precomputed.
+ && !Stem::get_beaming (state.extremes_[d].stem_, -d))
+ demerit /= 5;
string dir_str = d == LEFT ? "L" : "R";
add_score (demerit, dir_str + " edge");
string dir_str = d == LEFT ? "L" : "R";
add_score (demerit, dir_str + " edge");
- - state.parameters_.max_slope_), 0.0)
- * state.parameters_.max_slope_factor_;
+ - state.parameters_.max_slope_), 0.0)
+ * state.parameters_.max_slope_factor_;
- - state.parameters_.max_slope_), 0.0)
- * state.parameters_.max_slope_factor_;
+ - state.parameters_.max_slope_), 0.0)
+ * state.parameters_.max_slope_factor_;
+// This is a temporary hack to see how much we can gain by using a
+// priority queue on the beams to score.
+static int score_count = 0;
+LY_DEFINE (ly_slur_score_count, "ly:slur-score-count", 0, 0, 0,
+ (),
+ "count number of slur scores.")
+{
+ return scm_from_int (score_count);
+}
+
-Slur_configuration::calculate_score (Slur_score_state const &state)
+Slur_configuration::run_next_scorer (Slur_score_state const &state)
+{
+ switch (next_scorer_todo)
+ {
+ case EXTRA_ENCOMPASS:
+ score_extra_encompass (state);
+ break;
+ case SLOPE:
+ score_slopes (state);
+ break;
+ case EDGES:
+ score_edges (state);
+ break;
+ case ENCOMPASS:
+ score_encompass (state);
+ break;
+ default:
+ assert (false);
+ }
+ next_scorer_todo++;
+ score_count++;
+}
+
+bool
+Slur_configuration::done () const
+{
+ return next_scorer_todo >= NUM_SCORERS;
+}
+
+Slur_configuration *
+Slur_configuration::new_config (Drul_array<Offset> const &offs, int idx)
- score_extra_encompass (state);
- score_slopes (state);
- score_edges (state);
- score_encompass (state);
+ Slur_configuration *conf = new Slur_configuration;
+ conf->attachment_ = offs;
+ conf->index_ = idx;
+ conf->next_scorer_todo = INITIAL_SCORE + 1;
+ return conf;