]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/separating-group-spanner.cc
release: 1.5.4
[lilypond.git] / lily / separating-group-spanner.cc
index eca012b48500323dd39eaa660c55d693f35aed51..bc5e030994bd1404c465ac22bd4b2ee433a40fc3 100644 (file)
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998 Han-Wen Nienhuys <hanwen@cs.ruu.nl>
+  (c) 1998--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
 #include "separating-group-spanner.hh"
-#include "single-malt-grouping-item.hh"
+#include "separation-item.hh"
+#include "paper-column.hh"
+#include "paper-def.hh"
+#include "dimensions.hh"
+#include "group-interface.hh"
 
-Array<Rod>
-Separating_group_spanner::get_rods () const
+void
+Separating_group_spanner::find_rods (Item * r, SCM next)
 {
-  Array<Rod> a;
+  Interval ri (Separation_item::my_width (r));
+  if (ri.empty_b ())
+    return;
 
-  for (int i=0; i < spacing_unit_l_arr_.size () -1; i++)
+  /*
+    This is an inner loop, however, in most cases, the interesting L
+    will just be the first entry of NEXT, making it linear in most of
+    the cases.  */
+  for(; gh_pair_p (next); next = gh_cdr (next))
     {
-      a.push (Rod (spacing_unit_l_arr_[i], spacing_unit_l_arr_[i+1]));    
-      if (spacing_unit_l_arr_[i]->breakable_b_)
+      Item *l = dynamic_cast<Item*> (unsmob_grob (gh_car( next)));
+      Item *lb = l->find_prebroken_piece (RIGHT);
+
+      if (lb)
        {
-         a.push (Rod (spacing_unit_l_arr_[i]->find_prebroken_piece (RIGHT), spacing_unit_l_arr_[i+1]));
+         Interval li (Separation_item::my_width (lb));
+
+         if (!li.empty_b ())
+           {
+             Rod rod;
+
+             rod.item_l_drul_[LEFT] = lb;
+             rod.item_l_drul_[RIGHT] = r;
+
+             rod.distance_f_ = li[RIGHT] - ri[LEFT];
+       
+             rod.columnize ();
+             rod.add_to_cols ();
+           }
        }
-      if (spacing_unit_l_arr_[i+1]->breakable_b_)
+
+      Interval li (Separation_item::my_width (l));
+      if (!li.empty_b ())
        {
-         a.push (Rod (spacing_unit_l_arr_[i], spacing_unit_l_arr_[i+1]->find_prebroken_piece (LEFT)));
+         Rod rod;
+
+         rod.item_l_drul_[LEFT] =l;
+         rod.item_l_drul_[RIGHT]=r;
+
+         rod.distance_f_ = li[RIGHT] - ri[LEFT];
+       
+         rod.columnize ();
+         rod.add_to_cols ();
+
+         break;
        }
+      else
+       /*
+         this grob doesn't cause a constraint. We look further until we
+         find one that does.  */
+       ;
     }
+}
+
+MAKE_SCHEME_CALLBACK (Separating_group_spanner,set_spacing_rods,1);
+SCM
+Separating_group_spanner::set_spacing_rods (SCM smob)
+{
+  Grob*me = unsmob_grob (smob);
+  
+  for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s) && gh_pair_p (gh_cdr (s)); s = gh_cdr (s))
+    {
+      /*
+       Order of elements is reversed!
+       */
+      SCM elt = gh_car (s);
+      Item *r = dynamic_cast<Item*> (unsmob_grob (elt));
+
+      if (!r)
+       continue;
+
+      Item *rb
+       = dynamic_cast<Item*> (r->find_prebroken_piece (LEFT));
       
-  return a;
+      find_rods (r, gh_cdr (s));
+      if (rb)
+       find_rods (rb, gh_cdr (s));
+    }
+
+  /*
+    We've done our job, so we get lost. 
+   */
+  for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
+    {
+      Item * it =dynamic_cast<Item*> (unsmob_grob (gh_car (s)));
+      if (it && it->broken_b ())
+       {
+         it->find_prebroken_piece (LEFT) ->suicide ();
+         it->find_prebroken_piece (RIGHT)->suicide ();
+       }
+      it->suicide ();
+    }
+  me->suicide ();
+  return SCM_UNSPECIFIED ;
 }
 
 void
-Separating_group_spanner::add_spacing_unit (Single_malt_grouping_item*i)
+Separating_group_spanner::add_spacing_unit (Grob* me ,Item*i)
 {
-  spacing_unit_l_arr_.push (i);
-  add_dependency (i);
+  Pointer_group_interface::add_element (me, "elements",i);
+  me->add_dependency (i);
 }
 
-IMPLEMENT_IS_TYPE_B1(Separating_group_spanner, Spanner);
 
 void
-Separating_group_spanner::do_substitute_dependency (Score_elem*o, Score_elem*n)
+Separating_group_spanner::set_interface (Grob*)
 {
-  if (o->is_type_b (Single_malt_grouping_item::static_name ()))
-    {
-      Single_malt_grouping_item*ns = n ? (Single_malt_grouping_item*)n->item () : 0;
-      spacing_unit_l_arr_.substitute ((Single_malt_grouping_item*)o->item (), ns);
-    }
 }
 
+bool
+Separating_group_spanner::has_interface (Grob*)
+{//todo
+  assert (false);
+}