]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dot-column.cc
patch::: 1.3.15.jcn4
[lilypond.git] / lily / dot-column.cc
index 6da5e0bbced6c990b08e786c16ca16965a5b82c4..d085bf401116a6b8dbbdab1086e4eb6452c93b9a 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--1999 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"
 
 void
-Dot_column::add (Dots *d)
+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);
 }
 
 void
-Dot_column::add (Rhythmic_head *r)
+Dot_column::add_head (Rhythmic_head *r)
 {
-  if (!r->dots_l_)
+  if (!r->dots_l ())
     return ;
+
+  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 (r->dots_l_);
+  return int (s1.position_f () - s2.position_f ());
 }
 
-void
-Dot_column::do_substitute_dependency (Score_elem*o,Score_elem*n)
+
+Dot_column::Dot_column ()
 {
-  Item *oi =o->item ();
-  Item *ni = n?n->item ():0;
+  Group_interface gi (this, "dots");
+  gi.set_interface ();
   
-  if (oi&&oi->is_type_b (Rhythmic_head::static_name ()))
-    head_l_arr_.substitute ((Rhythmic_head*)oi, (Rhythmic_head*)ni);
-  else if (oi && oi->is_type_b (Dots::static_name ()))
-    dot_l_arr_.substitute ((Dots*) oi, (Dots*) ni);
+  set_direction (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]->width ());
+  Link_array<Dots> dots = Group_interface__extract_elements (this, (Dots*)0 , "dots"); 
+  dots.sort (Dot_column::compare);
   
-  if (!w.empty_b ())
-    translate (w[RIGHT] - width() [LEFT],X_AXIS);
-}
+  if (dots.size () < 2)
+    return;
+  Slice s;
+  s.set_empty ();
 
-IMPLEMENT_IS_TYPE_B1(Dot_column, Horizontal_group_item);
+  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_interface (dots[i]).set_position(pos);
+    }
+}