]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/align-interface.cc
remove break-algorithm.{cc,hh} as they are no longer used.
[lilypond.git] / lily / align-interface.cc
index 26d8d811438a8903a6945a1bd99e472afe762465..736ecb9096a51a48111595b51d938b74c896189a 100644 (file)
@@ -13,6 +13,8 @@
 #include "pointer-group-interface.hh"
 #include "hara-kiri-group-spanner.hh"
 #include "grob-array.hh"
+#include "international.hh"
+#include "warn.hh"
 
 /*
   TODO: for vertical spacing, should also include a rod & spring
@@ -27,7 +29,7 @@ Align_interface::calc_positioning_done (SCM smob)
 {
   Grob *me = unsmob_grob (smob);
   SCM axis = scm_car (me->get_property ("axes"));
-  Axis ax = (Axis)scm_to_int (axis);
+  Axis ax = Axis (scm_to_int (axis));
 
   SCM force = me->get_property ("forced-distance");
   if (scm_is_number (force))
@@ -49,6 +51,7 @@ Align_interface::stretch_after_break (SCM grob)
 
   Spanner *me_spanner = dynamic_cast<Spanner *> (me);
   extract_grob_set (me, "elements", elems);
+
   if (me_spanner && elems.size ())
     {
       Grob *common = common_refpoint_of_array (elems, me, Y_AXIS);
@@ -88,13 +91,13 @@ Align_interface::align_to_fixed_distance (Grob *me, Axis a)
 
   extract_grob_set (me, "elements", elem_source);
 
-  Link_array__Grob_ elems (elem_source); // writable..
+  vector<Grob*> elems (elem_source); // writable..
 
-  Real where_f = 0;
+  Real where = 0;
 
   Interval v;
   v.set_empty ();
-  std::vector<Real> translates;
+  vector<Real> translates;
 
   for (vsize j = elems.size (); j--;)
     {
@@ -115,9 +118,9 @@ Align_interface::align_to_fixed_distance (Grob *me, Axis a)
 
   for (vsize j = 0; j < elems.size (); j++)
     {
-      where_f += stacking_dir * dy;
-      translates.push_back (where_f);
-      v.unite (Interval (where_f, where_f));
+      where += stacking_dir * dy;
+      translates.push_back (where);
+      v.unite (Interval (where, where));
     }
 
   /*
@@ -143,15 +146,25 @@ Align_interface::align_to_fixed_distance (Grob *me, Axis a)
   align_to_fixed_distance ().
 */
 
-void
-Align_interface::align_elements_to_extents (Grob *me, Axis a)
+vector<Real>
+Align_interface::get_extents_aligned_translates (Grob *me,
+                                                vector<Grob*> const &all_grobs,
+                                                Axis a,
+                                                bool pure, int start, int end)
 {
   Spanner *me_spanner = dynamic_cast<Spanner *> (me);
 
 
   SCM line_break_details = SCM_EOL;
   if (a == Y_AXIS && me_spanner)
-    line_break_details =  me_spanner->get_bound (LEFT)->get_property ("line-break-system-details");
+    {
+      line_break_details = me_spanner->get_bound (LEFT)->get_property ("line-break-system-details");
+
+      if (!me->get_system () && !pure)
+       me->warning (_ ("vertical alignment called before line-breaking.\n"
+                       "Only do cross-staff spanners with PianoStaff."));
+
+    }
   
   Direction stacking_dir = robust_scm2dir (me->get_property ("stacking-dir"),
                                           DOWN);
@@ -159,13 +172,12 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a)
   Interval threshold = robust_scm2interval (me->get_property ("threshold"),
                                            Interval (0, Interval::infinity ()));
 
-  std::vector<Interval> dims;
-  Link_array__Grob_ elems;
+  vector<Interval> dims;
+  vector<Grob*> elems;
 
-  extract_grob_set (me, "elements", all_grobs);
   for (vsize i = 0; i < all_grobs.size (); i++)
     {
-      Interval y = all_grobs[i]->extent (me, a);
+      Interval y = all_grobs[i]->maybe_pure_extent (all_grobs[i], a, pure, start, end);
       if (!y.is_empty ())
        {
          Grob *e = dynamic_cast<Grob *> (all_grobs[i]);
@@ -194,8 +206,10 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a)
                                   ? scm_cdr (extra_space_handle)
                                   : SCM_EOL,
                                   extra_space);
-  
-  std::vector<Real> translates;
+
+  Real padding = robust_scm2double (me->get_property ("padding"),
+                                   0.0);
+  vector<Real> translates;
   for (vsize j = 0; j < elems.size (); j++)
     {
       Real dy = -dims[j][-stacking_dir];
@@ -209,17 +223,20 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a)
       if (j)
        dy = min (max (dy, threshold[SMALLER]), threshold[BIGGER]);
 
-      where += stacking_dir * (dy + extra_space / elems.size ());
+
+      where += stacking_dir * (dy + padding + extra_space / elems.size ());
       total.unite (dims[j] + where);
       translates.push_back (where);
     }
 
-  SCM offsets_handle = scm_assq (ly_symbol2scm ("alignment-offsets"), line_break_details);
+  SCM offsets_handle = scm_assq (ly_symbol2scm ("alignment-offsets"),
+                                line_break_details);
   if (scm_is_pair (offsets_handle))
     {
       vsize i = 0;
  
-      for (SCM s = scm_cdr (offsets_handle); scm_is_pair (s) && i < translates.size (); s = scm_cdr (s), i++)
+      for (SCM s = scm_cdr (offsets_handle);
+          scm_is_pair (s) && i < translates.size (); s = scm_cdr (s), i++)
        {
          if (scm_is_number (scm_car (s)))
            translates[i] = scm_to_double (scm_car (s));
@@ -232,28 +249,72 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a)
   /*
     also move the grobs that were empty, to maintain spatial order.
   */
-  std::vector<Real> all_translates;
+  vector<Real> all_translates;
   if (translates.size ())
     {
       Real w = translates[0];
+
+      if (scm_is_number (align))
+       center_offset = total.linear_combination (scm_to_double (align));
+
       for  (vsize i = 0, j = 0; j < all_grobs.size (); j++)
        {
          if (i < elems.size () && all_grobs[j] == elems[i])
            w = translates[i++];
-         all_translates.push_back (w);
+         all_translates.push_back (w - center_offset);
        }
+    }
+  return all_translates;
+}
 
-      /*
-       FIXME: uncommenting freaks out the Y-alignment of
-       line-of-score.
-      */
-      if (scm_is_number (align))
-       center_offset = total.linear_combination (scm_to_double (align));
+void
+Align_interface::align_elements_to_extents (Grob *me, Axis a)
+{
+  extract_grob_set (me, "elements", all_grobs);
 
+  vector<Real> translates = get_extents_aligned_translates (me, all_grobs, a, false, 0, 0);
+  if (translates.size ())
       for (vsize j = 0; j < all_grobs.size (); j++)
-       all_grobs[j]->translate_axis (all_translates[j] - center_offset, a);
+       all_grobs[j]->translate_axis (translates[j], a);
+}
+
+Real
+Align_interface::get_pure_child_y_translation (Grob *me, Grob *ch, int start, int end)
+{
+  extract_grob_set (me, "elements", all_grobs);
+  SCM dy_scm = me->get_property ("forced-distance");
+
+  if (scm_is_number (dy_scm))
+    {
+      Real dy = scm_to_double (dy_scm) * robust_scm2dir (me->get_property ("stacking-dir"), DOWN);
+      Real pos = 0;
+      for (vsize i = 0; i < all_grobs.size (); i++)
+       {
+         if (all_grobs[i] == ch)
+           return pos;
+         if (!Hara_kiri_group_spanner::has_interface (all_grobs[i])
+             || !Hara_kiri_group_spanner::request_suicide (all_grobs[i], start, end))
+           pos += dy;
+       }
+    }
+  else
+    {
+      vector<Real> translates = get_extents_aligned_translates (me, all_grobs, Y_AXIS, true, start, end);
+
+      if (translates.size ())
+       {
+         for (vsize i = 0; i < all_grobs.size (); i++)
+           if (all_grobs[i] == ch)
+             return translates[i];
+       }
+      else
+       return 0;
     }
+
+  programming_error (_ ("tried to get a translation for something that isn't my child"));
+  return 0;
 }
+
 Axis
 Align_interface::axis (Grob *me)
 {
@@ -267,7 +328,7 @@ Align_interface::add_element (Grob *me, Grob *element)
   SCM sym = axis_offset_symbol (a);
   SCM proc = axis_parent_positioning (a);
     
-  element->internal_set_property (sym, proc);
+  element->set_property (sym, proc);
   Axis_group_interface::add_element (me, element);
 }
 
@@ -319,12 +380,15 @@ ADD_INTERFACE (Align_interface,
               /*
                 properties
                */
+              "align-dir "
+              "axes "
+              "elements "
               "forced-distance "
+              "padding "
+              "positioning-done "
               "stacking-dir "
-              "align-dir "
               "threshold "
-              "positioning-done "
-              "elements axes");
+              );
 
 struct Foobar
 {