]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/side-position-interface.cc
* The grand 2005-2006 replace.
[lilypond.git] / lily / side-position-interface.cc
index 454333156877c61ee763243259defa03472a7869..b60af41146dc350301e0bb1bd5713ab55c1b2cdf 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "side-position-interface.hh"
@@ -57,14 +57,11 @@ Side_position_interface::general_side_position (Grob *me, Axis a, bool use_exten
 
   Grob *common = common_refpoint_of_array (support, me->get_parent (a), a);
   Grob *staff_symbol = Staff_symbol_referencer::get_staff_symbol (me);
-  bool include_staff = false;
-
-  if (staff_symbol
-      && a == Y_AXIS)
-    {
-      if (scm_is_number (me->get_property ("staff-padding")))
-       include_staff = true;
-    }
+  bool include_staff = 
+    staff_symbol
+    && a == Y_AXIS
+    && scm_is_number (me->get_property ("staff-padding"))
+    && !to_boolean (me->get_property ("quantize-position"));
 
   Interval dim;
   Interval staff_extents;
@@ -106,8 +103,8 @@ Side_position_interface::general_side_position (Grob *me, Axis a, bool use_exten
       && total_off * dir < minimum_space)
     total_off = minimum_space * dir;
   
-  /* FIXME: 100CM should relate to paper size.  */
-  if (fabs (total_off) > 100 CM)
+  /* FIXME: 1000 should relate to paper size.  */
+  if (fabs (total_off) > 1000)
     {
       String msg
        = String_convert::form_string ("Improbable offset for grob %s: %f%s",
@@ -148,7 +145,7 @@ Side_position_interface::y_aligned_side (SCM smob)
 }
 
 SCM
-Side_position_interface::aligned_side (Grob*me, Axis a)
+Side_position_interface::aligned_side (Grob *me, Axis a)
 {
   Direction dir = get_grob_direction (me);
 
@@ -173,19 +170,6 @@ Side_position_interface::aligned_side (Grob*me, Axis a)
   Grob *staff = Staff_symbol_referencer::get_staff_symbol (me);
   if (staff && a == Y_AXIS)
     {
-      if (scm_is_number (me->get_property ("staff-padding")))
-       {
-         Real padding
-           = Staff_symbol_referencer::staff_space (me)
-           * scm_to_double (me->get_property ("staff-padding"));
-
-         Grob *common = me->common_refpoint (staff, Y_AXIS);
-
-         Interval staff_size = staff->extent (common, Y_AXIS);
-         Real diff = dir*staff_size[dir] + padding - dir * (o + iv[-dir]);
-         o += dir * max (diff, 0.0);
-       }
-      
       if (to_boolean (me->get_property ("quantize-position")))
        {
          Grob *common = me->common_refpoint (staff, Y_AXIS);
@@ -196,7 +180,7 @@ Side_position_interface::aligned_side (Grob*me, Axis a)
          Real rounded = directed_round (position, dir);
          Grob *head = me->get_parent (X_AXIS);
       
-         if (rounded <= Staff_symbol_referencer::staff_radius (me) 
+         if (rounded <= 2 * Staff_symbol_referencer::staff_radius (me) 
              || (Note_head::has_interface (head)
                  && sign (Staff_symbol_referencer::get_position (head)) == - dir))
            {
@@ -205,6 +189,18 @@ Side_position_interface::aligned_side (Grob*me, Axis a)
                o += dir * 0.5 * ss;
            }
        }
+      else if (scm_is_number (me->get_property ("staff-padding")))
+       {
+         Real padding
+           = Staff_symbol_referencer::staff_space (me)
+           * scm_to_double (me->get_property ("staff-padding"));
+
+         Grob *common = me->common_refpoint (staff, Y_AXIS);
+
+         Interval staff_size = staff->extent (common, Y_AXIS);
+         Real diff = dir*staff_size[dir] + padding - dir * (o + iv[-dir]);
+         o += dir * max (diff, 0.0);
+       }
     }
   return scm_from_double (o);
 }
@@ -212,24 +208,23 @@ Side_position_interface::aligned_side (Grob*me, Axis a)
 void
 Side_position_interface::set_axis (Grob *me, Axis a)
 {
-  add_offset_callback (me,
-                      (a==X_AXIS)
-                      ? x_aligned_side_proc
-                      : y_aligned_side_proc,
-                      a);
+  if (!scm_is_number (me->get_property ("side-axis")))
+    {
+      me->set_property ("side-axis", scm_from_int (a));
+      add_offset_callback (me,
+                          (a==X_AXIS)
+                          ? x_aligned_side_proc
+                          : y_aligned_side_proc,
+                          a);
+    }
 }
-
-// ugh. doesn't catch all variants. 
 Axis
 Side_position_interface::get_axis (Grob *me)
 {
-  if (me->get_property_data (ly_symbol2scm ("X-offset"))
-      == Side_position_interface::x_aligned_side_proc)
-    return X_AXIS;
-  else if (me->get_property_data (ly_symbol2scm ("Y-offset"))
-          == Side_position_interface::y_aligned_side_proc)
-    return Y_AXIS;
-
+  if (scm_is_number (me->get_property ("side-axis")))
+    return Axis (scm_to_int (me->get_property ("side-axis")));
+  
+  me->programming_error ("side-axis not set.");
   return NO_AXES;
 }
 
@@ -245,6 +240,7 @@ ADD_INTERFACE (Side_position_interface, "side-position-interface",
               "direction-source "
               "minimum-space "
               "padding "
+              "side-axis "
               "side-relative-direction "
               "side-support-elements "
               "slur-padding "