lilypond-devel
[Top][All Lists]

## Prevents nested tuplets from colliding. (issue4808082)

 From: mtsolo Subject: Prevents nested tuplets from colliding. (issue4808082) Date: Mon, 08 Aug 2011 19:21:08 +0000

Reviewers: ,

Message:
This fixes Issue 509 and passes regtests.

Cheers,
MS

Description:
Prevents nested tuplets from colliding.

Affected files:
M input/regression/tuplet-nest.ly
M lily/tuplet-bracket.cc
M scm/define-grob-properties.scm
M scm/define-grobs.scm

Index: input/regression/tuplet-nest.ly

diff --git a/input/regression/tuplet-nest.ly b/input/regression/tuplet-nest.ly index dfdd543450bf13c3793e3b29671dd2213db49f61..f3a4a587f9f1c4f42e12dc5387dedc3d3345f8ff 100644
--- a/input/regression/tuplet-nest.ly
+++ b/input/regression/tuplet-nest.ly
@@ -11,10 +11,22 @@
}

\relative c'' {
+  \times 4/3 {
+    \times 2/3 { c8 [c8 c8 ]}
+    \times 2/3 { c8 [c8 c8 ]}
+    \times 2/3 { c8 [c8 c8 ]}
+  }
+
+  \times 4/3 {
+    \times 2/3 { a8 [a8 a8 ]}
+    \times 2/3 { a8 [a8 a8 ]}
+    \times 2/3 { a8 [a8 a8 ]}
+  }
+
\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
Index: lily/tuplet-bracket.cc
diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc

index c6dfa799924a5c4b169406cf26854c1b865d0f24..c97be7ef7d0f9bd5fe7234a38a09d293d0bcdea9 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"

@@ -656,6 +657,10 @@ 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).center ()));
     }

*offset = -dir * infinity_f;

@@ -671,6 +676,34 @@ Tuplet_bracket::calc_position_and_height (Grob *me_grob, Real *offset, Real *dy)

*offset += scm_to_double (me->get_property ("padding")) * dir;

+  // have to re_run numbers to check for number-on-number collisions
+  Grob *my_number = unsmob_grob (me->get_object ("tuplet-number"));
+  if (my_number)
+    {
+      /*

+ Slightly kludgy, as it centers the number as it would be in ly:tuplet-number::stencil + If this function is over-ridden, this may lead to bizarre results...
+      */

+ Stencil *my_number_stencil = unsmob_stencil (Text_interface::print (me->get_object ("tuplet-number"))); + Real base_line = minmax (dir, *offset, *offset + *dy) + dir * fabs (*dy) / 2;
+      Real sten_len = my_number_stencil->extent (Y_AXIS).length () / 2;

+ Box my_number_box = Box (my_number_stencil->extent (X_AXIS), Interval (base_line - sten_len, base_line + sten_len)); + my_number_box[X_AXIS] = my_number_box[X_AXIS] + x0 + (x1 - x0) / 2 - my_number_box[X_AXIS].length () / 2;
+      Skyline my_number_skyline (my_number_box, 0.0, X_AXIS, -dir);
+      vector<Box> their_number_boxes;
+      for (vsize i = 0; i < tuplets.size (); i++)
+        {

+ Grob *her_number = unsmob_grob (tuplets[i]->get_object ("tuplet-number"));
+          if (her_number)

+ their_number_boxes.push_back (Box (her_number->extent (commonx, X_AXIS), her_number->extent (commony, Y_AXIS)));
+        }
+      Skyline their_numbers_skyline (their_number_boxes, 0.0, X_AXIS, dir);
+      Real dist = my_number_skyline.distance (their_numbers_skyline);

+
+        *offset += dir * (dist + tuplet_number_padding);
+    }
/*
horizontal brackets should not collide with staff lines.

@@ -830,6 +863,7 @@ ADD_INTERFACE (Tuplet_bracket,
"note-columns "
"tuplet-number "
"shorten-pair "
"thickness "
Index: scm/define-grob-properties.scm
diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm

--- a/scm/define-grob-properties.scm
+++ b/scm/define-grob-properties.scm

@@ -896,6 +896,8 @@ toward the stem if their direction coincides with the stem direction.
 head), @code{1.0} means centered on the stem.  Interpolated values are
possible.")
(transparent ,boolean? "This makes the grob invisible.")
+numbers.")

;;
Index: scm/define-grobs.scm
diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm

index 4545e5bd9f6f7c130267397d3947812e31c82881..df5dbeaf6e2ce6bede405b45f36f8b10e6c99cd1 100644
--- a/scm/define-grobs.scm
+++ b/scm/define-grobs.scm
@@ -2339,6 +2339,7 @@
(stencil . ,ly:tuplet-bracket::print)
(thickness . 1.6)