From 2e613f5d4d7232507698d3a717576f46920a988b Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 12 Jan 2007 22:54:00 +0100 Subject: [PATCH] only do staffline avoidance if we're inside the staff or inside the ledgers. --- lily/include/misc.hh | 2 +- lily/include/tie-formatting-problem.hh | 3 + lily/include/tie-specification.hh | 1 + lily/misc.cc | 4 +- lily/tie-formatting-problem.cc | 104 +++++++++++++++---------- scm/define-grobs.scm | 2 +- 6 files changed, 71 insertions(+), 45 deletions(-) diff --git a/lily/include/misc.hh b/lily/include/misc.hh index d0bb6f417b..fad61b1ad3 100644 --- a/lily/include/misc.hh +++ b/lily/include/misc.hh @@ -38,7 +38,7 @@ linear_interpolate (Real x, Real x1, Real x2, Real y1, Real y2) Real directed_round (Real f, Direction d); Real peak_around (Real epsilon, Real threshold, Real x); -Real convex_amplifier (Real standard_x, Real x); +Real convex_amplifier (Real standard_x, Real increase_factor, Real x); string camel_case_to_lisp_identifier (string in); #endif diff --git a/lily/include/tie-formatting-problem.hh b/lily/include/tie-formatting-problem.hh index 863712e99e..ebee98877f 100644 --- a/lily/include/tie-formatting-problem.hh +++ b/lily/include/tie-formatting-problem.hh @@ -30,11 +30,13 @@ struct Tie_configuration_variation typedef map < Tuple, Skyline> Chord_outline_map; typedef map < Tuple, Box> Column_extent_map; +typedef map Position_extent_map; class Tie_formatting_problem { Chord_outline_map chord_outlines_; Column_extent_map stem_extents_; Column_extent_map head_extents_; + Position_extent_map head_positions_; set dot_positions_; Interval dot_x_; @@ -60,6 +62,7 @@ class Tie_formatting_problem void set_ties_config_standard_directions (Ties_configuration *tie_configs_ptr); void score_ties (Ties_configuration *) const; + Slice head_positions_slice (int) const; Ties_configuration generate_base_chord_configuration (); Ties_configuration find_best_variation (Ties_configuration const &base, vector const &vars); diff --git a/lily/include/tie-specification.hh b/lily/include/tie-specification.hh index 912dc78689..0a437d312b 100644 --- a/lily/include/tie-specification.hh +++ b/lily/include/tie-specification.hh @@ -23,6 +23,7 @@ struct Tie_specification bool has_manual_position_; bool has_manual_dir_; bool has_manual_delta_y_; + bool has_accidental_; Real manual_position_; Direction manual_dir_; diff --git a/lily/misc.cc b/lily/misc.cc index 8d10141524..6837df0d74 100644 --- a/lily/misc.cc +++ b/lily/misc.cc @@ -60,9 +60,9 @@ peak_around (Real epsilon, Real threshold, Real x) 0 at 0, 1 at standard_x, and increasing thereafter. */ Real -convex_amplifier (Real standard_x, Real x) +convex_amplifier (Real standard_x, Real increase_factor, Real x) { - return (exp (x / standard_x) - 1.0) / (exp (1) - 1.0); + return (exp (increase_factor * x / standard_x) - 1.0) / (exp (increase_factor) - 1.0); } string diff --git a/lily/tie-formatting-problem.cc b/lily/tie-formatting-problem.cc index 297fd4a155..6c7e2a024f 100644 --- a/lily/tie-formatting-problem.cc +++ b/lily/tie-formatting-problem.cc @@ -168,24 +168,25 @@ Tie_formatting_problem::set_column_chord_outline (vector bounds, extract_grob_set (stem, "note-heads", heads); for (vsize i = 0; i < heads.size(); i ++) { - if (find (bounds.begin(), bounds.end (), dynamic_cast (heads[i])) != bounds.end ()) - continue; - - /* - other untied notes in the same chord. - */ + if (find (bounds.begin(), bounds.end (), dynamic_cast (heads[i])) == bounds.end ()) + { + /* + other untied notes in the same chord. + */ - Interval y = Staff_symbol_referencer::extent_in_staff (heads[i]); - Interval x = heads[i]->extent (x_refpoint_, X_AXIS); - boxes.push_back (Box (x, y)); - + Interval y = Staff_symbol_referencer::extent_in_staff (heads[i]); + Interval x = heads[i]->extent (x_refpoint_, X_AXIS); + boxes.push_back (Box (x, y)); + } Grob *acc = unsmob_grob (heads[i]->get_object ("accidental-grob")); - if (acc && dir == RIGHT) + if (acc && acc->is_live () && dir == RIGHT) { boxes.push_back (Box (acc->extent (x_refpoint_, X_AXIS), Staff_symbol_referencer::extent_in_staff (acc))); } + + head_positions_[column_rank].add_point (int (Staff_symbol_referencer::get_position (heads[i]))); } } @@ -458,37 +459,41 @@ Tie_formatting_problem::generate_configuration (int pos, Direction dir, size. */ - if (h < details_.intra_space_threshold_ * 0.5 * details_.staff_space_) + if (head_positions_slice (columns[LEFT]).contains (pos) + || head_positions_slice (columns[RIGHT]).contains (pos) + || abs (pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_)) { - if (!Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos) - && abs (pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_)) + if (h < details_.intra_space_threshold_ * 0.5 * details_.staff_space_) { - conf->center_tie_vertically (details_); - } - else if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos)) - { - conf->delta_y_ += dir * - details_.tip_staff_line_clearance_ * 0.5 * details_.staff_space_; + if (!Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos) + && abs (pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_)) + { + conf->center_tie_vertically (details_); + } + else if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos)) + { + conf->delta_y_ += dir * + details_.tip_staff_line_clearance_ * 0.5 * details_.staff_space_; + } } - } - else - { - Real top_y = y + conf->delta_y_ + conf->dir_ * h; - Real top_pos = top_y / (0.5*details_.staff_space_); - int round_pos = int (my_round (top_pos)); - - /* TODO: should use other variable? */ - Real clearance = details_.center_staff_line_clearance_; - if (fabs (top_pos - round_pos) < clearance - && Staff_symbol_referencer::on_staff_line (details_.staff_symbol_referencer_, - round_pos)) + else { - Real new_y = (round_pos + clearance * conf->dir_) * 0.5 * details_.staff_space_; - conf->delta_y_ = (new_y - top_y); + Real top_y = y + conf->delta_y_ + conf->dir_ * h; + Real top_pos = top_y / (0.5*details_.staff_space_); + int round_pos = int (my_round (top_pos)); + + /* TODO: should use other variable? */ + Real clearance = details_.center_staff_line_clearance_; + if (fabs (top_pos - round_pos) < clearance + && Staff_symbol_referencer::on_staff_line (details_.staff_symbol_referencer_, + round_pos)) + { + Real new_y = (round_pos + clearance * conf->dir_) * 0.5 * details_.staff_space_; + conf->delta_y_ = (new_y - top_y); + } } } - } - + } conf->attachment_x_ = get_attachment (y + conf->delta_y_, conf->column_ranks_); if (conf->height (details_) < details_.intra_space_threshold_ * 0.5 * details_.staff_space_) { @@ -574,7 +579,8 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf, } { - Real p = details_.vertical_distance_penalty_factor_ * convex_amplifier (1.0, fabs (curve_y - tie_y)); + Real relevant_dist = max (fabs (curve_y - tie_y) - 0.5, 0.0); + Real p = details_.vertical_distance_penalty_factor_ * convex_amplifier (1.0, 0.9, relevant_dist); if (ties_conf) ties_conf->add_tie_score (p, tie_idx, "vdist"); else @@ -595,7 +601,7 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf, TODO: flatten with log or sqrt. */ Real p = details_.horizontal_distance_penalty_factor_ - * convex_amplifier (1.25, dist); + * convex_amplifier (1.25, 1.0, dist); if (ties_conf) ties_conf->add_tie_score (p, tie_idx, (d == LEFT) ? "lhdist" : "rhdist"); @@ -646,6 +652,18 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf, } +Slice +Tie_formatting_problem::head_positions_slice (int rank) const +{ + Position_extent_map::const_iterator i (head_positions_.find (rank)); + if (i != head_positions_.end ()) + { + return (*i).second; + } + Slice empty; + return empty; +} + /* Score a configuration, ie. how well these ties looks without regard to the note heads that they should connect to. @@ -682,9 +700,13 @@ Tie_formatting_problem::score_configuration (Tie_configuration *conf) const fabs (top_pos - round_top_pos)), "line center"); } - - if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, - int (rint (tip_pos)))) + + int rounded_tip_pos = int (rint (tip_pos)); + if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, rounded_tip_pos) + && (head_positions_slice (conf->column_ranks_[LEFT]).contains (rounded_tip_pos) + || head_positions_slice (conf->column_ranks_[RIGHT]).contains (rounded_tip_pos) + || abs (rounded_tip_pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_)) + ) { conf->add_score (details_.staff_line_collision_penalty_ * peak_around (0.1 * details_.tip_staff_line_clearance_, diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 9acbe3beaf..2130dab4be 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -1823,7 +1823,7 @@ (height-limit . 1.0) (horizontal-distance-penalty-factor . 10) (same-dir-as-stem-penalty . 8) - (min-length-penalty-factor . 20) + (min-length-penalty-factor . 26) (tie-tie-collision-distance . 0.45) (tie-tie-collision-penalty . 25.0) (intra-space-threshold . 1.25) -- 2.39.5