]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dot-column.cc
release: 1.5.47
[lilypond.git] / lily / dot-column.cc
index 3d3f73f41045137a1988edd53d669a849791c8fc..584b3616e64e4286abf7fa56aafff7a7ebb6f1ae 100644 (file)
@@ -3,57 +3,59 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2002 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"
+#include "stem.hh"
 
-void
-Dot_column::add_dots (Dots *d)
-{
-  dot_l_arr_.push (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_);
-}
+/*
+  TODO: let Dot_column communicate with stem via Note_column.
+ */
 
-void
-Dot_column::do_substitute_element_pointer (Score_element*o,Score_element*n)
+MAKE_SCHEME_CALLBACK (Dot_column,force_shift_callback,2);
+SCM
+Dot_column::force_shift_callback (SCM element_smob, SCM axis)
 {
-  Note_head_side::do_substitute_element_pointer (o,n);
-  if (Dots * d = dynamic_cast<Dots*> (o))
-    dot_l_arr_.substitute (d, dynamic_cast<Dots*> (n));
+  Grob *me = unsmob_grob (element_smob);
+  Axis a = (Axis) gh_scm2int (axis);
+  assert (a == Y_AXIS);
+  me = me->get_parent (X_AXIS);
+  SCM l = me->get_grob_property ("dots");
+  do_shifts (l);
+  return gh_double2scm (0.0);
 }
 
-int
-Dot_column::compare (Dots * const &d1, Dots * const &d2)
+MAKE_SCHEME_CALLBACK(Dot_column,side_position, 2);
+SCM
+Dot_column::side_position (SCM element_smob, SCM axis)
 {
-  return int (d1->position_f () - d2->position_f ());
-}
+  Grob *me = unsmob_grob (element_smob);
+  Axis a = (Axis) gh_scm2int (axis);
+  assert (a == X_AXIS);
+
+  Grob * stem = unsmob_grob (me->get_grob_property ("stem"));
+  if (stem
+      && !Stem::beam_l (stem)
+      && Stem::flag_i (stem))
+    {
+      /*
+       trigger stem end & direction calculation.
 
-void
-Dot_column::do_pre_processing ()
-{
-  dot_l_arr_.sort (Dot_column::compare);
-  Note_head_side::do_pre_processing ();
+       This will add the stem to the support if a flag collision happens.
+       */
+      Stem::stem_end_position (stem); 
+    }
+  return Side_position_interface::aligned_side (element_smob, axis);
 }
 
-Dot_column::Dot_column ()
-{
-  notehead_align_dir_ = RIGHT;
-  set_axes(X_AXIS,X_AXIS);
-}
 
 /*
   Will fuck up in this case.
@@ -70,39 +72,83 @@ Dot_column::Dot_column ()
 
    Should be smarter.
  */
-void
-Dot_column::do_post_processing ()
+SCM
+Dot_column::do_shifts (SCM l)
 {
-  if (dot_l_arr_.size () < 2)
-    return;
+  Link_array<Grob> dots;
+  while (gh_pair_p (l))
+    {
+      dots.push (unsmob_grob (ly_car (l)));
+      l = ly_cdr (l);
+    }
+  
+  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 < dot_l_arr_.size (); i++)
+  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) dot_l_arr_[i]->position_f ())
-         conflicts++;
-      taken_posns.push ((int)dot_l_arr_[i]->position_f ());
-      s.unite (Slice ((int)dot_l_arr_[i]->position_f (),
-                     (int)dot_l_arr_[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 ();
   /*
     +1 -> off by one 
    */
-  int pos = middle - dot_l_arr_.size () + 1;
-  if (!(pos % 2))
+  int pos = middle - dots.size () + 1;
+  if (! (pos % 2))
     pos ++;                    // center () rounds down.
 
-  for (int i=0; i  <dot_l_arr_.size (); pos += 2, i++)
+  for (int i=0; i < dots.size (); pos += 2, i++)
+    {
+      Grob * d = dots[i];
+      Staff_symbol_referencer::set_position (d,pos);
+    }
+
+  return SCM_UNSPECIFIED;
+}
+
+bool
+Dot_column::has_interface (Grob*m)
+{
+  return m && m->has_interface (ly_symbol2scm ("dot-column-interface"));
+}
+
+
+void
+Dot_column::add_head (Grob * me, Grob *rh)
+{
+  Grob * d = unsmob_grob (rh->get_grob_property ("dot"));
+  if (d)
     {
-      dot_l_arr_[i]->set_position(pos);
+      Side_position_interface::add_support (me,rh);
+
+      Pointer_group_interface::add_grob (me, ly_symbol2scm ("dots"), d);
+      d->add_offset_callback (Dot_column::force_shift_callback_proc , Y_AXIS);
+      Axis_group_interface::add_element (me, d);
     }
 }
+
+
+
+
+ADD_INTERFACE (Dot_column, "dot-column-interface",
+  "Interface that groups dots so they form a column",
+  "stem");
+