]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/collision.cc
release: 1.3.101
[lilypond.git] / lily / collision.cc
index e3eb69a4032a86700a18efc7adf3962f9cf1dc22..5bfac10d1c1025f434f550be76fa2b959a29fbb5 100644 (file)
@@ -8,41 +8,47 @@
 #include "debug.hh"
 #include "collision.hh"
 #include "note-column.hh"
-#include "note-head.hh"
+#include "rhythmic-head.hh"
 #include "paper-def.hh"
 #include "axis-group-interface.hh"
+#include "item.hh"
 
 
-Collision::Collision()
-{
-  Axis_group_interface (this).set_interface ();
-  Axis_group_interface (this).set_axes (X_AXIS, Y_AXIS);
-}
-
-void
-Collision::add_column (Note_column* ncol_l)
-{
-  Axis_group_interface (this).add_element (ncol_l);
-  add_dependency (ncol_l);
-}
-
-void
-Collision::before_line_breaking ()
+MAKE_SCHEME_CALLBACK(Collision,force_shift_callback,2);
+SCM
+Collision::force_shift_callback (SCM element_smob, SCM axis)
 {
-  do_shifts();
+  Score_element *me = unsmob_element (element_smob);
+  Axis a = (Axis) gh_scm2int (axis);
+  assert (a == X_AXIS);
+  
+   me = me->parent_l (a);
+  /*
+    ugh. the way DONE is done is not clean
+   */
+  if (!unsmob_element (me->get_elt_property ("done")))
+    {
+      me->set_elt_property ("done", me->self_scm ());
+      do_shifts (me);
+    }
+  
+  return gh_double2scm (0.0);
 }
 
 /*
   TODO: make callback of this.
  */
 void
-Collision::do_shifts()
+Collision::do_shifts(Score_element* me)
 {
-  SCM autos (automatic_shift ());
-  SCM hand (forced_shift ());
+  SCM autos (automatic_shift (me));
+  SCM hand (forced_shift (me));
+  
   Link_array<Score_element> done;
   
-  Real wid = paper_l ()->get_var ("collision_note_width");
+  Real wid
+    = gh_scm2double (me->get_elt_property ("note-width"));
+  
   for (; gh_pair_p (hand); hand =gh_cdr (hand))
     {
       Score_element * s = unsmob_element (gh_caar (hand));
@@ -67,20 +73,20 @@ Collision::do_shifts()
   This should be put into Scheme.  
   */
 SCM
-Collision::automatic_shift ()
+Collision::automatic_shift (Score_element *me)
 {
-  Drul_array<Link_array<Note_column> > clash_groups;
+  Drul_array<Link_array<Score_element> > clash_groups;
   Drul_array<Array<int> > shifts;
   SCM  tups = SCM_EOL;
 
-  SCM s = get_elt_property ("elements");
+  SCM s = me->get_elt_property ("elements");
   for (; gh_pair_p (s); s = gh_cdr (s))
     {
       SCM car = gh_car (s);
 
       Score_element * se = unsmob_element (car);
-      if (Note_column * col = dynamic_cast<Note_column*> (se))
-       clash_groups[col->dir ()].push (col);
+      if (Note_column::has_interface (se))
+       clash_groups[Note_column::dir (se)].push (se);
     }
 
   
@@ -88,14 +94,14 @@ Collision::automatic_shift ()
   do
     {
       Array<int> & shift (shifts[d]);
-      Link_array<Note_column> & clashes (clash_groups[d]);
+      Link_array<Score_element> & clashes (clash_groups[d]);
 
       clashes.sort (Note_column::shift_compare);
 
       for (int i=0; i < clashes.size (); i++)
        {
          SCM sh
-           = clashes[i]->remove_elt_property ("horizontal-shift");
+           = clashes[i]->get_elt_property ("horizontal-shift");
 
          if (gh_number_p (sh))
            shift.push (gh_scm2int (sh));
@@ -121,7 +127,7 @@ Collision::automatic_shift ()
     {
       for (int i=0; i < clash_groups[d].size (); i++)
        {
-         Slice s(clash_groups[d][i]->head_positions_interval ());
+         Slice s(Note_column::head_positions_interval (clash_groups[d][i]));
          s[LEFT] --;
          s[RIGHT]++;
          extents[d].push (s);
@@ -149,26 +155,26 @@ Collision::automatic_shift ()
     all of them again. */
   if (extents[UP].size () && extents[DOWN].size ())
     {
-      Note_column *cu_l =clash_groups[UP][0];
-      Note_column *cd_l =clash_groups[DOWN][0];
+      Score_element *cu_l =clash_groups[UP][0];
+      Score_element *cd_l =clash_groups[DOWN][0];
 
 
       /*
        TODO.
        */
-      Note_head * nu_l= cu_l->first_head();
-      Note_head * nd_l = cd_l->first_head();
+      Score_element * nu_l= Note_column::first_head(cu_l);
+      Score_element * nd_l = Note_column::first_head(cd_l);
       
-      int downpos = cd_l->head_positions_interval ()[BIGGER];
-      int uppos = cu_l->head_positions_interval ()[SMALLER];      
+      int downpos = Note_column::head_positions_interval (cd_l)[BIGGER];
+      int uppos = Note_column::head_positions_interval (cu_l)[SMALLER];      
       
       bool merge  =
        downpos == uppos
-       && nu_l->balltype_i () == nd_l->balltype_i ();
+       && Rhythmic_head::balltype_i (nu_l) == Rhythmic_head::balltype_i (nd_l);
 
 
-      if (!to_boolean (get_elt_property ("merge-differently-dotted")))
-       merge = merge && nu_l->dot_count () == nd_l->dot_count ();
+      if (!to_boolean (me->get_elt_property ("merge-differently-dotted")))
+       merge = merge && Rhythmic_head::dot_count (nu_l) == Rhythmic_head::dot_count (nd_l);
 
       /*
        notes are close, but can not be merged.  Shift
@@ -187,7 +193,7 @@ Collision::automatic_shift ()
   do
     {
       for (int i=0; i < clash_groups[d].size (); i++)
-       tups = gh_cons (gh_cons (clash_groups[d][i]->self_scm_, gh_double2scm (offsets[d][i])),
+       tups = gh_cons (gh_cons (clash_groups[d][i]->self_scm (), gh_double2scm (offsets[d][i])),
                                 tups);
     }
   while (flip (&d) != UP);
@@ -196,19 +202,19 @@ Collision::automatic_shift ()
 
 
 SCM
-Collision::forced_shift ()
+Collision::forced_shift (Score_element *me)
 {
   SCM tups = SCM_EOL;
   
-  SCM s = get_elt_property ("elements");
+  SCM s = me->get_elt_property ("elements");
   for (; gh_pair_p (s); s = gh_cdr (s))
     {
-      Score_element * se = unsmob_element ( gh_car (s));
+      Score_element * se = unsmob_element (gh_car (s));
 
       SCM force =  se->remove_elt_property ("force-hshift");
       if (gh_number_p (force))
        {
-         tups = gh_cons (gh_cons (se->self_scm_, force),
+         tups = gh_cons (gh_cons (se->self_scm (), force),
                          tups);
        }
     }
@@ -217,3 +223,11 @@ Collision::forced_shift ()
 
 
 
+
+void
+Collision::add_column (Score_element*me,Score_element* ncol_l)
+{
+  ncol_l->add_offset_callback (Collision::force_shift_callback_proc, X_AXIS);
+  Axis_group_interface::add_element (me, ncol_l);
+  me->add_dependency (ncol_l);
+}