]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dot-column.cc
release: 1.3.29
[lilypond.git] / lily / dot-column.cc
index 56ffe94762cbf597796c28d97efc3575aecdd042..2e80a913bc1150ace6da548cb0c5043e38fcb204 100644 (file)
@@ -3,17 +3,23 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "dots.hh"
 #include "dot-column.hh"
 #include "rhythmic-head.hh"
+#include "group-interface.hh"
+#include "staff-symbol-referencer.hh"
+#include "directional-element-interface.hh"
+#include "side-position-interface.hh"
 
 void
 Dot_column::add_dots (Dots *d)
 {
-  dot_l_arr_.push (d);
+  Group_interface gi (this, "dots");
+  gi.add_element (d);
+
   add_dependency (d);
   add_element (d);
 }
@@ -21,62 +27,87 @@ Dot_column::add_dots (Dots *d)
 void
 Dot_column::add_head (Rhythmic_head *r)
 {
-  if (!r->dots_l_)
+  if (!r->dots_l ())
     return ;
 
-  add_support (r);
-  add_dots (r->dots_l_);
+  side_position (this).add_support (r);
+  add_dots (r->dots_l ());
 }
 
-void
-Dot_column::do_substitute_element_pointer (Score_element*o,Score_element*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_;
+  Staff_symbol_referencer_interface s1(d1);
+  Staff_symbol_referencer_interface s2(d2);  
+  
+  return int (s1.position_f () - s2.position_f ());
 }
 
-void
-Dot_column::do_pre_processing ()
-{
-  dot_l_arr_.sort (Dot_column::compare);
-  Note_head_side::do_pre_processing ();
-}
 
 Dot_column::Dot_column ()
 {
-  notehead_align_dir_ = RIGHT;
+  Group_interface gi (this, "dots");
+  gi.set_interface ();
+  
+  directional_element (this).set (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)
+  Link_array<Dots> dots = Group_interface__extract_elements (this, (Dots*)0 , "dots"); 
+  dots.sort (Dot_column::compare);
+  
+  if (dots.size () < 2)
     return;
   Slice s;
   s.set_empty ();
-  
-  for (int i=0; i < dot_l_arr_.size (); i++)
+
+  Array<int> taken_posns;
+  int conflicts = 0;
+  for (int i=0; i < dots.size (); i++)
     {
-      s.unite (Slice (dot_l_arr_[i]->position_i_,dot_l_arr_[i]->position_i_));      
+      Real p = Staff_symbol_referencer_interface (dots[i]).position_f ();
+      for (int j=0; j < taken_posns.size (); j++)
+       {
+         if (taken_posns[j] == (int) p)
+           conflicts++;
+       }
+      taken_posns.push ((int)p);
+      s.unite (Slice ((int)p,
+                     (int)p));      
     }
+
+  if (!conflicts)
+    return;
+  
   int  middle = s.center ();
   /*
     +1 -> off by one 
    */
-  int pos = middle - dot_l_arr_.size () + 1;
+  int pos = middle - dots.size () + 1;
   if (!(pos % 2))
     pos ++;                    // center () rounds down.
 
-  for (int i=0; i  <dot_l_arr_.size (); pos += 2, i++)
+  for (int i=0; i  <dots.size (); pos += 2, i++)
     {
-      dot_l_arr_[i]->position_i_ = pos;
+      staff_symbol_referencer (dots[i]).set_position(pos);
     }
 }