]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-column.cc
patch::: 1.3.9.hwn2
[lilypond.git] / lily / note-column.cc
index 2a0805d9029955b293aaec937ad365c6ac7254e4..844ad7701ad6e00371ecaf5e80487046c843e630 100644 (file)
@@ -3,17 +3,16 @@
 
   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 "dot-column.hh"
 #include "note-column.hh"
-#include "script.hh"
+#include "beam.hh"
 #include "note-head.hh"
 #include "stem.hh"
 #include "rest.hh"
 #include "debug.hh"
-
-
+#include "paper-def.hh"
 
 bool
 Note_column::rest_b () const
@@ -21,11 +20,21 @@ Note_column::rest_b () const
   return rest_l_arr_.size ();
 }
 
+int
+Note_column::shift_compare (Note_column *const &p1, Note_column*const&p2)
+{
+  SCM s1 = p1->get_elt_property ("horizontal-shift");
+  SCM s2 = p2->get_elt_property ("horizontal-shift");
+
+  int h1 = (s1 == SCM_UNDEFINED) ? 0 : gh_scm2int (s1);
+  int h2 = (s2 == SCM_UNDEFINED) ? 0 : gh_scm2int (s2);
+  return h1 - h2;
+}
+
 Note_column::Note_column()
 {
+  set_axes (X_AXIS, Y_AXIS);
   stem_l_ = 0;
-  h_shift_b_ = false;
-  dir_ =CENTER;
 }
 
 void
@@ -34,72 +43,44 @@ Note_column::sort()
   head_l_arr_.sort (Note_head::compare);
 }
   
-Interval_t<int>
+Slice
 Note_column::head_positions_interval() const
 {
-  ((Note_column*)this)->sort();
-  Interval_t<int>  iv;
+  Slice  iv;
 
   iv.set_empty ();
-
-  if (head_l_arr_.size ())
-    iv = Interval_t<int>(head_l_arr_[0]->position_i_, 
-                        head_l_arr_.top()->position_i_);
-  
+  for (int i=0; i <head_l_arr_.size ();i ++)
+    {
+      int j = int (head_l_arr_[i]->position_f ());
+      iv.unite (Slice (j,j));
+    }
   return iv;
 }
 
-/*
-Interval 
-Note_column::do_width () const
-{
-  if (head_l_arr_.size ())
-    return head_l_arr_[0]->extent (X_AXIS);
-  else
-    return Interval (0,0);
-}
-*/
-void
-Note_column::do_pre_processing()
+Direction
+Note_column::dir () const
 {
-  if (!dir_)
-    {
-      if (stem_l_)
-       dir_ = stem_l_->dir_;
-      else if (head_l_arr_.size ())
-       {
-         //      assert (false);       // looks obsolete?
-         dir_ = sign (head_positions_interval().center ());
-       }
-    }
-  Script_column::do_pre_processing();
+  if (stem_l_)
+    return stem_l_->get_direction ();
+  else if (head_l_arr_.size ())
+    return (Direction)sign (head_positions_interval().center ());
+
+  programming_error ("Note column without heads and stem!");
+  return CENTER;
 }
 
-  
 
 void
 Note_column::set_stem (Stem * stem_l)
 {
-  add_support (stem_l);
   stem_l_ = stem_l;
-  /* 
-     don't add stem to support; mostly invisible for rest-columns (and possibly taken . .)
-  */
-  Score_element::add_dependency (stem_l);
-  for (int i=0; i < script_l_arr_.size(); i++)
-    script_l_arr_[i]->set_stem (stem_l);
+  add_dependency (stem_l);
+  add_element (stem_l);
 }
 
-void
-Note_column::add_script (Script *script_l)
-{
-  Script_column::add_script (script_l) ;
-  if  (stem_l_)
-    script_l->set_stem (stem_l_);
-}
 
 void
-Note_column::do_substitute_dependency (Score_element*o, Score_element*n)
+Note_column::do_substitute_element_pointer (Score_element*o, Score_element*n)
 {
   if (stem_l_ == o) 
     {
@@ -110,7 +91,7 @@ Note_column::do_substitute_dependency (Score_element*o, Score_element*n)
       head_l_arr_.substitute (dynamic_cast<Note_head *> (o), 
                              (n)? dynamic_cast<Note_head *> (n) : 0);
     }
-  Script_column::do_substitute_dependency (o,n);
+
   if (dynamic_cast<Rest *> (o)) 
     {
       rest_l_arr_.substitute (dynamic_cast<Rest *> (o), 
@@ -121,35 +102,35 @@ Note_column::do_substitute_dependency (Score_element*o, Score_element*n)
 void
 Note_column::add_head (Rhythmic_head *h)
 {
-  if (dynamic_cast<Rest *> (h))
+  if (Rest*r=dynamic_cast<Rest *> (h))
     {
-      rest_l_arr_.push ((Rest*)h);
-      add_support (h);  
+      rest_l_arr_.push (r);
     }
-  if (dynamic_cast<Note_head *> (h))
+  if (Note_head *nh=dynamic_cast<Note_head *> (h))
     {
-      head_l_arr_.push ((Note_head*) h);
-      add_support (h);
+      head_l_arr_.push (nh);
     }
+  add_element (h);
 }
 
 /**
-  translate the rest symbols
+  translate the rest symbols vertically by amount DY_I.
  */
 void
 Note_column::translate_rests (int dy_i)
 {
   invalidate_cache (Y_AXIS);
   for (int i=0; i < rest_l_arr_.size(); i++)
-    rest_l_arr_[i]->position_i_ += dy_i;
+    rest_l_arr_[i]->translate_axis (dy_i  * rest_l_arr_[i]->staff_line_leading_f ()/2.0,
+                                   Y_AXIS);
 }
 
 void
 Note_column::do_print() const
 {
 #ifndef NPRINT
-  DOUT << "rests: " << rest_l_arr_.size() << ", ";
-  DOUT << "heads: " << head_l_arr_.size();
+  DEBUG_OUT << "rests: " << rest_l_arr_.size() << ", ";
+  DEBUG_OUT << "heads: " << head_l_arr_.size();
 #endif
 }
 
@@ -158,3 +139,49 @@ Note_column::set_dotcol (Dot_column *d)
 {
   add_element (d);
 }
+
+/*
+  [TODO]
+  handle rest under beam (do_post: beams are calculated now)
+  what about combination of collisions and rest under beam.
+
+  Should lookup
+    
+    rest -> stem -> beam -> interpolate_y_position ()
+    
+*/
+
+void
+Note_column::do_post_processing ()
+{
+  if (!stem_l_ || !rest_b ())
+    return;
+
+  Beam * b = stem_l_->beam_l ();
+  if (!b || !b->stem_count ())
+    return;
+  
+  /* ugh. Should be done by beam. */
+  Direction d = stem_l_->get_direction ();
+  Real beamy = (stem_l_->hpos_f () - b->stem(0)->hpos_f ()) * b->slope_f_ + b->left_y_;
+
+  Real staff_space = rest_l_arr_[0]->staff_line_leading_f ();      
+  Real rest_dim = extent (Y_AXIS)[d]*2.0  /staff_space ;
+
+  Real minimum_dist
+    = paper_l ()->get_var ("restcollision_minimum_beamdist") ;
+  Real dist =
+    minimum_dist +  -d  * (beamy - rest_dim) >? 0;
+
+  int stafflines = rest_l_arr_[0]->lines_i ();
+
+  // move discretely by half spaces.
+  int discrete_dist = int (ceil (dist ));
+
+  // move by whole spaces inside the staff.
+  if (discrete_dist < stafflines+1)
+    discrete_dist = int (ceil (discrete_dist / 2.0)* 2.0);
+
+  translate_rests (-d *  discrete_dist);
+}
+