]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/collision.cc
release: 1.3.153
[lilypond.git] / lily / collision.cc
index 8bd1bc186cb225e8abf6b403b6dfc4d9bd6ff3ba..792caf0d3ea6a9e2f323a9e4af24454c14c9f706 100644 (file)
@@ -3,8 +3,9 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
+
 #include "debug.hh"
 #include "collision.hh"
 #include "note-column.hh"
 #include "item.hh"
 
 
-MAKE_SCHEME_CALLBACK(Collision,force_shift_callback,2);
+MAKE_SCHEME_CALLBACK (Collision,force_shift_callback,2);
+
 SCM
 Collision::force_shift_callback (SCM element_smob, SCM axis)
 {
-  Grob *me = unsmob_element (element_smob);
+  Grob *me = unsmob_grob (element_smob);
   Axis a = (Axis) gh_scm2int (axis);
   assert (a == X_AXIS);
   
@@ -26,7 +28,7 @@ Collision::force_shift_callback (SCM element_smob, SCM axis)
   /*
     ugh. the way DONE is done is not clean
    */
-  if (!unsmob_element (me->get_grob_property ("done")))
+  if (!unsmob_grob (me->get_grob_property ("done")))
     {
       me->set_grob_property ("done", me->self_scm ());
       do_shifts (me);
@@ -37,21 +39,30 @@ Collision::force_shift_callback (SCM element_smob, SCM axis)
 
 /*
   TODO: make callback of this.
+
+  TODO:
+
+  note-width is hardcoded, making it difficult to handle all note
+  heads sanely. We should really look at the widths of the colliding
+  columns, and have a separate setting for "align stems".
+
+  
  */
 void
-Collision::do_shifts(Grob* me)
+Collision::do_shifts (Grob* me)
 {
   SCM autos (automatic_shift (me));
   SCM hand (forced_shift (me));
   
   Link_array<Grob> done;
-  
+
+
   Real wid
     = gh_scm2double (me->get_grob_property ("note-width"));
   
   for (; gh_pair_p (hand); hand =gh_cdr (hand))
     {
-      Grob * s = unsmob_element (gh_caar (hand));
+      Grob * s = unsmob_grob (gh_caar (hand));
       Real amount = gh_scm2double (gh_cdar (hand));
       
       s->translate_axis (amount *wid, X_AXIS);
@@ -59,7 +70,7 @@ Collision::do_shifts(Grob* me)
     }
   for (; gh_pair_p (autos); autos =gh_cdr (autos))
     {
-      Grob * s = unsmob_element (gh_caar (autos));
+      Grob * s = unsmob_grob (gh_caar (autos));
       Real amount = gh_scm2double (gh_cdar (autos));
       
       if (!done.find_l (s))
@@ -84,7 +95,7 @@ Collision::automatic_shift (Grob *me)
     {
       SCM car = gh_car (s);
 
-      Grob * se = unsmob_element (car);
+      Grob * se = unsmob_grob (car);
       if (Note_column::has_interface (se))
        clash_groups[Note_column::dir (se)].push (se);
     }
@@ -127,7 +138,7 @@ Collision::automatic_shift (Grob *me)
     {
       for (int i=0; i < clash_groups[d].size (); i++)
        {
-         Slice s(Note_column::head_positions_interval (clash_groups[d][i]));
+         Slice s (Note_column::head_positions_interval (clash_groups[d][i]));
          s[LEFT] --;
          s[RIGHT]++;
          extents[d].push (s);
@@ -143,7 +154,7 @@ Collision::automatic_shift (Grob *me)
          Slice prev =extents[d][i-1];
          prev.intersect (extents[d][i]);
          if (prev.length ()> 0 ||
            (extents[-d].size () && d * (extents[d][i][-d] - extents[-d][0][d]) < 0))
+ (extents[-d].size () && d * (extents[d][i][-d] - extents[-d][0][d]) < 0))
            for (int j = i; j <  clash_groups[d].size (); j++)
              offsets[d][j] += d * 0.5;
        }
@@ -162,8 +173,8 @@ Collision::automatic_shift (Grob *me)
       /*
        TODO.
        */
-      Grob * nu_l= Note_column::first_head(cu_l);
-      Grob * nd_l = Note_column::first_head(cd_l);
+      Grob * nu_l= Note_column::first_head (cu_l);
+      Grob * nd_l = Note_column::first_head (cd_l);
       
       int downpos = Note_column::head_positions_interval (cd_l)[BIGGER];
       int uppos = Note_column::head_positions_interval (cu_l)[SMALLER];      
@@ -179,7 +190,7 @@ Collision::automatic_shift (Grob *me)
       /*
        notes are close, but can not be merged.  Shift
        */
-      if (abs(uppos - downpos) < 2 && !merge)
+      if (abs (uppos - downpos) < 2 && !merge)
          do
          {
            for (int i=0; i < clash_groups[d].size (); i++)
@@ -209,7 +220,7 @@ Collision::forced_shift (Grob *me)
   SCM s = me->get_grob_property ("elements");
   for (; gh_pair_p (s); s = gh_cdr (s))
     {
-      Grob * se = unsmob_element (gh_car (s));
+      Grob * se = unsmob_grob (gh_car (s));
 
       SCM force =  se->remove_grob_property ("force-hshift");
       if (gh_number_p (force))
@@ -221,9 +232,6 @@ Collision::forced_shift (Grob *me)
   return tups;
 }
 
-
-
-
 void
 Collision::add_column (Grob*me,Grob* ncol_l)
 {