]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dot-column.cc
release: 1.3.72
[lilypond.git] / lily / dot-column.cc
index b673b77092de22500c2a77fbef8c8d56658ba2ea..5557790b33915819b77c26dc6b0bfbf23129514c 100644 (file)
 
   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"
+#include "axis-group-interface.hh"
+
+
 
 void
-Dot_column::add_dots (Dots *d)
+Dot_column::add_head (Score_element * me, Score_element *rh)
 {
-  dot_l_arr_.push (d);
-  add_dependency (d);
-  add_element (d);
+  Score_element * d = unsmob_element (rh->get_elt_property ("dot"));
+  if (d)
+    {
+      Side_position::add_support (me,rh);
+
+      Pointer_group_interface gi (me, "dots");
+      gi.add_element (d);
+      
+      d->add_offset_callback (force_shift_callback , Y_AXIS);
+      Axis_group_interface::add_element (me, d);
+    }
 }
 
+
+
+
 void
-Dot_column::add_head (Rhythmic_head *r)
+Dot_column::set_interface (Score_element* me)
 {
-  if (!r->dots_l_)
-    return ;
+  me->set_elt_property  ("dots", SCM_EOL);
+  Directional_element_interface (me).set (RIGHT);
   
-  head_l_arr_.push (r);
-  add_dependency (r);
-  add_dots (r->dots_l_);
+  Axis_group_interface::set_interface (me);
+  Axis_group_interface::set_axes (me, X_AXIS,X_AXIS);
 }
 
-void
-Dot_column::do_substitute_element_pointer (Score_element*o,Score_element*n)
+/*
+  Will fuck up in this case.
+
+  X.  .
+  X.X .
+   |X .
+   |
+   |
+   |X .
+   |
+   |
+
+
+   Should be smarter.
+ */
+
+
+Real
+Dot_column::force_shift_callback (Score_element * dot, Axis a)
 {
-  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));
+  assert (a == Y_AXIS);
+  Score_element * me = dot->parent_l (X_AXIS);
+  SCM dots = me->get_elt_property ("dots");
+  do_shifts (dots);
+  return 0.0;
 }
 
-void
-Dot_column::do_pre_processing ()
+SCM
+Dot_column::do_shifts (SCM l)
 {
-  Interval w;
-  for (int i=0; i < head_l_arr_.size (); i++)
-    w.unite (head_l_arr_[i]->extent (X_AXIS));
+  Link_array<Score_element> dots;
+  while (gh_pair_p (l))
+    {
+      dots.push (unsmob_element (gh_car (l)));
+      l = gh_cdr (l);
+    }
   
-  if (!w.empty_b ())
-    translate_axis (w[RIGHT] - extent(X_AXIS) [LEFT],X_AXIS);
-}
+  dots.sort (compare_position);
+  
+  if (dots.size () < 2)
+    return SCM_UNSPECIFIED;
+  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::position_f (dots[i]);
+      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 SCM_UNSPECIFIED;
+  
+  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++)
+    {
+      Score_element * d = dots[i];
+      Staff_symbol_referencer::set_position (d,pos);
+    }
+
+  return SCM_UNSPECIFIED;
+}
 
-Dot_column::Dot_column ()
+bool
+Dot_column::has_interface (Score_element*m)
 {
-  set_axes(X_AXIS,X_AXIS);
+  return m && m->has_interface (ly_symbol2scm ("dot-column-interface"));
 }