]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/separating-group-spanner.cc
release: 1.3.83
[lilypond.git] / lily / separating-group-spanner.cc
index 059afad994521fe15d33079eaf802d79ec5c9be0..628af83903ec87c95e267dad2692798f5cd35a4a 100644 (file)
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
 #include "separating-group-spanner.hh"
-#include "single-malt-grouping-item.hh"
-#include "p-col.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
+static void
+do_rod (Item *l, Item *r)
 {
-  Array<Rod> a;
+  Rod rod;
+
+  Interval li (Separation_item::my_width (l));
+  Interval ri (Separation_item::my_width (r));
+
+  rod.item_l_drul_[LEFT] =l;
+  rod.item_l_drul_[RIGHT]=r;
+
+  if (li.empty_b () || ri.empty_b ())
+    rod.distance_f_ = 0;
+  else
+    rod.distance_f_ = li[RIGHT] - ri[LEFT];
+
+  rod.columnize ();
+  rod.add_to_cols ();
+}
+  
+MAKE_SCHEME_CALLBACK(Separating_group_spanner,set_spacing_rods);
+SCM
+Separating_group_spanner::set_spacing_rods (SCM smob)
+{
+  Score_element*me = unsmob_element (smob);
   
-  for (int i=0; i < spacing_unit_l_arr_.size () -1; i++)
+  for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s) && gh_pair_p (gh_cdr (s)); s = gh_cdr (s))
     {
-      a.push (Rod (spacing_unit_l_arr_[i], spacing_unit_l_arr_[i+1]));
-      bool lb =spacing_unit_l_arr_[i]->column_l ()->breakable_b_;
+      /*
+       Order of elements is reversed!
+       */
+      SCM elt = gh_cadr (s);
+      SCM next_elt = gh_car (s);
+
+      Item *l = dynamic_cast<Item*> (unsmob_element (elt));
+      Item *r = dynamic_cast<Item*> (unsmob_element ( next_elt));
+
+      if (!r || !l)
+       continue;
+      
+      Item *lb
+       = dynamic_cast<Item*>(l->find_prebroken_piece (RIGHT));
+
+      Item *rb
+       = dynamic_cast<Item*>(r->find_prebroken_piece (LEFT));
+      
+      do_rod(l,  r);
       if (lb)
        {
-         Rod r((Single_malt_grouping_item*)
-                      spacing_unit_l_arr_[i]->find_prebroken_piece (RIGHT),
-                      spacing_unit_l_arr_[i+1]);
-         r.distance_f_ += paper ()->interline_f () *1.5;
-         a.push (r);
+         do_rod (lb, r);
        }
-      bool rb=spacing_unit_l_arr_[i+1]->column_l ()->breakable_b_;
+      
       if (rb)
        {
-         a.push (Rod (spacing_unit_l_arr_[i],
-                      (Single_malt_grouping_item*)
-                      spacing_unit_l_arr_[i+1]->find_prebroken_piece (LEFT)));
+         do_rod (l, rb);
        }
+      
       if (lb && rb)
        {
-         Rod r((Single_malt_grouping_item*)
-                      spacing_unit_l_arr_[i]->find_prebroken_piece (RIGHT),
-                      (Single_malt_grouping_item*)
-                      spacing_unit_l_arr_[i+1]->find_prebroken_piece (LEFT));
-         r.distance_f_ += paper ()->interline_f () *1.5;
-         a.push (r);
+         do_rod (lb, rb);
+
        }
     }
-      
-  return a;
+
+  /*
+    We've done our job, so we get lost. 
+   */
+  for (SCM s = me->get_elt_property ("elements"); gh_pair_p (s); s = gh_cdr (s))
+    {
+      Item * it =dynamic_cast<Item*>(unsmob_element (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 (Score_element* me ,Item*i)
 {
-  spacing_unit_l_arr_.push (i);
-  add_dependency (i);
+  Pointer_group_interface (me, "elements").add_element (i);
+  me->add_dependency (i);
 }
 
-IMPLEMENT_IS_TYPE_B1(Separating_group_spanner, Spanner);
 
 void
-Separating_group_spanner::do_substitute_dependency (Score_element*o, Score_element*n)
+Separating_group_spanner::set_interface (Score_element*me)
 {
-  if (o->is_type_b (Single_malt_grouping_item::static_name ()))
-    {
-      Single_malt_grouping_item*ns = n ?
-       (Single_malt_grouping_item*)dynamic_cast <Item *> (n) : 0;
-      spacing_unit_l_arr_.substitute ((Single_malt_grouping_item*)dynamic_cast <Item *> (o), ns);
-    }
-}
 
+}