From 387a298cdf6e9a987e7bc4f8fc0db6a89d0f6d5a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benk=C5=91=20P=C3=A1l?= Date: Fri, 11 May 2012 17:50:29 +0200 Subject: [PATCH] Issue 2515: staff_radius fixes 1. implementation does not assume staff centred at zero 2. where used for determining whether within staff or not, use new function Staff_symbol_referencer::staff_span instead --- lily/include/staff-symbol-referencer.hh | 10 ++++++++++ lily/side-position-interface.cc | 4 +++- lily/slur-configuration.cc | 24 ++++++++++-------------- lily/staff-symbol-referencer.cc | 16 ++++++++++++++-- lily/tie-formatting-problem.cc | 24 +++++++++++++++--------- lily/tuplet-bracket.cc | 19 +++++++++---------- 6 files changed, 61 insertions(+), 36 deletions(-) diff --git a/lily/include/staff-symbol-referencer.hh b/lily/include/staff-symbol-referencer.hh index 179bae828f..79d07cfe7c 100644 --- a/lily/include/staff-symbol-referencer.hh +++ b/lily/include/staff-symbol-referencer.hh @@ -48,7 +48,17 @@ public: static int line_count (Grob *); static Real get_position (Grob *); static Real pure_get_position (Grob *); + + /** + Interval of staff lines. + */ + static Interval staff_span (Grob *); + + /** + Half of the height, in staff space, i.e. 2.0 for a normal staff. + */ static Real staff_radius (Grob *); + static int get_rounded_position (Grob *); static int pure_get_rounded_position (Grob *); static Interval extent_in_staff (Grob *); diff --git a/lily/side-position-interface.cc b/lily/side-position-interface.cc index 7cf332e85c..6fad89ea54 100644 --- a/lily/side-position-interface.cc +++ b/lily/side-position-interface.cc @@ -349,7 +349,9 @@ Side_position_interface::aligned_side (Grob *me, Axis a, bool pure, int start, i Real rounded = directed_round (position, dir); Grob *head = me->get_parent (X_AXIS); - if (fabs (position) <= 2 * Staff_symbol_referencer::staff_radius (me) + 1 + Interval staff_span = Staff_symbol::line_span (staff); + staff_span.widen (1); + if (staff_span.contains (position) /* In case of a ledger lines, quantize even if we're outside the staff. */ || (Note_head::has_interface (head) diff --git a/lily/slur-configuration.cc b/lily/slur-configuration.cc index d6d231de30..c446ca1a12 100644 --- a/lily/slur-configuration.cc +++ b/lily/slur-configuration.cc @@ -49,19 +49,15 @@ avoid_staff_line (Slur_score_state const &state, Real p = 2 * (y - staff->relative_coordinate (state.common_[Y_AXIS], Y_AXIS)) / state.staff_space_; - Real distance = fabs (my_round (p) - p); // in halfspaces - if (distance < 4 * state.thickness_ - && (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)) + Real const round = my_round (p); + Real const frac = p - round; + if (fabs (frac) < 4 * state.thickness_ + && Staff_symbol_referencer::on_staff_line (staff, int (round))) { - Direction resolution_dir - = (distance ? state.dir_ : Direction (sign (p - my_round (p)))); + Direction resolution_dir = frac ? state.dir_ : CENTER; // TODO: parameter - Real newp = my_round (p) + resolution_dir - * 5 * state.thickness_; + Real newp = round + resolution_dir * 5 * state.thickness_; Real dy = (newp - p) * state.staff_space_ / 2.0; @@ -278,11 +274,12 @@ Slur_configuration::score_encompass (Slur_score_state const &state) } add_score (demerit, "encompass"); - if (convex_head_distances.size ()) + if (vsize n = convex_head_distances.size ()) { Real avg_distance = 0.0; Real min_dist = infinity_f; - for (vsize j = 0; j < convex_head_distances.size (); j++) + + for (vsize j = 0; j < n; j++) { min_dist = min (min_dist, convex_head_distances[j]); avg_distance += convex_head_distances[j]; @@ -292,12 +289,11 @@ Slur_configuration::score_encompass (Slur_score_state const &state) For slurs over 3 or 4 heads, the average distance is not a good normalizer. */ - Real n = convex_head_distances.size (); if (n <= 2) { Real fact = 1.0; avg_distance += height_ * fact; - n += fact; + ++n; } /* diff --git a/lily/staff-symbol-referencer.cc b/lily/staff-symbol-referencer.cc index b18bb04fa3..3b8aa6ba18 100644 --- a/lily/staff-symbol-referencer.cc +++ b/lily/staff-symbol-referencer.cc @@ -189,11 +189,23 @@ Staff_symbol_referencer::internal_set_position (Grob *me, Real p, bool pure) me->translate_axis ((p - oldpos) * ss * 0.5, Y_AXIS); } -/* Half of the height, in staff space, i.e. 2.0 for a normal staff. */ +Interval +Staff_symbol_referencer::staff_span (Grob *me) +{ + Interval result; + if (me) + if (Grob *symb = get_staff_symbol (me)) + result = Staff_symbol::line_span (symb); + return result; +} + Real Staff_symbol_referencer::staff_radius (Grob *me) { - return (line_count (me) - 1) / 2.0; + /* + line_span is measured in pitch steps, not in staff spaces + */ + return staff_span (me).length () / 4.0; } int diff --git a/lily/tie-formatting-problem.cc b/lily/tie-formatting-problem.cc index d93df73abf..e2c3736f70 100644 --- a/lily/tie-formatting-problem.cc +++ b/lily/tie-formatting-problem.cc @@ -497,22 +497,25 @@ Tie_formatting_problem::generate_configuration (int pos, Direction dir, size. */ + Interval staff_span = + Staff_symbol_referencer::staff_span (details_.staff_symbol_referencer_); + staff_span.widen (-1); + bool const within_staff = staff_span.contains(pos); 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_)) + || within_staff) { if (h < details_.intra_space_threshold_ * 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)) + 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 if (within_staff) + { + conf->center_tie_vertically (details_); + } } else { @@ -718,9 +721,11 @@ Tie_formatting_problem::score_configuration (Tie_configuration *conf) const Real top_y = tip_y + conf->dir_ * height; Real top_pos = 2 * top_y / details_.staff_space_; Real round_top_pos = rint (top_pos); + Interval staff_span = + Staff_symbol_referencer::staff_span (details_.staff_symbol_referencer_); if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, int (round_top_pos)) - && Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_) > top_y) + && staff_span[UP] * 0.5 > top_y) { conf->add_score (details_.staff_line_collision_penalty_ * peak_around (0.1 * details_.center_staff_line_clearance_, @@ -730,10 +735,11 @@ Tie_formatting_problem::score_configuration (Tie_configuration *conf) const } int rounded_tip_pos = int (rint (tip_pos)); + staff_span.widen (-1); 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_)) + || staff_span.contains (rounded_tip_pos)) ) { conf->add_score (details_.staff_line_collision_penalty_ diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc index 37099683bf..643d07ae67 100644 --- a/lily/tuplet-bracket.cc +++ b/lily/tuplet-bracket.cc @@ -681,21 +681,20 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) /* horizontal brackets should not collide with staff lines. - Kind of pointless since we put them outside the staff anyway, but - let's leave code for the future when possibly allow them to move - into the staff once again. - This doesn't seem to support cross-staff tuplets atm. */ - if (*dy == 0 - && fabs (*offset) < ss * Staff_symbol_referencer::staff_radius (me)) + if (*dy == 0) { // quantize, then do collision check. - *offset *= 2 / ss; + *offset /= 0.5 * ss; - *offset = rint (*offset); - if (Staff_symbol_referencer::on_line (me, (int) rint (*offset))) - *offset += dir; + Interval staff_span = Staff_symbol_referencer::staff_span (me); + if (staff_span.contains (*offset)) + { + *offset = rint (*offset); + if (Staff_symbol_referencer::on_line (me, int (*offset))) + *offset += dir; + } *offset *= 0.5 * ss; } -- 2.39.2