X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftuplet-bracket.cc;h=d566027d2af5d2e82dc89c12e6e85cef7e0f4494;hb=ab3ab5538700b2ff12729ee3b14961a99d843731;hp=c682b67b48fe99954c19999442dd9aa38a76980b;hpb=49fbcc8b526edcad8a0650e9d7870b647c43d698;p=lilypond.git diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc index c682b67b48..d566027d2a 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--2011 Jan Nieuwenhuizen + Copyright (C) 1997--2012 Jan Nieuwenhuizen Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify @@ -41,6 +41,7 @@ */ #include "tuplet-bracket.hh" +#include "axis-group-interface.hh" #include "line-interface.hh" #include "beam.hh" #include "warn.hh" @@ -105,10 +106,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 ())) @@ -139,8 +138,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 ()); @@ -160,7 +158,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]), @@ -200,10 +197,9 @@ 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] = 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]) { @@ -213,8 +209,9 @@ Tuplet_bracket::calc_x_positions (SCM smob) if (d == RIGHT) x_span[d] += d * overshoot[d]; else - x_span[d] = robust_relative_extent (bounds[d], - commonx, X_AXIS)[RIGHT] + 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]) - overshoot[LEFT]; } @@ -242,7 +239,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)); } @@ -300,10 +296,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 (); @@ -348,8 +342,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]) { @@ -377,7 +370,6 @@ Tuplet_bracket::print (SCM smob) } } } - while (flip (&d) != LEFT); Stencil brack = make_bracket (me, Y_AXIS, points[RIGHT] - points[LEFT], @@ -389,12 +381,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); } @@ -427,29 +418,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], @@ -459,8 +446,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])); @@ -548,8 +533,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])) @@ -557,7 +541,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])); @@ -627,14 +610,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)); @@ -647,7 +629,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) @@ -655,6 +637,33 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) number->extent (commony, Y_AXIS)[dir])); } + if (to_boolean (me->get_property ("avoid-scripts")) + && !scm_is_number (me->get_property ("outside-staff-priority"))) + { + extract_grob_set (me, "scripts", scripts); + for (vsize i = 0; i < scripts.size (); i++) + { + if (!scripts[i]->is_live ()) + continue; + 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 + SCM avoid = scripts[i]->get_property ("avoid-slur"); + if (unsmob_grob (scripts[i]->get_object ("slur")) + && (avoid == ly_symbol2scm ("outside") + || avoid == ly_symbol2scm ("around"))) + continue; + + Interval script_x (scripts[i]->extent (commonx, X_AXIS)); + Interval script_y (scripts[i]->extent (commony, Y_AXIS)); + + points.push_back (Offset (script_x.center () - x0, + script_y[dir])); + } + } + *offset = -dir * infinity_f; Real factor = (columns.size () > 1) ? 1 / (x1 - x0) : 1.0; for (vsize i = 0; i < points.size (); i++) @@ -671,21 +680,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; } @@ -749,10 +757,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; } @@ -767,6 +773,12 @@ Tuplet_bracket::add_column (Grob *me, Item *n) add_bound_item (dynamic_cast (me), n); } +void +Tuplet_bracket::add_script (Grob *me, Item *s) +{ + Pointer_group_interface::add_grob (me, ly_symbol2scm ("scripts"), s); +} + void Tuplet_bracket::add_tuplet_bracket (Grob *me, Grob *bracket) { @@ -812,6 +824,7 @@ ADD_INTERFACE (Tuplet_bracket, " @code{edge-text} are printed at the edges.", /* properties */ + "avoid-scripts " "bracket-flare " "bracket-visibility " "break-overshoot "