]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/rest-collision.cc
* lily/midi-item.cc (name): new method.
[lilypond.git] / lily / rest-collision.cc
index bcc8a8545a12669111cfc943c4433ff7af0520ab..8ad587e88bd91a4b1a205821e38091b43780cec7 100644 (file)
@@ -16,7 +16,7 @@
 #include "rhythmic-head.hh"
 #include "output-def.hh"
 #include "rest.hh"
-#include "group-interface.hh"
+#include "pointer-group-interface.hh"
 #include "staff-symbol-referencer.hh"
 #include "duration.hh"
 #include "directional-element-interface.hh"
@@ -26,12 +26,12 @@ SCM
 Rest_collision::force_shift_callback (SCM element_smob, SCM axis)
 {
   Grob *them = unsmob_grob (element_smob);
-  Axis a = (Axis) scm_to_int (axis);
-  assert (a == Y_AXIS);
+  (void) axis;
+  assert (scm_to_int (axis) == Y_AXIS);
 
   if (Note_column::has_rests (them))
     {
-      Grob *rc = unsmob_grob (them->get_property ("rest-collision"));
+      Grob *rc = unsmob_grob (them->get_object ("rest-collision"));
 
       if (rc && !to_boolean (rc->get_property ("positioning-done")))
        {
@@ -39,7 +39,7 @@ Rest_collision::force_shift_callback (SCM element_smob, SCM axis)
          do_shift (rc);
        }
     }
-  return scm_make_real (0.0);
+  return scm_from_double (0.0);
 }
 
 MAKE_SCHEME_CALLBACK (Rest_collision, force_shift_callback_rest, 2);
@@ -53,7 +53,7 @@ Rest_collision::force_shift_callback_rest (SCM rest, SCM axis)
   if (Note_column::has_interface (parent))
     return force_shift_callback (parent->self_scm (), axis);
   else
-    return scm_make_real (0.0);
+    return scm_from_double (0.0);
 }
 
 void
@@ -69,9 +69,9 @@ Rest_collision::add_column (Grob *me, Grob *p)
     (not?)
   */
   p->add_offset_callback (Rest_collision::force_shift_callback_proc, Y_AXIS);
-  p->set_property ("rest-collision", me->self_scm ());
+  p->set_object ("rest-collision", me->self_scm ());
 
-  Grob *rest = unsmob_grob (p->get_property ("rest"));
+  Grob *rest = unsmob_grob (p->get_object ("rest"));
   if (rest)
     {
       rest->add_offset_callback (Rest_collision::force_shift_callback_rest_proc,
@@ -86,21 +86,21 @@ Rest_collision::add_column (Grob *me, Grob *p)
 SCM
 Rest_collision::do_shift (Grob *me)
 {
-  SCM elts = me->get_property ("elements");
+  extract_grob_set (me, "elements", elts);
 
   Link_array<Grob> rests;
   Link_array<Grob> notes;
 
-  for (SCM s = elts; scm_is_pair (s); s = scm_cdr (s))
+  for (int i = 0; i < elts.size (); i++)
     {
-      Grob *e = unsmob_grob (scm_car (s));
-      if (unsmob_grob (e->get_property ("rest")))
+      Grob *e = elts[i];
+      if (unsmob_grob (e->get_object ("rest")))
        {
          /*
            Ignore rests under beam.
          */
-         Grob *st = unsmob_grob (e->get_property ("stem"));
-         if (st && unsmob_grob (st->get_property ("beam")))
+         Grob *st = unsmob_grob (e->get_object ("stem"));
+         if (st && unsmob_grob (st->get_object ("beam")))
            continue;
 
          rests.push (e);
@@ -133,26 +133,23 @@ Rest_collision::do_shift (Grob *me)
        This is incomplete: in case of an uneven number of rests, the
        center one should be centered on the staff.
       */
-      Drul_array< Link_array<Grob> > ordered_rests;
+      Drul_array<Link_array<Grob> > ordered_rests;
       for (int i = 0; i < rests.size (); i++)
        {
          Grob *r = Note_column::get_rest (rests[i]);
 
          Direction d = get_grob_direction (r);
          if (d)
-           {
-             ordered_rests[d].push (rests[i]);
-           }
+           ordered_rests[d].push (rests[i]);
          else
-           rests[d]->warning (_ ("rest direction not set.  Cannot resolve collision."));
+           rests[d]->warning (_ ("can't resolve rest collision: rest direction not set"));
        }
 
       Direction d = LEFT;
       do
-       {
-         ordered_rests[d].sort (Note_column::shift_compare);
-       }
-      while (flip (&d) != LEFT);
+       ordered_rests[d].sort (Note_column::shift_compare);
+      while (flip (&d) != LEFT)
+       ;
 
       do
        {
@@ -191,13 +188,12 @@ Rest_collision::do_shift (Grob *me)
              Real last_y = ordered_rests[d][i + 1]->extent (common, Y_AXIS)[d];
              Real y = ordered_rests[d][i]->extent (common, Y_AXIS)[-d];
 
-             Real diff = d * ((last_y - y) /staff_space);
+             Real diff = d * ((last_y - y) / staff_space);
              if (diff > 0)
                Note_column::translate_rests (ordered_rests[d][i], d * (int) ceil (diff) * 2);
            }
        }
       while (flip (&d) != LEFT);
-
     }
   else
     {
@@ -205,9 +201,7 @@ Rest_collision::do_shift (Grob *me)
        Rests and notes.
       */
       if (rests.size () > 1)
-       {
-         warning (_ ("too many colliding rests"));
-       }
+       warning (_ ("too many colliding rests"));
       Grob *rcol = 0;
       Direction dir = CENTER;
 
@@ -232,26 +226,24 @@ Rest_collision::do_shift (Grob *me)
 
       Interval notedim;
       for (int i = 0; i < notes.size (); i++)
-       {
-         notedim.unite (notes[i]->extent (common, Y_AXIS));
-       }
+       notedim.unite (notes[i]->extent (common, Y_AXIS));
 
       Real dist
-       = minimum_dist + dir * (notedim[dir] - restdim[-dir]) >? 0;
+       = minimum_dist + dir * max (notedim[dir] - restdim[-dir], 0.0);
 
       int stafflines = Staff_symbol_referencer::line_count (me);
       if (!stafflines)
        {
-         programming_error ("No staff line count ? ");
-         stafflines =5;
+         programming_error ("no staff line count");
+         stafflines = 5;
        }
 
       // move discretely by half spaces.
-      int discrete_dist = int (ceil (dist / (0.5 *staff_space)));
+      int discrete_dist = int (ceil (dist / (0.5 * staff_space)));
 
       // move by whole spaces inside the staff.
       if (discrete_dist < stafflines + 1)
-       discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
+       discrete_dist = int (ceil (discrete_dist / 2.0) * 2.0);
 
       Note_column::translate_rests (rcol, dir * discrete_dist);
     }