X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Ftuplet-bracket.cc;h=261b086c3f4dea1605f3f9dab4c7aede94f8fbf6;hb=daffbcdf881ddacfb28c3f3ef67b83d7ca7dd843;hp=146499dbaa1f0e6b761dc4033b25897f29df659d;hpb=64313890b232c731d432e5b096f30bffc3f3756d;p=lilypond.git diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc index 146499dbaa..261b086c3f 100644 --- a/lily/tuplet-bracket.cc +++ b/lily/tuplet-bracket.cc @@ -44,6 +44,8 @@ #include "spanner.hh" #include "staff-symbol-referencer.hh" #include "lookup.hh" +#include "paper-column.hh" +#include "moment.hh" static Item * get_x_bound_item (Grob *me_grob, Direction hdir, Direction my_dir) @@ -64,15 +66,21 @@ flatten_number_pair_property (Grob *me, Direction xdir, SCM sym) { Drul_array zero (0, 0); - Drul_array pair = robust_scm2drul (me->internal_get_property (sym), zero); + Drul_array pair + = robust_scm2drul (me->internal_get_property (sym), zero); pair[xdir] = 0.0; - me->internal_set_property (sym, ly_interval2scm (pair)); + me->set_property (sym, ly_interval2scm (pair)); } +/* + Return beam that encompasses the span of the tuplet bracket. +*/ + Grob * -Tuplet_bracket::parallel_beam (Grob *me_grob, Link_array const &cols, bool *equally_long) +Tuplet_bracket::parallel_beam (Grob *me_grob, vector const &cols, + bool *equally_long) { Spanner *me = dynamic_cast (me_grob); @@ -105,7 +113,9 @@ Tuplet_bracket::parallel_beam (Grob *me_grob, Link_array const &cols, bool return 0; } - *equally_long = (beam_stems[0] == stems[LEFT] && beam_stems.back () == stems[RIGHT]); + *equally_long = + (beam_stems[0] == stems[LEFT] + && beam_stems.back () == stems[RIGHT]); return beams[LEFT]; } @@ -141,8 +151,7 @@ Tuplet_bracket::calc_connect_to_neighbors (SCM smob) connect_to_other[d] = (break_dir - && (neighbor_idx < orig_spanner->broken_intos_.size () - && neighbor_idx >= 0) + && neighbor_idx < orig_spanner->broken_intos_.size () && orig_spanner->broken_intos_[neighbor_idx]->is_live ()); } while (flip (&d) != LEFT); @@ -175,8 +184,15 @@ Tuplet_bracket::calc_control_points (SCM smob) extract_grob_set (me, "note-columns", columns); + SCM scm_positions = me->get_property ("positions"); + if (!me->is_live ()) + return SCM_EOL; + + if (!scm_is_pair (scm_positions)) + programming_error ("Positions should be number pair"); + Drul_array positions - = ly_scm2realdrul (me->get_property ("positions")); + = robust_scm2drul (scm_positions, Drul_array (0,0)); Grob *commonx = get_common_x (me); Direction dir = get_grob_direction (me); @@ -207,12 +223,16 @@ Tuplet_bracket::calc_control_points (SCM smob) x_span[d] = robust_relative_extent (bounds[d], commonx, X_AXIS)[RIGHT] - overshoot[LEFT]; } + else if (d == RIGHT && (columns.empty () || (bounds[d]->get_column () != dynamic_cast (columns.back ())->get_column ()))) { /* + We're connecting to a column, for the last bit of a broken + fullLength bracket. + TODO: make padding tunable? */ Real padding = 1.0; @@ -220,7 +240,9 @@ Tuplet_bracket::calc_control_points (SCM smob) if (bounds[d]->break_status_dir ()) padding = 0.0; - x_span[d] = robust_relative_extent (bounds[d], commonx, X_AXIS) [LEFT] - padding; + x_span[d] + = robust_relative_extent (bounds[d], commonx, X_AXIS) [LEFT] + - padding; } } while (flip (&d) != LEFT); @@ -398,8 +420,7 @@ Tuplet_bracket::make_bracket (Grob *me, // for line properties. Direction d = LEFT; do straight_corners[d] += -d * shorten[d] / length * dz; - while (flip (&d) != LEFT) - ; + while (flip (&d) != LEFT); if (gap.is_empty ()) gap = Interval (0, 0); @@ -439,16 +460,16 @@ Tuplet_bracket::get_bounds (Grob *me, Grob **left, Grob **right) while (l < columns.size () && Note_column::has_rests (columns[l])) l++; - int r = columns.size ()- 1; - while (r >= l && Note_column::has_rests (columns[r])) + vsize r = columns.size (); + while (r > l && Note_column::has_rests (columns[r-1])) r--; *left = *right = 0; - if (l <= r) + if (l < r) { *left = columns[l]; - *right = columns[r]; + *right = columns[r-1]; } } @@ -521,7 +542,7 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) Real x0 = robust_relative_extent (lgr, commonx, X_AXIS)[LEFT]; Real x1 = robust_relative_extent (rgr, commonx, X_AXIS)[RIGHT]; - std::vector points; + vector points; points.push_back (Offset (x0 - x0, staff[dir])); points.push_back (Offset (x1 - x0, staff[dir])); @@ -546,8 +567,12 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) Interval tuplet_x (tuplets[i]->extent (commonx, X_AXIS)); Interval tuplet_y (tuplets[i]->extent (commony, Y_AXIS)); + if (!tuplets[i]->is_live ()) + continue; + Direction d = LEFT; - Drul_array positions = ly_scm2realdrul (tuplets[i]->get_property ("positions")); + Drul_array positions = robust_scm2interval (tuplets[i]->get_property ("positions"), + Interval (0,0)); Real other_dy = positions[RIGHT] - positions[LEFT]; @@ -557,19 +582,11 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy) Real y = tuplet_y.linear_combination (d * sign (other_dy)); -#if 0 /* - Let's not take padding into account for nested tuplets. + We don't take padding into account for nested tuplets. the edges can come very close to the stems, likewise for nested tuplets? */ - Drul_array my_height - = robust_scm2drul (me->get_property ("edge-height"), - Interval (0, 0)); - if (dynamic_cast (tuplets[i])->get_bound (d) - == me->get_bound (d)) - y += dir * my_height[d]; -#endif points.push_back (Offset (tuplet_x[d] - x0, y)); } @@ -623,9 +640,20 @@ MAKE_SCHEME_CALLBACK (Tuplet_bracket, calc_positions, 1); SCM Tuplet_bracket::calc_positions (SCM smob) { - Grob *me = unsmob_grob (smob); + Spanner *me = unsmob_spanner (smob); extract_grob_set (me, "note-columns", columns); + /* + Don't print if it doesn't span time. + */ + if (robust_scm2moment (me->get_bound (LEFT)->get_column ()->get_property ("when"), Moment (0)) + == robust_scm2moment (me->get_bound (RIGHT)->get_column ()->get_property ("when"), Moment (0))) + { + me->suicide (); + return SCM_EOL; + } + + Direction dir = get_grob_direction (me); bool equally_long = false; Grob *par_beam = parallel_beam (me, columns, &equally_long); @@ -638,18 +666,29 @@ Tuplet_bracket::calc_positions (SCM smob) if (!par_beam || get_grob_direction (par_beam) != dir) calc_position_and_height (me, &offset, &dy); - else + else if (columns.size () + && Note_column::get_stem (columns[0]) + && Note_column::get_stem (columns.back ())) { - SCM ps = par_beam->get_property ("positions"); + /* + trigger set_stem_ends + */ + (void) par_beam->get_property ("quantized-positions"); - Real lp = scm_to_double (scm_car (ps)); - Real rp = scm_to_double (scm_cdr (ps)); - /* - duh. magic. - */ + Drul_array stems (Note_column::get_stem (columns[0]), + Note_column::get_stem (columns.back ())); + + + + + Real ss = 0.5 * Staff_symbol_referencer::staff_space (me); + Real lp = ss * robust_scm2double (stems[LEFT]->get_property ("stem-end-position"), 0.0); + Real rp = ss * robust_scm2double (stems[RIGHT]->get_property ("stem-end-position"), 0.0); + + offset = lp + dir * (0.5 + scm_to_double (me->get_property ("padding"))); - dy = rp - lp; + dy = (rp - lp); }