]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dot-column.cc
release: 1.1.64
[lilypond.git] / lily / dot-column.cc
index 284b746cc946841ec581cc52cbd3ccdc92f47ddb..d510fba7f46850ae6151e2332455b0019c72b557 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 "dots.hh"
@@ -23,34 +23,85 @@ Dot_column::add_head (Rhythmic_head *r)
 {
   if (!r->dots_l_)
     return ;
-  
-  head_l_arr_.push (r);
-  add_dependency (r);
+
+  add_support (r);
   add_dots (r->dots_l_);
 }
 
 void
-Dot_column::do_substitute_dependency (Score_element*o,Score_element*n)
+Dot_column::do_substitute_element_pointer (Score_element*o,Score_element*n)
 {
-  Item *oi =dynamic_cast <Item *> (o);
-  
-  if (oi && dynamic_cast<Rhythmic_head *> (oi))
-    head_l_arr_.substitute (dynamic_cast<Rhythmic_head*> (oi),
-                           dynamic_cast<Rhythmic_head*>(n));
-  else if (oi && dynamic_cast<Dots *> (oi))
-    dot_l_arr_.substitute (dynamic_cast<Dots*> (oi),
-                          dynamic_cast<Dots*> (n));
+  Note_head_side::do_substitute_element_pointer (o,n);
+  if (Dots * d = dynamic_cast<Dots*> (o))
+    dot_l_arr_.substitute (d, dynamic_cast<Dots*> (n));
+}
+
+int
+Dot_column::compare (Dots * const &d1, Dots * const &d2)
+{
+  return d1->position_i_ - d2->position_i_;
 }
 
 void
 Dot_column::do_pre_processing ()
 {
-  Interval w;
-  for (int i=0; i < head_l_arr_.size (); i++)
-    w.unite (head_l_arr_[i]->width ());
-  
-  if (!w.empty_b ())
-    translate_axis (w[RIGHT] - width() [LEFT],X_AXIS);
+  dot_l_arr_.sort (Dot_column::compare);
+  Note_head_side::do_pre_processing ();
 }
 
-IMPLEMENT_IS_TYPE_B1(Dot_column, Horizontal_group_item);
+Dot_column::Dot_column ()
+{
+  notehead_align_dir_ = RIGHT;
+  set_axes(X_AXIS,X_AXIS);
+}
+
+/*
+  Will fuck up in this case.
+
+  X.  .
+  X.X .
+   |X .
+   |
+   |
+   |X .
+   |
+   |
+
+
+   Should be smarter.
+ */
+void
+Dot_column::do_post_processing ()
+{
+  if (dot_l_arr_.size () < 2)
+    return;
+  Slice s;
+  s.set_empty ();
+
+  Array<int> taken_posns;
+  int conflicts = 0;
+  for (int i=0; i < dot_l_arr_.size (); i++)
+    {
+      for (int j=0; j < taken_posns.size (); j++)
+       if (taken_posns[j] == dot_l_arr_[i]->position_i_)
+         conflicts++;
+      taken_posns.push (dot_l_arr_[i]->position_i_);
+      s.unite (Slice (dot_l_arr_[i]->position_i_,dot_l_arr_[i]->position_i_));      
+    }
+
+  if (!conflicts)
+    return;
+  
+  int  middle = s.center ();
+  /*
+    +1 -> off by one 
+   */
+  int pos = middle - dot_l_arr_.size () + 1;
+  if (!(pos % 2))
+    pos ++;                    // center () rounds down.
+
+  for (int i=0; i  <dot_l_arr_.size (); pos += 2, i++)
+    {
+      dot_l_arr_[i]->position_i_ = pos;
+    }
+}