]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-column.cc
release: 1.1.41
[lilypond.git] / lily / note-column.cc
index 3894bd6e2bcb81659b3fdebac2b8d388cb28f570..26a33eb5cd28c76dab6d2c329f270371eb7d2bcb 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
@@ -23,9 +22,8 @@ Note_column::rest_b () const
 
 Note_column::Note_column()
 {
+  set_axes (X_AXIS,X_AXIS);
   stem_l_ = 0;
-  h_shift_b_ = false;
-  dir_ =CENTER;
 }
 
 void
@@ -38,67 +36,41 @@ Interval_t<int>
 Note_column::head_positions_interval() const
 {
   ((Note_column*)this)->sort();
- Interval_t<int>  iv;
 Interval_t<int>  iv;
 
- iv.set_empty ();
 iv.set_empty ();
 
- if (head_l_arr_.size ())
-   iv = Interval_t<int>(head_l_arr_[0]->position_i_, 
-                         head_l_arr_.top()->position_i_);
 if (head_l_arr_.size ())
+    iv = Interval_t<int>(head_l_arr_[0]->position_i_, 
+                        head_l_arr_.top()->position_i_);
   
   return iv;
 }
 
-Interval 
-Note_column::width () const
-{
-  if (head_l_arr_.size ())
-    return head_l_arr_[0]->width ();
-  else
-    return Interval (0,0);
-}
-
-void
-Note_column::do_pre_processing()
+Direction
+Note_column::dir () const
 {
+  if (stem_l_)
+    return stem_l_->dir_;
+  else if (head_l_arr_.size ())
+    return sign (head_positions_interval().center ());
 
-  if (!dir_)
-    {
-      if (stem_l_)
-       dir_ = stem_l_->dir_;
-      else if (head_l_arr_.size ())
-       {
-         dir_ = (head_positions_interval().center () >=  5) ? DOWN:UP;
-       }
-    }
-  Script_column::do_pre_processing();
+  assert (false);
+  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) 
     {
@@ -109,7 +81,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), 
@@ -120,16 +92,15 @@ 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);
 }
 
 /**
@@ -157,3 +128,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)
+    return;
+      
+      /* ugh. Should be done by beam. */
+  Real x = stem_l_->hpos_f ();
+  Direction d = stem_l_->get_dir ();
+  Real beamy = x * b->slope_f_ + b->left_y_;
+  Interval restdim = extent (Y_AXIS);
+
+  Real staff_space = rest_l_arr_[0]->staff_line_leading_f ();      
+  Real internote_f = staff_space/2;
+  Real minimum_dist
+    = paper_l ()->get_var ("restcollision_minimum_beamdist") * internote_f;
+  Real dist =
+    minimum_dist +  -d  * (beamy - restdim[d]) >? 0;
+
+  int stafflines = rest_l_arr_[0]->lines_i ();
+      
+  // move discretely by half spaces.
+  int discrete_dist = int (ceil (dist / (0.5 *staff_space)));
+
+  // 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);
+}