X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftuplet-bracket.cc;h=04e67fbdecd781138e098877c997ec78b69c8daa;hb=c39d188d28fdc84cef8cbaea7b8d6e2fb718c30f;hp=40e0c728c5ef2c353de391bd5da025386bce7007;hpb=a00fa3d9a28af688cf3bf3dcc8636f2e0cb39117;p=lilypond.git diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc index 40e0c728c5..04e67fbdec 100644 --- a/lily/tuplet-bracket.cc +++ b/lily/tuplet-bracket.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1997--2012 Jan Nieuwenhuizen + Copyright (C) 1997--2014 Jan Nieuwenhuizen Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify @@ -92,8 +92,10 @@ Tuplet_bracket::parallel_beam (Grob *me_grob, vector const &cols, { Spanner *me = dynamic_cast (me_grob); - if (me->get_bound (LEFT)->break_status_dir () - || me->get_bound (RIGHT)->break_status_dir ()) + Item *left = me->get_bound (LEFT); + Item *right = me->get_bound (RIGHT); + if (!left || left->break_status_dir () + || !right || right->break_status_dir ()) return 0; Drul_array stems (Note_column::get_stem (cols[0]), @@ -106,10 +108,8 @@ Tuplet_bracket::parallel_beam (Grob *me_grob, vector const &cols, return 0; Drul_array beams; - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) beams[d] = stems[d] ? Stem::get_beam (stems[d]) : 0; - while (flip (&d) != LEFT); *equally_long = false; if (! (beams[LEFT] && (beams[LEFT] == beams[RIGHT]) && !me->is_broken ())) @@ -140,8 +140,7 @@ Tuplet_bracket::calc_connect_to_neighbors (SCM smob) get_x_bound_item (me, RIGHT, dir)); Drul_array connect_to_other (false, false); - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) { Direction break_dir = bounds[d]->break_status_dir (); Spanner *orig_spanner = dynamic_cast (me->original ()); @@ -161,7 +160,6 @@ Tuplet_bracket::calc_connect_to_neighbors (SCM smob) && neighbor_idx < orig_spanner->broken_intos_.size () && orig_spanner->broken_intos_[neighbor_idx]->is_live ()); } - while (flip (&d) != LEFT); if (connect_to_other[LEFT] || connect_to_other[RIGHT]) return scm_cons (scm_from_bool (connect_to_other[LEFT]), @@ -201,12 +199,10 @@ Tuplet_bracket::calc_x_positions (SCM smob) Drul_array (false, false)); Interval x_span; - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) { - x_span[d] = bounds[d]->break_status_dir () - ? Axis_group_interface::generic_bound_extent (bounds[d], commonx, X_AXIS)[d] - : robust_relative_extent (bounds[d], commonx, X_AXIS)[d]; + x_span[d] = Axis_group_interface::generic_bound_extent (bounds[d], commonx, X_AXIS)[d]; + if (connect_to_other[d]) { Interval overshoot (robust_scm2drul (me->get_property ("break-overshoot"), @@ -216,8 +212,8 @@ Tuplet_bracket::calc_x_positions (SCM smob) x_span[d] += d * overshoot[d]; else x_span[d] = (bounds[d]->break_status_dir () - ? Axis_group_interface::generic_bound_extent (bounds[d], commonx, X_AXIS)[-d] - : robust_relative_extent (bounds[d], commonx, X_AXIS)[-d]) + ? Axis_group_interface::generic_bound_extent (bounds[d], commonx, X_AXIS)[-d] + : robust_relative_extent (bounds[d], commonx, X_AXIS)[-d]) - overshoot[LEFT]; } @@ -245,7 +241,6 @@ Tuplet_bracket::calc_x_positions (SCM smob) x_span[d] = coord - padding; } } - while (flip (&d) != LEFT); return ly_interval2scm (x_span - me->get_bound (LEFT)->relative_coordinate (commonx, X_AXIS)); } @@ -303,10 +298,8 @@ Tuplet_bracket::print (SCM smob) Interval positions = robust_scm2interval (scm_positions, Interval (0.0, 0.0)); Drul_array points; - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) points[d] = Offset (x_span[d], positions[d]); - while (flip (&d) != LEFT); Output_def *pap = me->layout (); @@ -351,8 +344,7 @@ Tuplet_bracket::print (SCM smob) = robust_scm2booldrul (me->get_property ("connect-to-neighbor"), Drul_array (false, false)); - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) { if (connect_to_other[d]) { @@ -380,7 +372,6 @@ Tuplet_bracket::print (SCM smob) } } } - while (flip (&d) != LEFT); Stencil brack = make_bracket (me, Y_AXIS, points[RIGHT] - points[LEFT], @@ -392,12 +383,11 @@ Tuplet_bracket::print (SCM smob) Interval (-0.5, 0.5) * gap + 0.1, flare, shorten); - do + for (LEFT_and_RIGHT (d)) { if (!edge_stencils[d].is_empty ()) brack.add_stencil (edge_stencils[d]); } - while (flip (&d) != LEFT); mol.add_stencil (brack); } @@ -430,29 +420,25 @@ Tuplet_bracket::make_bracket (Grob *me, // for line properties. Drul_array straight_corners = corners; - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) straight_corners[d] += -d * shorten[d] / length * dz; - while (flip (&d) != LEFT); if (!gap.is_empty ()) { - do + for (LEFT_and_RIGHT (d)) gap_corners[d] = (dz * 0.5) + gap[d] / length * dz; - while (flip (&d) != LEFT); } Drul_array flare_corners = straight_corners; - do + for (LEFT_and_RIGHT (d)) { flare_corners[d][bracket_axis] = straight_corners[d][bracket_axis]; flare_corners[d][protrusion_axis] += height[d]; straight_corners[d][bracket_axis] += -d * flare[d]; } - while (flip (&d) != LEFT); Stencil m; - do + for (LEFT_and_RIGHT (d)) { if (!gap.is_empty ()) m.add_stencil (Line_interface::line (me, straight_corners[d], @@ -462,8 +448,6 @@ Tuplet_bracket::make_bracket (Grob *me, // for line properties. flare_corners[d])); } - while (flip (&d) != LEFT); - if (gap.is_empty ()) m.add_stencil (Line_interface::line (me, straight_corners[LEFT], straight_corners[RIGHT])); @@ -539,7 +523,7 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) Real x1 = robust_relative_extent (rgr, commonx, X_AXIS)[RIGHT]; bool follow_beam = par_beam && get_grob_direction (par_beam) == dir - && !to_boolean (par_beam->get_property ("knee")); + && !Beam::is_knee (par_beam); vector points; if (columns.size () @@ -551,8 +535,7 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) Note_column::get_stem (columns.back ())); Interval poss; - Direction side = LEFT; - do + for (LEFT_and_RIGHT (side)) { // Trigger setting of stem lengths if necessary. if (Grob *beam = Stem::get_beam (stems[side])) @@ -560,7 +543,6 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) poss[side] = stems[side]->extent (stems[side], Y_AXIS)[get_grob_direction (stems[side])] + stems[side]->get_parent (Y_AXIS)->relative_coordinate (commony, Y_AXIS); } - while (flip (&side) != LEFT); *dy = poss[RIGHT] - poss[LEFT]; points.push_back (Offset (stems[LEFT]->relative_coordinate (commonx, X_AXIS) - x0, poss[LEFT])); @@ -630,14 +612,13 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) if (!tuplets[i]->is_live ()) continue; - Direction d = LEFT; Drul_array positions = robust_scm2interval (tuplets[i]->get_property ("positions"), Interval (0, 0)); Real other_dy = positions[RIGHT] - positions[LEFT]; - do + for (LEFT_and_RIGHT (d)) { Real y = tuplet_y.linear_combination (d * sign (other_dy)); @@ -650,7 +631,7 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) points.push_back (Offset (tuplet_x[d] - x0, y)); } - while (flip (&d) != LEFT); + // Check for number-on-bracket collisions Grob *number = unsmob_grob (tuplets[i]->get_object ("tuplet-number")); if (number) @@ -669,6 +650,11 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) if (scm_is_number (scripts[i]->get_property ("outside-staff-priority"))) continue; + // assume that if a script is avoiding slurs, it should not get placed + // under a tuplet bracket + if (unsmob_grob (scripts[i]->get_object ("slur"))) + continue; + Interval script_x (scripts[i]->extent (commonx, X_AXIS)); Interval script_y (scripts[i]->extent (commony, Y_AXIS)); @@ -693,21 +679,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; } @@ -771,10 +756,8 @@ Tuplet_bracket::get_default_dir (Grob *me) Direction d = Note_column::dir (columns[i]); extremal_positions[d] = minmax (d, 1.0 * Note_column::head_positions_interval (columns[i])[d], extremal_positions[d]); } - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) extremal_positions[d] = -d * (staff_extent[d] - extremal_positions[d]); - while (flip (&d) != LEFT); return extremal_positions[UP] <= extremal_positions[DOWN] ? UP : DOWN; }