]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dot-column.cc
release: 1.3.96
[lilypond.git] / lily / dot-column.cc
index 730228eeecad7cdbeae88bcb94eb9cf3808e3c71..a9838ae13b25609a68a41bbdde03ab62c0443896 100644 (file)
@@ -3,49 +3,30 @@
 
   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)
-{
-  Group_interface gi (this, "dots");
-  gi.add_element (d);
 
-  add_dependency (d);
-  add_element (d);
-}
 
-void
-Dot_column::add_head (Rhythmic_head *r)
-{
-  if (!r->dots_l ())
-    return ;
-
-  add_support (r);
-  add_dots (r->dots_l ());
-}
 
 
-int
-Dot_column::compare (Dots * const &d1, Dots * const &d2)
+void
+Dot_column::set_interface (Score_element* me)
 {
-  return int (d1->position_f () - d2->position_f ());
-}
 
-
-Dot_column::Dot_column ()
-{
-  Group_interface gi (this, "dots");
-  gi.set_interface ();
+  Directional_element_interface::set (me, RIGHT);
   
-  set_direction (RIGHT);
-  set_axes(X_AXIS,X_AXIS);
+  Axis_group_interface::set_interface (me);
+  Axis_group_interface::set_axes (me, X_AXIS,X_AXIS);
 }
 
 /*
@@ -63,14 +44,35 @@ Dot_column::Dot_column ()
 
    Should be smarter.
  */
-void
-Dot_column::do_post_processing ()
+
+
+MAKE_SCHEME_CALLBACK(Dot_column,force_shift_callback,2);
+SCM
+Dot_column::force_shift_callback (SCM element_smob, SCM axis)
+{
+  Score_element *me = unsmob_element (element_smob);
+  Axis a = (Axis) gh_scm2int (axis);
+  assert (a == Y_AXIS);
+ me = me->parent_l (X_AXIS);
+  SCM dots = me->get_elt_property ("dots");
+  do_shifts (dots);
+  return gh_double2scm (0.0);
+}
+
+SCM
+Dot_column::do_shifts (SCM l)
 {
-  Link_array<Dots> dots = Group_interface__extract_elements (this, (Dots*)0 , "dots"); 
-  dots.sort (Dot_column::compare);
+  Link_array<Score_element> dots;
+  while (gh_pair_p (l))
+    {
+      dots.push (unsmob_element (gh_car (l)));
+      l = gh_cdr (l);
+    }
+  
+  dots.sort (compare_position);
   
   if (dots.size () < 2)
-    return;
+    return SCM_UNSPECIFIED;
   Slice s;
   s.set_empty ();
 
@@ -78,16 +80,19 @@ Dot_column::do_post_processing ()
   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) dots[i]->position_f ())
-         conflicts++;
-      taken_posns.push ((int)dots[i]->position_f ());
-      s.unite (Slice ((int)dots[i]->position_f (),
-                     (int)dots[i]->position_f ()));      
+       {
+         if (taken_posns[j] == (int) p)
+           conflicts++;
+       }
+      taken_posns.push ((int)p);
+      s.unite (Slice ((int)p,
+                     (int)p));      
     }
 
   if (!conflicts)
-    return;
+    return SCM_UNSPECIFIED;
   
   int  middle = s.center ();
   /*
@@ -97,8 +102,33 @@ Dot_column::do_post_processing ()
   if (!(pos % 2))
     pos ++;                    // center () rounds down.
 
-  for (int i=0; i  <dots.size (); pos += 2, i++)
+  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;
+}
+
+bool
+Dot_column::has_interface (Score_element*m)
+{
+  return m && m->has_interface (ly_symbol2scm ("dot-column-interface"));
+}
+
+
+void
+Dot_column::add_head (Score_element * me, Score_element *rh)
+{
+  Score_element * d = unsmob_element (rh->get_elt_property ("dot"));
+  if (d)
     {
-      dots[i]->set_position(pos);
+      Side_position::add_support (me,rh);
+
+      Pointer_group_interface ::add_element (me, "dots",d);
+      d->add_offset_callback (Dot_column::force_shift_callback_proc , Y_AXIS);
+      Axis_group_interface::add_element (me, d);
     }
 }
+