]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/side-position-interface.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / side-position-interface.cc
index b5844859f1df0fee4a069a9a6f826fbd0deed33f..4964c475727014e80f3795faaaa438ef1288786c 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"
@@ -14,8 +14,7 @@ using namespace std;
 
 #include "note-head.hh"
 #include "warn.hh"
-#include "warn.hh"
-#include "dimensions.hh"
+#include "main.hh"
 #include "staff-symbol-referencer.hh"
 #include "pointer-group-interface.hh"
 #include "directional-element-interface.hh"
@@ -27,7 +26,7 @@ using namespace std;
 void
 Side_position_interface::add_support (Grob *me, Grob *e)
 {
-  Pointer_group_interface::add_grob (me, ly_symbol2scm ("side-support-elements"), e);
+  Pointer_group_interface::add_unordered_grob (me, ly_symbol2scm ("side-support-elements"), e);
 }
 
 Direction
@@ -74,7 +73,7 @@ Side_position_interface::general_side_position (Grob *me, Axis a, bool use_exten
        dim.unite (staff_extents);
     }
 
-  for (int i = 0; i < support.size (); i++)
+  for (vsize i = 0; i < support.size (); i++)
     {
       Grob *e = support[i];
       if (e)
@@ -103,21 +102,23 @@ 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",
-                                      me->name ().to_str0 (), total_off,
-                                      INTERNAL_UNIT);
+      string msg
+       = String_convert::form_string ("Improbable offset for grob %s: %f",
+                                      me->name ().c_str (), total_off);
 
       programming_error (msg);
+      if (strict_infinity_checking)
+       scm_misc_error (__FUNCTION__, "Improbable offset.", SCM_EOL);
     }
   return scm_from_double (total_off);
 }
 
 
 MAKE_SCHEME_CALLBACK (Side_position_interface, y_aligned_on_support_refpoints, 1);
+
 SCM
 Side_position_interface::y_aligned_on_support_refpoints (SCM smob)
 {
@@ -145,7 +146,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);
 
@@ -179,13 +180,13 @@ Side_position_interface::aligned_side (Grob*me, Axis a)
          Real position = 2 * (my_off + o - staff_off) / ss;
          Real rounded = directed_round (position, dir);
          Grob *head = me->get_parent (X_AXIS);
-      
-         if (rounded <= Staff_symbol_referencer::staff_radius (me) 
+
+         if (fabs (position) <= 2 * Staff_symbol_referencer::staff_radius (me) + 1 
              || (Note_head::has_interface (head)
                  && sign (Staff_symbol_referencer::get_position (head)) == - dir))
            {
-             o += dir *(rounded - position) * 0.5 * ss;
-             if (Staff_symbol_referencer::on_staffline (me, int (rounded)))
+             o += (rounded - position) * 0.5 * ss;
+             if (Staff_symbol_referencer::on_line (me, int (rounded)))
                o += dir * 0.5 * ss;
            }
        }
@@ -208,24 +209,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;
 }
 
@@ -241,9 +241,10 @@ ADD_INTERFACE (Side_position_interface, "side-position-interface",
               "direction-source "
               "minimum-space "
               "padding "
+              "quantize-position "
+              "side-axis "
               "side-relative-direction "
               "side-support-elements "
               "slur-padding "
               "staff-padding "
-              "quantize-position "
               );