]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/rest-collision.cc
release: 1.1.38
[lilypond.git] / lily / rest-collision.cc
index 0a7807ce3140cdd6465dbe10d8e9ed1f416ecc68..77eecea668677c904a23e72808f45897fd77295a 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#include "debug.hh"
 #include "rest-collision.hh"
-#include "rest-column.hh"
+#include "note-column.hh"
+#include "stem.hh"
+#include "note-head.hh"
 #include "collision.hh"
+#include "paper-def.hh"
 
 void
-Rest_collision::add(Rest_column *rc_l)
+Rest_collision::add_column (Note_column *nc_l)
 {
-    rest_l_arr_.push(rc_l);
-    add_dependency(rc_l);
+  add_dependency (nc_l);
+  if (nc_l->rest_b ())
+    rest_l_arr_.push (nc_l);
+  else
+    ncol_l_arr_.push (nc_l);
 }
+
 void
-Rest_collision::add(Collision * c_l)
+Rest_collision::do_post_processing()
 {
-    add_dependency(c_l);
-    for (int i=0; i < c_l->clash_l_arr_.size(); i ++)
-       ncol_l_arr_.push(c_l->clash_l_arr_[i]);
+  /*
+    [TODO]
+    handle rest under beam (do_post: beams are calculated now)
+    what about combination of collisions and rest under beam
+   */
 }
 
-
 void
-Rest_collision::do_post_processing()
+Rest_collision::do_pre_processing()
 {
-#if 0
-        bool rest_b_a[4];
-       rest_b_a[j] = (col_l_a[j]) ? col_l_a[j]->rest_b_ : false;       
-    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);
+  /* 
+     handle rest-rest and rest-note collisions
 
-    do {
-       int i1 = idx(d, false);
-       int i2 = idx(-d,false);
+     [todo]
+     decide not to print rest if too crowded?
+   */
+
+  // no rests to collide
+  if (!rest_l_arr_.size())
+    return;
+
+  // no partners to collide with
+  if (rest_l_arr_.size() + ncol_l_arr_.size () < 2)
+    return;
+
+  // meisjes met meisjes
+  if (!ncol_l_arr_.size()) 
+    {
+      int dy = rest_l_arr_.size() > 2 ? 6 : 4;
+       
+      rest_l_arr_[0]->translate_rests (rest_l_arr_[0]->dir () *dy);    
+      // top is last element...
+      rest_l_arr_.top()->translate_rests (rest_l_arr_.top ()->dir ()* dy);     
+    }
+  // meisjes met jongetjes
+  else 
+    {
+      // int dir_i = - ncol_l_arr_[0]->dir_;
+      Direction dir = rest_l_arr_[0]->dir ();
+       
+      // minimum move
+      int minpos = 4;
        
-       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];
+      // quart rest height
+      // UGH Should get dims from table!
+      int size_i = 6;
+       
+
+      // staff ref'd?
+      Real internote_f = paper_l ()->get_realvar (interline_scm_sym)/2.0;
+      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++)
+           {
+             int stem = (int)((ncol_l_arr_[i]->stem_l_->extent
+                              (Y_AXIS)[dir]) / internote_f);
+             minpos = minpos >? (dir * stem + sep_i);
+           }
        }
-    } while ((d *= -1) != 1);
-    
+      rest_l_arr_[0]->translate_rests (dir * minpos);  
+    }
+}
+
+void
+Rest_collision::do_print() const
+{
+#ifndef NPRINT
+  DOUT << "rests: " << rest_l_arr_.size() << ", ";
+  DOUT << "cols: " << ncol_l_arr_.size();
 #endif
 }
-IMPLEMENT_STATIC_NAME(Rest_collision);
+
 void
-Rest_collision::do_substitute_dependency(Score_elem*o,Score_elem*n)
+Rest_collision::do_substitute_element_pointer (Score_element*o,Score_element*n)
+{
+  if (Note_column *onl = dynamic_cast<Note_column *> (o))
+    {
+      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);
+    }
+}
+
+Rest_collision::Rest_collision()
 {
-    Item*o_l = o->item();
-    Item*n_l = n?n->item():0;
-    
-    rest_l_arr_.substitute((Rest_column*)o_l,(Rest_column*)n_l);
-    ncol_l_arr_.substitute((Note_column*)o_l,(Note_column*)n_l);
+  set_elt_property (transparent_scm_sym, SCM_BOOL_T);
+  set_empty (true);
 }