]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dot-column.cc
release: 1.3.54
[lilypond.git] / lily / dot-column.cc
index 4c44095826f217b81fb5745260afa0d0a6408960..75f8391fe934b16092c5dd2b2aa4d2e9da6c8bb6 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.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"
+#include "axis-group-interface.hh"
 
+
+// todo: dots and elements duplicate each other.
 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);
+  Axis_group_interface (this).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 ;
+
+  Side_position_interface (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 (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 ();
+  directional_element (this).set (RIGHT);
   
-  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);
+  Axis_group_interface (this).set_interface ();
+  Axis_group_interface (this).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::after_line_breaking ()
 {
-  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_axis (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 (dots[i]).set_position(pos);
+    }
+}