From 2bf0066ec032cdea3897dd66145c752b82ccb865 Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Fri, 30 Sep 2011 02:48:49 +0200 Subject: [PATCH] Stopes nested tuplets from colliding (issue 1855). Currently uses the `padding' property to space out nested tuplets. This is the same property used to space tuplets from other objects they encompass. --- input/regression/tuplet-nest-broken.ly | 53 ++++++++++++++++++++++++++ input/regression/tuplet-nest.ly | 16 +++++++- lily/include/tuplet-bracket.hh | 2 +- lily/tuplet-bracket.cc | 46 ++++++++++------------ lily/tuplet-number.cc | 42 +++++++++++++------- scm/define-grob-properties.scm | 3 ++ scm/define-grobs.scm | 6 ++- 7 files changed, 125 insertions(+), 43 deletions(-) create mode 100644 input/regression/tuplet-nest-broken.ly diff --git a/input/regression/tuplet-nest-broken.ly b/input/regression/tuplet-nest-broken.ly new file mode 100644 index 0000000000..06e105c207 --- /dev/null +++ b/input/regression/tuplet-nest-broken.ly @@ -0,0 +1,53 @@ + +\version "2.15.9" + +\header { + texidoc = "Broken nested tuplets avoid each other correctly. +" +} + +\paper { + ragged-right = ##t + indent = 0.0 +} + +\score { + \new Staff + << + \relative c'' { + \override Score . Beam #'breakable = ##t + + r2 + + \times 4/3 { + \times 2/3 { c8[ c c] } + \times 2/3 { c8[ c c] } + \times 2/3 { c8[ c c] } + } + + \times 4/3 { + \times 2/3 { a8[ a a] } + \times 2/3 { a8[ a a] } + \times 2/3 { a8[ a a] } + } + + \override TupletNumber #'text = #tuplet-number::calc-fraction-text + \times 4/6 { + \times 2/3 { + a4 a a + } + \times 3/5 { + a4 a a a a + } + a4 + } + r2 + } + { \repeat unfold 3 { s1 \break } } + >> + \layout { + \context { + \Voice \remove Forbid_line_break_engraver + } + } +} diff --git a/input/regression/tuplet-nest.ly b/input/regression/tuplet-nest.ly index dfdd543450..a0a1810398 100644 --- a/input/regression/tuplet-nest.ly +++ b/input/regression/tuplet-nest.ly @@ -11,13 +11,25 @@ } \relative c'' { + \times 4/3 { + \times 2/3 { c8[ c c] } + \times 2/3 { c8[ c c] } + \times 2/3 { c8[ c c] } + } + + \times 4/3 { + \times 2/3 { a8[ a a] } + \times 2/3 { a8[ a a] } + \times 2/3 { a8[ a a] } + } + \override TupletNumber #'text = #tuplet-number::calc-fraction-text \times 4/6 { \times 2/3 { - a a a + a4 a a } \times 3/5 { - a a a a a + a4 a a a a } } diff --git a/lily/include/tuplet-bracket.hh b/lily/include/tuplet-bracket.hh index ceeb7f3440..617758cc66 100644 --- a/lily/include/tuplet-bracket.hh +++ b/lily/include/tuplet-bracket.hh @@ -29,7 +29,7 @@ class Tuplet_bracket public: DECLARE_SCHEME_CALLBACK (calc_direction, (SCM)); DECLARE_SCHEME_CALLBACK (calc_positions, (SCM)); - DECLARE_SCHEME_CALLBACK (calc_control_points, (SCM)); + DECLARE_SCHEME_CALLBACK (calc_x_positions, (SCM)); DECLARE_SCHEME_CALLBACK (print, (SCM)); DECLARE_SCHEME_CALLBACK (calc_connect_to_neighbors, (SCM smob)); DECLARE_SCHEME_CALLBACK (calc_cross_staff, (SCM)); diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc index 627d6fcfb0..b2c67cbb18 100644 --- a/lily/tuplet-bracket.cc +++ b/lily/tuplet-bracket.cc @@ -51,6 +51,7 @@ #include "note-column.hh" #include "pointer-group-interface.hh" #include "directional-element-interface.hh" +#include "skyline.hh" #include "spanner.hh" #include "staff-symbol-referencer.hh" #include "lookup.hh" @@ -180,24 +181,13 @@ Tuplet_bracket::get_common_x (Spanner *me) return commonx; } -MAKE_SCHEME_CALLBACK (Tuplet_bracket, calc_control_points, 1) +MAKE_SCHEME_CALLBACK (Tuplet_bracket, calc_x_positions, 1) SCM -Tuplet_bracket::calc_control_points (SCM smob) +Tuplet_bracket::calc_x_positions (SCM smob) { Spanner *me = unsmob_spanner (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 - = robust_scm2drul (scm_positions, Drul_array (0, 0)); - Grob *commonx = get_common_x (me); Direction dir = get_grob_direction (me); @@ -254,9 +244,7 @@ Tuplet_bracket::calc_control_points (SCM smob) } while (flip (&d) != LEFT); - x_span -= me->get_bound (LEFT)->relative_coordinate (commonx, X_AXIS); - return scm_list_2 (ly_offset2scm (Offset (x_span[LEFT], positions[LEFT])), - ly_offset2scm (Offset (x_span[RIGHT], positions[RIGHT]))); + return ly_interval2scm (x_span - me->get_bound (LEFT)->relative_coordinate (commonx, X_AXIS)); } /* @@ -290,10 +278,11 @@ Tuplet_bracket::print (SCM smob) /* Don't print a tuplet bracket and number if - no control-points were calculated + no X or Y positions were calculated. */ - SCM cpoints = me->get_property ("control-points"); - if (scm_ilength (cpoints) < 2) + SCM scm_x_span = me->get_property ("X-positions"); + SCM scm_positions = me->get_property ("positions"); + if (!scm_is_pair (scm_x_span) || !scm_is_pair (scm_positions)) { me->suicide (); return SCM_EOL; @@ -307,12 +296,14 @@ Tuplet_bracket::print (SCM smob) == robust_scm2moment (me->get_bound (RIGHT)->get_column ()->get_property ("when"), Moment (0)))) bracket_visibility = false; - Drul_array points; - points[LEFT] = ly_scm2offset (scm_car (cpoints)); - points[RIGHT] = ly_scm2offset (scm_cadr (cpoints)); + Interval x_span = robust_scm2interval (scm_x_span, Interval (0.0, 0.0)); + Interval positions = robust_scm2interval (scm_positions, Interval (0.0, 0.0)); - Interval x_span (points[LEFT][X_AXIS], points[RIGHT][X_AXIS]); - Drul_array positions (points[LEFT][Y_AXIS], points[RIGHT][Y_AXIS]); + Drul_array points; + Direction d = LEFT; + do + points[d] = Offset (x_span[d], positions[d]); + while (flip (&d) != LEFT); Output_def *pap = me->layout (); @@ -657,6 +648,11 @@ 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) + points.push_back (Offset (number->extent (commonx, X_AXIS).center () - x0, + number->extent (commony, Y_AXIS)[dir])); } *offset = -dir * infinity_f; @@ -820,7 +816,6 @@ ADD_INTERFACE (Tuplet_bracket, "bracket-visibility " "break-overshoot " "connect-to-neighbor " - "control-points " "direction " "edge-height " "edge-text " @@ -835,4 +830,5 @@ ADD_INTERFACE (Tuplet_bracket, "staff-padding " "thickness " "tuplets " + "X-positions " ); diff --git a/lily/tuplet-number.cc b/lily/tuplet-number.cc index 2972942ee3..aaa862395d 100644 --- a/lily/tuplet-number.cc +++ b/lily/tuplet-number.cc @@ -28,8 +28,12 @@ struct Tuplet_number { DECLARE_SCHEME_CALLBACK (print, (SCM)); + DECLARE_SCHEME_CALLBACK (calc_x_offset, (SCM)); + DECLARE_SCHEME_CALLBACK (calc_y_offset, (SCM)); DECLARE_SCHEME_CALLBACK (calc_cross_staff, (SCM)); DECLARE_GROB_INTERFACE (); + + static Real calc_offset (Spanner *me, Axis a); }; MAKE_SCHEME_CALLBACK (Tuplet_number, print, 1); @@ -51,20 +55,32 @@ Tuplet_number::print (SCM smob) stc->align_to (X_AXIS, CENTER); stc->align_to (Y_AXIS, CENTER); - SCM cpoints = tuplet->get_property ("control-points"); - Drul_array points; - if (scm_is_pair (cpoints)) - { - points[LEFT] = ly_scm2offset (scm_car (cpoints)); - points[RIGHT] = ly_scm2offset (scm_cadr (cpoints)); - } - else - { - programming_error ("wrong type for control-points"); - } - stc->translate ((points[RIGHT] + points[LEFT]) / 2); + return stc->smobbed_copy (); +} + +MAKE_SCHEME_CALLBACK (Tuplet_number, calc_x_offset, 1); +SCM +Tuplet_number::calc_x_offset (SCM smob) +{ + Spanner *me = unsmob_spanner (smob); + Spanner *tuplet = unsmob_spanner (me->get_object ("bracket")); + + Interval x_positions = robust_scm2interval (tuplet->get_property ("X-positions"), Interval (0.0, 0.0)); + + return scm_from_double (x_positions.center ()); +} + +MAKE_SCHEME_CALLBACK (Tuplet_number, calc_y_offset, 1); +SCM +Tuplet_number::calc_y_offset (SCM smob) +{ + + Spanner *me = unsmob_spanner (smob); + Spanner *tuplet = unsmob_spanner (me->get_object ("bracket")); + + Interval positions = robust_scm2interval (tuplet->get_property ("positions"), Interval (0.0, 0.0)); - return stc_scm; + return scm_from_double (positions.center ()); } MAKE_SCHEME_CALLBACK (Tuplet_number, calc_cross_staff, 1) diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index a78ce0e9bb..eea44eed4d 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -939,6 +939,9 @@ texts.") (X-extent ,number-pair? "Hard coded extent in X@tie{}direction.") (X-offset ,number? "The horizontal amount that this object is moved relative to its X-parent.") + (X-positions ,number-pair? "Pair of X staff coordinates of a spanner +in the form @code{(@var{left} . @var{right})}, where both @var{left} and +@var{right} are in @code{staff-space} units of the current staff.") ;; diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index c8764e15e0..5e551acf8f 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -1187,7 +1187,6 @@ ;; a tuplet bracket. (connect-to-neighbor . ,ly:tuplet-bracket::calc-connect-to-neighbors) - (control-points . ,ly:tuplet-bracket::calc-control-points) (direction . ,UP) (edge-height . (0.7 . 0.7)) (padding . 2.0) @@ -1196,6 +1195,7 @@ (staff-padding . 0.25) (stencil . ,ly:tuplet-bracket::print) (thickness . 1.6) + (X-positions . ,ly:tuplet-bracket::calc-x-positions) (meta . ((class . Spanner) (interfaces . (line-interface tuplet-bracket-interface)))))) @@ -2347,7 +2347,6 @@ (TupletBracket . ( (connect-to-neighbor . ,ly:tuplet-bracket::calc-connect-to-neighbors) - (control-points . ,ly:tuplet-bracket::calc-control-points) (cross-staff . ,ly:tuplet-bracket::calc-cross-staff) (direction . ,ly:tuplet-bracket::calc-direction) (edge-height . (0.7 . 0.7)) @@ -2358,6 +2357,7 @@ (staff-padding . 0.25) (stencil . ,ly:tuplet-bracket::print) (thickness . 1.6) + (X-positions . ,ly:tuplet-bracket::calc-x-positions) (meta . ((class . Spanner) (interfaces . (line-interface @@ -2372,6 +2372,8 @@ (font-size . -2) (stencil . ,ly:tuplet-number::print) (text . ,tuplet-number::calc-denominator-text) + (X-offset . ,ly:tuplet-number::calc-x-offset) + (Y-offset . ,ly:tuplet-number::calc-y-offset) (meta . ((class . Spanner) (interfaces . (font-interface text-interface -- 2.39.2