]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/rest-collision.cc
release: 1.1.29
[lilypond.git] / lily / rest-collision.cc
index c8f0d3e78982592ececb394f64abbbbe6e7d4d33..1e479f196bbf66833015245727da6916a870d71a 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "debug.hh"
@@ -15,7 +15,7 @@
 #include "paper-def.hh"
 
 
-IMPLEMENT_IS_TYPE_B1(Rest_collision,Item);
+
 
 void
 Rest_collision::add_column (Note_column *nc_l)
@@ -31,37 +31,10 @@ void
 Rest_collision::do_post_processing()
 {
   /*
+    [TODO]
     handle rest under beam (do_post: beams are calculated now)
-
-    [todo]
-    i-d like to have access to the beam itself, 
-    iso only the (half-initialised?) stem
-
     what about combination of collisions and rest under beam
    */
-
-  // no rests to collide
-  if (!rest_l_arr_.size())
-       return;
-  // can this happen?
-  Stem* stem_l = rest_l_arr_[0]->stem_l_;
-  if (!stem_l)
-    return;
-  // no beam
-  if (!(stem_l->beams_left_i_ || stem_l->beams_right_i_))
-    return;
-
-  int dir_i = rest_l_arr_[0]->dir_;
-  int midpos = 4;
-#if 1
-  // ugh
-  int stem_length_i = 7 - 2;
-  // ugh, Stem::stem_start vs Stem::stem_end
-  int pos = (int)(stem_l->stem_end_f() - midpos) - dir_i * stem_length_i;
-#else // nogo: stem_start not set for rests?
-  int pos = (stem_l->stem_begin_f() - midpos) + dir_i * 2;
-#endif
-  rest_l_arr_[0]->translate_rests (pos);       
 }
 
 void
@@ -96,8 +69,6 @@ Rest_collision::do_pre_processing()
     {
       // int dir_i = - ncol_l_arr_[0]->dir_;
       int dir_i = rest_l_arr_[0]->dir_;
-      // hope it's 4: if it works->doco
-      int midpos = 0;
        
       // minimum move
       int minpos = 4;
@@ -106,14 +77,18 @@ Rest_collision::do_pre_processing()
       // UGH Should get dims from table!
       int size_i = 6;
        
+      Real internote_f = paper ()->internote_f ();
       int sep_i = 3 + size_i / 2;
       for (int i = 0; i < ncol_l_arr_.size(); i++) 
        {
          // how to know whether to sort?
          ncol_l_arr_[i]->sort();
          for (int j = 0; j < ncol_l_arr_[i]->head_l_arr_.size(); j++)
-           minpos = minpos >? dir_i * 
-             (ncol_l_arr_[i]->head_l_arr_[j]->position_i_ -midpos) + sep_i;
+           {
+             int stem = (int)((ncol_l_arr_[i]->stem_l_->extent
+                              (Y_AXIS)[dir_i]) / internote_f);
+             minpos = minpos >? (dir_i * stem + sep_i);
+           }
        }
       rest_l_arr_[0]->translate_rests (dir_i * minpos);        
     }
@@ -131,14 +106,11 @@ Rest_collision::do_print() const
 void
 Rest_collision::do_substitute_dependency (Score_element*o,Score_element*n)
 {
-  Item*o_l = o->access_Item ();
-  
-
-  if (o_l&&o_l->is_type_b (Note_column::static_name ()))
+  if (Note_column *onl = dynamic_cast<Note_column *> (o))
     {
-      Note_column *n_l = n?(Note_column*)n->access_Item ():0;
-      rest_l_arr_.substitute ((Note_column*)o_l, n_l);
-      ncol_l_arr_.substitute ((Note_column*)o_l, n_l);
+      Note_column *n_l = n?dynamic_cast<Note_column *> (n):0;
+      rest_l_arr_.substitute (onl, n_l);
+      ncol_l_arr_.substitute (onl, n_l);
     }
 }