]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tuplet-bracket.cc
Merge remote-tracking branch 'origin/translation'
[lilypond.git] / lily / tuplet-bracket.cc
index 478d53bb2a4bea9c8b1e617aed56c32cf9b8b9ef..f4b4456812d0c45130a446d894cba119be12903f 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1997--2011 Jan Nieuwenhuizen <janneke@gnu.org>
+  Copyright (C) 1997--2014 Jan Nieuwenhuizen <janneke@gnu.org>
   Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   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"
@@ -91,8 +92,10 @@ Tuplet_bracket::parallel_beam (Grob *me_grob, vector<Grob *> const &cols,
 {
   Spanner *me = dynamic_cast<Spanner *> (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<Grob *> stems (Note_column::get_stem (cols[0]),
@@ -105,10 +108,8 @@ Tuplet_bracket::parallel_beam (Grob *me_grob, vector<Grob *> const &cols,
     return 0;
 
   Drul_array<Grob *> 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 +140,7 @@ Tuplet_bracket::calc_connect_to_neighbors (SCM smob)
                              get_x_bound_item (me, RIGHT, dir));
 
   Drul_array<bool> 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<Spanner *> (me->original ());
@@ -160,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]),
@@ -200,10 +199,9 @@ Tuplet_bracket::calc_x_positions (SCM smob)
                            Drul_array<bool> (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 +211,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 +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));
 }
@@ -300,10 +298,8 @@ Tuplet_bracket::print (SCM smob)
   Interval positions = robust_scm2interval (scm_positions, Interval (0.0, 0.0));
 
   Drul_array<Offset> 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 +344,7 @@ Tuplet_bracket::print (SCM smob)
         = robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
                                Drul_array<bool> (false, false));
 
-      Direction d = LEFT;
-      do
+      for (LEFT_and_RIGHT (d))
         {
           if (connect_to_other[d])
             {
@@ -377,7 +372,6 @@ Tuplet_bracket::print (SCM smob)
                 }
             }
         }
-      while (flip (&d) != LEFT);
 
       Stencil brack = make_bracket (me, Y_AXIS,
                                     points[RIGHT] - points[LEFT],
@@ -389,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);
     }
@@ -427,29 +420,25 @@ Tuplet_bracket::make_bracket (Grob *me, // for line properties.
 
   Drul_array<Offset> 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<Offset> 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 +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]));
@@ -548,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]))
@@ -557,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]));
@@ -627,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<Real> 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 +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)
@@ -655,13 +639,21 @@ 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")))
+  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
+          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));
@@ -687,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;
     }
@@ -765,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;
     }