]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dot-column.cc
release: 1.3.29
[lilypond.git] / lily / dot-column.cc
index a802c5cfa21802e7767fb2adb4f28b5e2cb91c7b..2e80a913bc1150ace6da548cb0c5043e38fcb204 100644 (file)
@@ -3,17 +3,23 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 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,36 +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 ;
+
+  side_position (this).add_support (r);
+  add_dots (r->dots_l ());
+}
+
+
+int
+Dot_column::compare (Dots * const &d1, Dots * const &d2)
+{
+  Staff_symbol_referencer_interface s1(d1);
+  Staff_symbol_referencer_interface s2(d2);  
   
-  head_l_arr_.push (r);
-  add_dependency (r);
-  add_dots (r->dots_l_);
+  return int (s1.position_f () - s2.position_f ());
 }
 
-void
-Dot_column::do_substitute_dependency (Score_element*o,Score_element*n)
+
+Dot_column::Dot_column ()
 {
-  Item *oi =dynamic_cast <Item *> (o);
+  Group_interface gi (this, "dots");
+  gi.set_interface ();
   
-  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));
+  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_pre_processing ()
+Dot_column::do_post_processing ()
 {
-  Interval w;
-  for (int i=0; i < head_l_arr_.size (); i++)
-    w.unite (head_l_arr_[i]->extent (X_AXIS));
+  Link_array<Dots> dots = Group_interface__extract_elements (this, (Dots*)0 , "dots"); 
+  dots.sort (Dot_column::compare);
   
-  if (!w.empty_b ())
-    translate_axis (w[RIGHT] - extent(X_AXIS) [LEFT],X_AXIS);
-}
+  if (dots.size () < 2)
+    return;
+  Slice s;
+  s.set_empty ();
+
+  Array<int> taken_posns;
+  int conflicts = 0;
+  for (int i=0; i < dots.size (); 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 - dots.size () + 1;
+  if (!(pos % 2))
+    pos ++;                    // center () rounds down.
 
+  for (int i=0; i  <dots.size (); pos += 2, i++)
+    {
+      staff_symbol_referencer (dots[i]).set_position(pos);
+    }
+}