]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/rest-collision.cc
*** empty log message ***
[lilypond.git] / lily / rest-collision.cc
index a0f7e744913840dc110440a3fc7fb3f762361c01..c815db634efbd875f3576f7969c4a969f54b4d76 100644 (file)
@@ -28,11 +28,11 @@ Rest_collision::force_shift_callback (SCM element_smob, SCM axis)
   Axis a = (Axis) gh_scm2int (axis);
   assert (a == Y_AXIS);
 
-  Grob * rc = unsmob_grob (them->get_grob_property ("rest-collision"));
+  Grob * rc = unsmob_grob (them->get_property ("rest-collision"));
 
-  if (rc && !to_boolean (rc->get_grob_property ("positioning-done")))
+  if (rc && !to_boolean (rc->get_property ("positioning-done")))
     {
-      rc->set_grob_property ("positioning-done", SCM_BOOL_T);
+      rc->set_property ("positioning-done", SCM_BOOL_T);
 
       do_shift (rc);
     }
@@ -55,7 +55,7 @@ Rest_collision::add_column (Grob*me,Grob *p)
     (not?)
   */
   p->add_offset_callback (Rest_collision::force_shift_callback_proc, Y_AXIS);
-  p->set_grob_property ("rest-collision", me->self_scm ());
+  p->set_property ("rest-collision", me->self_scm ());
 }
 
 
@@ -65,27 +65,24 @@ Rest_collision::add_column (Grob*me,Grob *p)
 static SCM
 head_characteristic (Grob * col)
 {
-  Grob * s = unsmob_grob (col->get_grob_property ("rest"));
+  Grob * s = unsmob_grob (col->get_property ("rest"));
 
   if (!s)
     return SCM_BOOL_F;
   else
-    return gh_cons (s->get_grob_property ("duration-log"),
+    return gh_cons (s->get_property ("duration-log"),
                    gh_int2scm (Rhythmic_head::dot_count (s)));
 }
 
 /*
-  TODO: fixme, fucks up if called twice on the same set of rests.
-
   TODO: look at horizontal-shift to determine ordering between rests
   for more than two voices.
-
   
  */
 SCM
 Rest_collision::do_shift (Grob *me)
 {
-  SCM elts = me->get_grob_property ("elements");
+  SCM elts = me->get_property ("elements");
 
   Link_array<Grob> rests;
   Link_array<Grob> notes;
@@ -93,13 +90,13 @@ Rest_collision::do_shift (Grob *me)
   for (SCM s = elts; gh_pair_p (s); s = ly_cdr (s))
     {
       Grob * e = unsmob_grob (ly_car (s));
-      if (unsmob_grob (e->get_grob_property ("rest")))
+      if (unsmob_grob (e->get_property ("rest")))
        {
          /*
            Ignore rests under beam.
           */
-         Grob* st = unsmob_grob (e->get_grob_property ("stem"));
-         if (st && unsmob_grob (st->get_grob_property ("beam")))
+         Grob* st = unsmob_grob (e->get_property ("stem"));
+         if (st && unsmob_grob (st->get_property ("beam")))
            continue;
          
          rests.push (e);
@@ -195,17 +192,27 @@ Rest_collision::do_shift (Grob *me)
        {
          warning (_ ("too many colliding rests"));
        }
-      Grob * rcol = rests[0];
-      Grob *common = common_refpoint_of_array (notes, rcol, Y_AXIS);
+      Grob * rcol = 0;
+      Direction dir = CENTER;
+
+      for (int i= rests.size (); !rcol && i--;)
+       if (Note_column::dir (rests[i]))
+         {
+           dir = Note_column::dir (rests[i]);
+           rcol = rests[i];
+         }
+
+      if (!rcol)
+       return SCM_UNSPECIFIED;
       
-      Direction dir = Note_column::dir (rests[0]);
+      Grob *common = common_refpoint_of_array (notes, rcol, Y_AXIS);
       
       Interval restdim = rcol->extent (common, Y_AXIS);
       if (restdim.is_empty ())
        return SCM_UNSPECIFIED;
       
       Real staff_space = Staff_symbol_referencer::staff_space (rcol);
-      Real minimum_dist = robust_scm2double (me->get_grob_property ("minimum-distance"), 1.0) * staff_space;
+      Real minimum_dist = robust_scm2double (me->get_property ("minimum-distance"), 1.0) * staff_space;
 
       Interval notedim;
       for (int i = 0; i < notes.size (); i++) 
@@ -239,5 +246,5 @@ Rest_collision::do_shift (Grob *me)
 ADD_INTERFACE (Rest_collision,"rest-collision-interface",
   "Move around ordinary rests (not multi-measure-rests) to avoid "
 "conflicts.",
-  "maximum-rest-count minimum-distance positioning-done elements");
+  "minimum-distance positioning-done elements");