]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/rest-collision.cc
*** empty log message ***
[lilypond.git] / lily / rest-collision.cc
index 98151137c36894baa568dfc7f045cb09118d08ae..679a9426216c281185925314174da7c672a1ebd4 100644 (file)
@@ -6,14 +6,15 @@
   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#include "rest-collision.hh"
+
 #include <math.h>              // ceil.
 
 #include "warn.hh"
-#include "rest-collision.hh"
 #include "note-column.hh"
 #include "stem.hh"
 #include "rhythmic-head.hh"
-#include "paper-def.hh"
+#include "output-def.hh"
 #include "rest.hh"
 #include "group-interface.hh"
 #include "staff-symbol-referencer.hh"
@@ -25,18 +26,19 @@ SCM
 Rest_collision::force_shift_callback (SCM element_smob, SCM axis)
 {
   Grob *them = unsmob_grob (element_smob);
-  Axis a = (Axis) ly_scm2int (axis);
+  Axis a = (Axis) scm_to_int (axis);
   assert (a == Y_AXIS);
 
-  Grob * rc = unsmob_grob (them->get_property ("rest-collision"));
-
-  if (rc && !to_boolean (rc->get_property ("positioning-done")))
-    {
-      rc->set_property ("positioning-done", SCM_BOOL_T);
+  if (Note_column::has_rests (them))
+    {  
+      Grob * rc = unsmob_grob (them->get_property ("rest-collision"));
 
-      do_shift (rc);
-    }
-  
+      if (rc && !to_boolean (rc->get_property ("positioning-done")))
+       {
+         rc->set_property ("positioning-done", SCM_BOOL_T);
+         do_shift (rc);
+       }
+    }  
   return scm_make_real (0.0);
 }
 
@@ -59,20 +61,6 @@ Rest_collision::add_column (Grob*me,Grob *p)
 }
 
 
-/*
-  Combination of dot-count and duration-log.
- */
-static SCM
-head_characteristic (Grob * col)
-{
-  Grob * s = unsmob_grob (col->get_property ("rest"));
-
-  if (!s)
-    return SCM_BOOL_F;
-  else
-    return scm_cons (s->get_property ("duration-log"),
-                   scm_int2num (Rhythmic_head::dot_count (s)));
-}
 
 /*
   TODO: look at horizontal-shift to determine ordering between rests
@@ -87,9 +75,9 @@ Rest_collision::do_shift (Grob *me)
   Link_array<Grob> rests;
   Link_array<Grob> notes;
 
-  for (SCM s = elts; ly_c_pair_p (s); s = ly_cdr (s))
+  for (SCM s = elts; scm_is_pair (s); s = scm_cdr (s))
     {
-      Grob * e = unsmob_grob (ly_car (s));
+      Grob * e = unsmob_grob (scm_car (s));
       if (unsmob_grob (e->get_property ("rest")))
        {
          /*
@@ -150,9 +138,15 @@ Rest_collision::do_shift (Grob *me)
        ordered_rests[d].sort (Note_column::shift_compare);
       } while (flip (&d) != LEFT);
       
-      if (ordered_rests[UP].size () < 1
-         || ordered_rests[DOWN].size () < 1)
-       return SCM_UNSPECIFIED;
+      do {
+       if (ordered_rests[d].size () < 1)
+         {
+           if (ordered_rests[-d].size() > 1)
+             ordered_rests[-d][0]->warning (_ ("too many colliding rests"));
+         
+           return SCM_UNSPECIFIED;
+         }
+      } while (flip (&d) != LEFT);
 
       Grob *common = common_refpoint_of_array (ordered_rests[DOWN], me, Y_AXIS);
       common =  common_refpoint_of_array (ordered_rests[UP], common, Y_AXIS);
@@ -245,7 +239,7 @@ Rest_collision::do_shift (Grob *me)
 
 
 ADD_INTERFACE (Rest_collision,"rest-collision-interface",
-  "Move around ordinary rests (not multi-measure-rests) to avoid "
-"conflicts.",
-  "minimum-distance positioning-done elements");
+              "Move around ordinary rests (not multi-measure-rests) to avoid "
+              "conflicts.",
+              "minimum-distance positioning-done elements");