slur_ = 0;
common_[X_AXIS] = 0;
common_[Y_AXIS] = 0;
- scores_ = 0;
}
Slur_score_state::~Slur_score_state ()
{
- delete scores_;
+ junk_pointers (configurations_);
}
-
-
-
-
Real
get_detail (SCM alist, SCM sym)
{
}
void
-init_score_param (Grob *me,
- Slur_score_parameters *score_param)
+Slur_score_parameters::fill (Grob *me)
{
SCM details = me->get_property ("slur-details");
- score_param->region_size_
+ region_size_
= (int) get_detail (details, ly_symbol2scm ("region-size"));
- score_param->head_encompass_penalty_
+ head_encompass_penalty_
= get_detail (details, ly_symbol2scm ("head-encompass-penalty"));
- score_param->stem_encompass_penalty_
+ stem_encompass_penalty_
= get_detail (details, ly_symbol2scm ("stem-encompass-penalty"));
- score_param->closeness_factor_
+ closeness_factor_
= get_detail (details, ly_symbol2scm ("closeness-factor"));
- score_param->edge_attraction_factor_
+ edge_attraction_factor_
= get_detail (details, ly_symbol2scm ("edge-attraction-factor"));
- score_param->same_slope_penalty_
+ same_slope_penalty_
= get_detail (details, ly_symbol2scm ("same-slope-penalty"));
- score_param->steeper_slope_factor_
+ steeper_slope_factor_
= get_detail (details, ly_symbol2scm ("steeper-slope-factor"));
- score_param->non_horizontal_penalty_
+ non_horizontal_penalty_
= get_detail (details, ly_symbol2scm ("non-horizontal-penalty"));
- score_param->max_slope_
+ max_slope_
= get_detail (details, ly_symbol2scm ("max-slope"));
- score_param->max_slope_factor_
+ max_slope_factor_
= get_detail (details, ly_symbol2scm ("max-slope-factor"));
- score_param->free_head_distance_
+ free_head_distance_
= get_detail (details, ly_symbol2scm ("free-head-distance"));
- score_param->extra_object_collision_
+ absolute_closeness_measure_
+ = get_detail (details, ly_symbol2scm ("absolute-closeness-measure"));
+ extra_object_collision_
= get_detail (details, ly_symbol2scm ("extra-object-collision"));
- score_param->accidental_collision_
+ accidental_collision_
= get_detail (details, ly_symbol2scm ("accidental-collision"));
- score_param->extra_encompass_free_distance_
+ extra_encompass_free_distance_
= get_detail (details, ly_symbol2scm ("extra-encompass-free-distance"));
- score_param->head_slur_distance_factor_
+ head_slur_distance_factor_
= get_detail (details, ly_symbol2scm ("head-slur-distance-factor"));
- score_param->head_slur_distance_max_ratio_
+ head_slur_distance_max_ratio_
= get_detail (details, ly_symbol2scm ("head-slur-distance-max-ratio"));
- score_param->free_slur_distance_
+ free_slur_distance_
= get_detail (details, ly_symbol2scm ("free-slur-distance"));
- score_param->edge_slope_exponent_
+ edge_slope_exponent_
= get_detail (details, ly_symbol2scm ("edge-slope-exponent"));
}
}
staff_space_ = Staff_symbol_referencer::staff_space (me);
- Real lt = me->get_paper ()->get_dimension (ly_symbol2scm ("linethickness"));
+ Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
thickness_ = robust_scm2double (me->get_property ("thickness"), 1.0) * lt;
dir_ = get_grob_direction (me);
- init_score_param (me, ¶meters_);
+ parameters_.fill (me);
SCM eltlist = me->get_property ("note-columns");
SCM extra_list = me->get_property ("encompass-objects");
Direction d = LEFT;
do {
- common_[a] = common_[a]->common_refpoint (sp->get_bound (d), a);
+ /*
+ If bound is not in note-columns, we don't want to know about
+ its Y-position
+ */
+ if (a != Y_AXIS)
+ common_[a] = common_[a]->common_refpoint (sp->get_bound (d), a);
}
while (flip (&d) != LEFT);
}
extremes_ = get_bound_info ();
is_broken_ = (!extremes_[LEFT].note_column_
- || !extremes_[RIGHT].note_column_);
+ || !extremes_[RIGHT].note_column_);
+ has_same_beam_ =
+ (extremes_[LEFT].stem_ && extremes_[RIGHT].stem_
+ && Stem::get_beam (extremes_[LEFT].stem_) == Stem::get_beam (extremes_[RIGHT].stem_));
base_attachments_ = get_base_attachments ();
Drul_array<Real> end_ys
= get_y_attachment_range ();
- scores_ = enumerate_attachments ( end_ys);
+ configurations_ = enumerate_attachments ( end_ys);
for (int i = 0; i < columns_.size (); i++)
encompass_infos_.push (get_encompass_info ( columns_[i]));
= (extremes_[LEFT].stem_ && Stem::get_beam (extremes_[LEFT].stem_))
|| (extremes_[RIGHT].stem_ && Stem::get_beam (extremes_[RIGHT].stem_));
- has_same_beam_ =
- (extremes_[LEFT].stem_ && extremes_[RIGHT].stem_
- && Stem::get_beam (extremes_[LEFT].stem_) == Stem::get_beam (extremes_[RIGHT].stem_));
set_next_direction ();
Bezier
Slur_score_state::get_best_curve ()
{
- for (int i = 0; i < scores_->size (); i++)
+ for (int i = 0; i < configurations_.size (); i++)
{
- scores_->elem (i).score (*this);
+ configurations_[i]->score (*this);
}
Real opt = 1e6;
int opt_idx = -1;
- for (int i = 0; i < scores_->size (); i++)
+ for (int i = 0; i < configurations_.size (); i++)
{
- if ((*scores_)[i].score_ < opt)
+ if (configurations_[i]->score_ < opt)
{
- opt = (*scores_)[i].score_;
+ opt = configurations_[i]->score_;
opt_idx = i;
}
}
#if DEBUG_SLUR_SCORING
SCM inspect_quants = slur_->get_property ("inspect-quants");
- if (to_boolean (slur_->get_paper ()
+ if (to_boolean (slur_->get_layout ()
->lookup_variable (ly_symbol2scm ("debug-slur-scoring")))
&& scm_is_pair (inspect_quants))
{
Drul_array<Real> ins = ly_scm2interval (inspect_quants);
Real mindist = 1e6;
- for (int i = 0; i < scores_->size (); i ++)
+ for (int i = 0; i < configurations_.size (); i ++)
{
- Real d =fabs ((*scores_)[i].attachment_[LEFT][Y_AXIS] - ins[LEFT])
- + fabs ((*scores_)[i].attachment_[RIGHT][Y_AXIS] - ins[RIGHT]);
+ Real d =fabs (configurations_[i]->attachment_[LEFT][Y_AXIS] - ins[LEFT])
+ + fabs (configurations_[i]->attachment_[RIGHT][Y_AXIS] - ins[RIGHT]);
if (d < mindist)
{
opt_idx = i;
if (mindist > 1e5)
programming_error ("Could not find quant.");
}
- (*scores_)[opt_idx].score_card_ += to_string ("i%d", opt_idx);
+
+ configurations_[opt_idx]->score_card_ += to_string ("=%.2f", opt);
+ configurations_[opt_idx]->score_card_ += to_string ("i%d", opt_idx);
// debug quanting
slur_->set_property ("quant-score",
- scm_makfrom0str ((*scores_)[opt_idx].score_card_.to_str0 ()));
+ scm_makfrom0str (configurations_[opt_idx]->score_card_.to_str0 ()));
+
#endif
- return scores_->elem (opt_idx).curve_;
+ return configurations_[opt_idx]->curve_;
}
/*
y = head->extent (common_[Y_AXIS], Y_AXIS)[dir_];
y += dir_ * 0.5 * staff_space_;
- Real pos
- = (y - extremes_[d].staff_->relative_coordinate (common_[Y_AXIS],
- Y_AXIS))
- * 2.0 / staff_space_;
- /* start off staffline. */
- if (fabs (pos - my_round (pos)) < 0.2
- && Staff_symbol_referencer::on_staffline (head, (int) rint (pos))
- && Staff_symbol_referencer::line_count (head) - 1 >= rint (pos)
- )
- // TODO: calc from slur thick & line thick, parameter.
- y += 1.5 * staff_space_ * dir_ / 10;
+ y = move_away_from_staffline (y, head);
Grob * fh = Note_column::first_head (extremes_[d].note_column_);
x =
if (extremes_[-d].bound_ != col)
{
y = robust_relative_extent (col, common_[Y_AXIS], Y_AXIS)[dir_];
- if (get_grob_direction (col) == dir_)
- y -= dir_ ;
+ y += dir_ * 0.5 * staff_space_;
+
+ if (get_grob_direction (col) == dir_
+ && Note_column::get_stem (col)
+ && !Stem::is_invisible (Note_column::get_stem (col)))
+ y -= dir_ * 1.5 * staff_space_;
}
else
y = base_attachment[-d][Y_AXIS];
+
+ y = move_away_from_staffline (y, col);
+
base_attachment[d] = Offset (x, y);
}
}
return base_attachment;
}
+Real
+Slur_score_state::move_away_from_staffline (Real y,
+ Grob *on_staff) const
+{
+ Real pos
+ = (y - Staff_symbol_referencer::get_staff_symbol (on_staff)->relative_coordinate (common_[Y_AXIS],
+ Y_AXIS))
+ * 2.0 / staff_space_;
+
+ if (fabs (pos - my_round (pos)) < 0.2
+ && Staff_symbol_referencer::on_staffline (on_staff, (int) rint (pos))
+ && Staff_symbol_referencer::line_count (on_staff) - 1 >= rint (pos)
+ )
+ y += 1.5 * staff_space_ * dir_ / 10;
+
+ return y;
+}
+
void
Slur_score_state::generate_curves () const
{
Real r_0 = robust_scm2double (slur_->get_property ("ratio"), 0.33);
Real h_inf = staff_space_ *scm_to_double (slur_->get_property ("height-limit"));
- for (int i = 0; i < scores_->size (); i++)
- scores_->elem(i).generate_curve (*this, r_0, h_inf);
+ for (int i = 0; i < configurations_.size (); i++)
+ configurations_[i]->generate_curve (*this, r_0, h_inf);
}
-Array<Slur_configuration> *
+Link_array<Slur_configuration>
Slur_score_state::enumerate_attachments (Drul_array<Real> end_ys) const
{
/*ugh. */
- Array<Slur_configuration> scores;
+ Link_array<Slur_configuration> scores;
Drul_array<Offset> os;
while (flip (&d) != LEFT);
s.attachment_ = os;
- scores.push (s);
-
+ s.index_ = scores.size ();
+
+ scores.push (new Slur_configuration (s));
+
os[RIGHT][Y_AXIS] += dir_ * staff_space_ / 2;
}
}
assert (scores.size () > 0);
- return new Array<Slur_configuration> (scores);
+ return scores;
}
Array<Extra_collision_info>
-Slur_score_state::get_extra_encompass_infos ( ) const
+Slur_score_state::get_extra_encompass_infos () const
{
Link_array<Grob> encompasses
= Pointer_group_interface__extract_grobs (slur_, (Grob *)0,
if (hdir && small_slur->get_bound (hdir) != slur_->get_bound (hdir))
continue;
-
- Offset z = b.curve_point ( k / 2.0);
+ Offset z = b.curve_point (k / 2.0);
z += relative;
Interval yext;