]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/collision.cc
release: 1.3.16
[lilypond.git] / lily / collision.cc
index 1ddff7d2f7cc3f880b3edcc1dc967453e8b52dbf..a6bf46e56cc85da7374356e3564d00697da529ff 100644 (file)
@@ -19,29 +19,57 @@ Collision::Collision()
 void
 Collision::add_column (Note_column* ncol_l)
 {
-  clash_l_arr_.push (ncol_l);
   add_element (ncol_l);
   add_dependency (ncol_l);
 }
 
+/*
+  UGH.  junk Shift_tup .
+ */
+
+void
+Collision::do_pre_processing()
+{
+  Array<Shift_tup> autos (automatic_shift ());
+  Array<Shift_tup> hand (forced_shift ());
+  Link_array<Score_element> done;
+  
+  Real wid = paper_l ()->get_var ("collision_note_width");
+  for (int i=0; i < hand.size (); i++)
+    {
+      hand[i].e1_->translate_axis (hand[i].e2_ *wid, X_AXIS);
+      done.push (hand[i].e1_);
+    }
+
+  for (int i=0; i < autos.size (); i++)
+    {
+      if (!done.find_l (autos[i].e1_))
+       autos[i].e1_->translate_axis (autos[i].e2_ * wid, X_AXIS);
+    }
+}
 
 /** This complicated routine moves note columns around horizontally to
   ensure that notes don't clash.
 
   This should be done better, probably.
 
-  TODO: forced hshift
-  
   */
-void
-Collision::do_pre_processing()
+Array< Shift_tup >
+Collision::automatic_shift ()
 {
   Drul_array<Link_array<Note_column> > clash_groups;
   Drul_array<Array<int> > shifts;
-  
-  for (int i=0; i < clash_l_arr_.size(); i++)
+  Array<Shift_tup>  tups;
+
+
+  SCM s = get_elt_property ("elements");
+  for (; gh_pair_p (s); s = gh_cdr (s))
     {
-      clash_groups[clash_l_arr_[i]->dir ()].push (clash_l_arr_[i]);
+      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);
     }
 
   
@@ -56,20 +84,20 @@ Collision::do_pre_processing()
       for (int i=0; i < clashes.size (); i++)
        {
          SCM sh
-           = clashes[i]->remove_elt_property (horizontal_shift_scm_sym);
+           = clashes[i]->remove_elt_property ("horizontal-shift");
 
-         if (sh == SCM_BOOL_F)
-           shift.push (0);
+         if (gh_number_p (sh))
+           shift.push (gh_scm2int (sh));
          else
-           shift.push (gh_scm2int (SCM_CDR (sh)));
+           shift.push (0);
        }
       
       for (int i=1; i < shift.size (); i++)
        {
          if (shift[i-1] == shift[i])
            {
-             warning (_ ("Too many clashing notecolumns. Ignoring them."));
-             return;
+             warning (_ ("Too many clashing notecolumns.  Ignoring them."));
+             return tups;
            }
        }
     }
@@ -112,15 +140,21 @@ Collision::do_pre_processing()
     {
       Note_column *cu_l =clash_groups[UP][0];
       Note_column *cd_l =clash_groups[DOWN][0];
-      Note_head * nu_l= cu_l->head_l_arr_[0];
-      Note_head * nd_l = cd_l->head_l_arr_.top();
-      int downpos =    cd_l->head_positions_interval ()[SMALLER];
-      int uppos =      cu_l->head_positions_interval ()[BIGGER];      
+
+
+      /*
+       TODO.
+       */
+      Note_head * nu_l= cu_l->first_head();
+      Note_head * nd_l = cd_l->first_head();
+      
+      int downpos =    cd_l->head_positions_interval ()[BIGGER];
+      int uppos =      cu_l->head_positions_interval ()[SMALLER];      
       
       bool merge  =
        downpos == uppos
-       && nu_l->balltype_i_ == nd_l->balltype_i_
-       && nu_l->dots_i_ == nd_l->dots_i_;
+       && nu_l->balltype_i () == nd_l->balltype_i ()
+       && nu_l->dots_i () == nd_l->dots_i ();
 
       /*
        notes are close, but can not be merged.  Shift
@@ -136,25 +170,34 @@ Collision::do_pre_processing()
          while ((flip (&d))!= UP);
     }
 
-  Real wid_f = paper_l ()->note_width ();
   do
     {
       for (int i=0; i < clash_groups[d].size (); i++)
-       {
-         clash_groups[d][i]->translate_axis (offsets[d][i]*wid_f, X_AXIS);
-       }
+       tups.push (Shift_tup (clash_groups[d][i], offsets[d][i]));
     }
   while (flip (&d) != UP);
+  return tups;
 }
 
 
-void
-Collision::do_substitute_element_pointer (Score_element*o_l,Score_element*n_l)
+Array <Shift_tup>
+Collision::forced_shift ()
 {
-  if (o_l)
+  Array<Shift_tup> tups;
+  
+  SCM s = get_elt_property ("elements");
+  for (; gh_pair_p (s); s = gh_cdr (s))
     {
-      clash_l_arr_.substitute (dynamic_cast<Note_column *> (o_l),
-                              dynamic_cast <Note_column *> (n_l));
+      Score_element * se = unsmob_element ( gh_car (s));
 
+      SCM force =  se->remove_elt_property ("force-hshift");
+      if (gh_number_p (force))
+       {
+         tups. push (Shift_tup (se, gh_scm2double (force)));
+       }
     }
+  return tups;
 }
+
+
+