]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/collision.cc
release: 0.1.7
[lilypond.git] / lily / collision.cc
index 2fbb0d80187447ffaa0b6d89722abac13a45ae76..0af68c462e2e3efc6fe9ca1a61cd264d31997416 100644 (file)
@@ -1,26 +1,31 @@
 /*
   collision.cc -- implement Collision
 
-  source file of the LilyPond music typesetter
+  source file of the GNU LilyPond music typesetter
 
   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
 */
 #include "debug.hh"
 #include "collision.hh"
 #include "note-column.hh"
-#include "notehead.hh"
+#include "note-head.hh"
 #include "paper-def.hh"
 
 Collision::Collision()
 {
+    empty_b_ = transparent_b_ =true;
 }
 
 void
 Collision::add(Note_column* ncol_l)
 {
     clash_l_arr_.push(ncol_l);
+    add_element( ncol_l );
     add_dependency(ncol_l);
 }
+/**
+  should derive of Array.
+ */
 static 
 int idx(int dir, bool h_shift_b)
 {
@@ -52,11 +57,16 @@ Collision::do_pre_processing()
     
     for (int i=0; i < clash_l_arr_.size(); i++) {
        Note_column* c_l = clash_l_arr_[i];
+       if (! c_l->dir_i_) {
+           warning ("No stem direction set. Ignoring column in clash. ");
+           continue;
+       }
        int d = (c_l->dir_i_);
        
        clash_group_arr_a[idx(d, c_l->h_shift_b_)].push(c_l);
     }
     
+    
     for (int j=0; j < 4; j++) {
        if (clash_group_arr_a[j].size() > 1) {
            warning("Too many clashing notecolumns. Ignoring them.");
@@ -67,7 +77,7 @@ Collision::do_pre_processing()
     do {
        if (!clash_group_arr_a[idx(d, false)].size()){
            clash_group_arr_a[idx(d,  false)] = clash_group_arr_a[idx(d, true)];
-           clash_group_arr_a[idx(d, true)].set_size(0);
+           clash_group_arr_a[idx(d, true)].clear();
        }
     } while ((d *= -1) != 1);
                                  
@@ -76,7 +86,6 @@ Collision::do_pre_processing()
     Note_column * col_l_a[4];
     Real x_off [4];
     int y_off[4];
-    bool rest_b_a[4];
     
     for (int j =0 ; j < 4; j++) {
        if (clash_group_arr_a[j].size()) 
@@ -88,7 +97,7 @@ Collision::do_pre_processing()
            y_extent[j] = col_l_a[j]->head_positions_interval();
        }
 
-       rest_b_a[j] = (col_l_a[j]) ? col_l_a[j]->rest_b_ : false;       
+
        x_off [j] = 0.0;
        y_off[j] = 0;
     }
@@ -97,55 +106,51 @@ Collision::do_pre_processing()
        x_off[idx(d, true)] = d*0.5;
     } while ((d *= -1) != 1);
 
-   do {
-       int i1 = idx(d, false);
-       int i2 = idx(d,true);
-       if (!intersection(y_extent[i1] , 
-                         y_extent[i2]).empty_b()) {
-           if (rest_b_a[i1]) {
-               y_off[i1] = -y_extent[i1][-d] + y_extent[1][d] + d*4; // ugh
-               y_extent[i1] += y_off[i1];
-           }
-       }
-    } while ((d *= -1) != 1);
-
-    do {
-       int i1 = idx(d, false);
-       int i2 = idx(-d,false);
-       
-       if (d*(y_extent[i1][-d] - y_extent[i2][d] )< 0&& rest_b_a[i1]) {
-           y_off[i1] = -y_extent[i1][-d] + y_extent[i2][d] +d* 4; // ugh
-           y_extent[i1] += y_off[i1];
-       }
-    } while ((d *= -1) != 1);
-    
-    Interval_t<int> middle( y_extent[0].min(), y_extent[3].max());
-    Interval_t<int> open_middle( y_extent[3].max()+1, y_extent[0].min()-1);
+  
+    // y_extent: smallest y-pos noteball interval containing all balls
+    // 4 (0..3) groups: stem up/down; shift on/off; 
+    Interval_t<int> middle( y_extent[idx(-1,0)].max(),
+                           y_extent[idx(1,0)].min() );
+    Interval_t<int> open_middle( y_extent[idx(-1,0)].max()+1, y_extent[idx(1,0)].min()-1);
     do{
        if (!open_middle.contains_b(y_extent[idx(d,true)]))
            x_off[idx(d, true)] = d *1.0 ;
     } while ((d *= -1) != 1);
    
-    if (!middle.empty_b() && 
-       middle.length() <= 1 && col_l_a[idx(1,0)] && col_l_a[idx(-1,0)]
-       && !rest_b_a[idx(1,0)] && !rest_b_a[idx(-1,0)]) {
-       
-       Notehead * nu_l= col_l_a[idx(1,0)]->head_l_arr_[idx(1,0)];
-       Notehead * nd_l = col_l_a[idx(-1,0)]->head_l_arr_[idx(1,0)];
-       if (! (nu_l->balltype == nd_l->balltype && nu_l->dots == nd_l->dots)) {
+    if (!middle.empty_b() 
+       && middle.length() < 2 && col_l_a[idx(1,0)] && col_l_a[idx(-1,0)]) {    
+// reproduction of bugfix at 3am ?
+       Note_head * nu_l= col_l_a[idx(1,0)]->head_l_arr_[0];
+       Note_head * nd_l = col_l_a[idx(-1,0)]->head_l_arr_.top();
+       if (! (nu_l->balltype_i_ == nd_l->balltype_i_ 
+              && nu_l->dots_i_ == nd_l->dots_i_  && middle.length() == 0 )) {
            x_off[idx(1,0)] -= 0.5;
-           x_off[1] -= 0.5;
-           x_off[2] += 0.5;
+           x_off[idx(1,1)] -= 0.5;
+           x_off[idx(-1,1)] += 0.5;
            x_off[idx(-1,0)] += 0.5;
        }
+       
     }    
-    Real inter_f = paper()->internote();
+    Real inter_f = paper()->internote_f();
     Real wid_f = paper()->note_width();
     for (int j=0; j < 4; j++) {
-       if (col_l_a[j])
-           col_l_a[j]->translate(Offset(x_off[j] * wid_f,
-                                        y_off[j] * inter_f));
-       
+       if (col_l_a[j]) {
+           /* collision.cc:138: request for method `translate' is ambiguous 
+              
+              (shaddup)
+            */
+           Offset o(x_off[j] * wid_f, y_off[j] * inter_f);
+           ((Score_elem*)col_l_a[j])->translate(o);
+       }
     }
 }
-IMPLEMENT_STATIC_NAME(Collision);
+
+
+IMPLEMENT_IS_TYPE_B1(Collision, Item);
+
+void
+Collision::do_substitute_dependency(Score_elem*o_l,Score_elem*n_l)
+{
+    clash_l_arr_.substitute((Note_column*)o_l->item(), 
+                           (Note_column*)(n_l?n_l->item():0));
+}