]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/align-interface.cc
* scm/define-music-types.scm (music-descriptions): remove
[lilypond.git] / lily / align-interface.cc
index 6faaa013c075f5f0345f1f6889e00eddfd2baca7..afe470251ccac043c57940e159483a4be3de383c 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))
@@ -89,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--;)
     {
@@ -116,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));
     }
 
   /*
@@ -144,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);
@@ -160,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]);
@@ -196,7 +207,7 @@ Align_interface::align_elements_to_extents (Grob *me, Axis a)
                                   : SCM_EOL,
                                   extra_space);
   
-  std::vector<Real> translates;
+  vector<Real> translates;
   for (vsize j = 0; j < elems.size (); j++)
     {
       Real dy = -dims[j][-stacking_dir];
@@ -233,28 +244,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)
 {