]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/separating-group-spanner.cc
Imported sources
[lilypond.git] / lily / separating-group-spanner.cc
index d102e35bdb4c36945d71eb7424d673c5ceab69a9..868e49ecdd2cdb29a41c92a6b35ba8d2b36ce1f9 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
 #include "group-interface.hh"
 
 void
-Separating_group_spanner::find_rods (Item * r, SCM next)
+Separating_group_spanner::find_rods (Item * r, SCM next, Real padding)
 {
-  Interval ri (Separation_item::my_width (r));
-  if (ri.empty_b ())
-    return;
 
   /*
-    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))
+    This is an inner loop: look for the first normal (unbroken) Left
+    grob.  This looks like an inner loop (ie. quadratic total), but in
+    most cases, the interesting L will just be the first entry of
+    NEXT, making it linear in most of the cases.
+  */
+  if (Separation_item::width (r).is_empty ())
+    return; 
+
+
+  for(; gh_pair_p (next); next = ly_cdr (next))
     {
-      Item *l = dynamic_cast<Item*> (unsmob_grob (gh_car( next)));
+      Item *l = dynamic_cast<Item*> (unsmob_grob (ly_car( next)));
       Item *lb = l->find_prebroken_piece (RIGHT);
 
       if (lb)
        {
-         Interval li (Separation_item::my_width (lb));
-
-         if (!li.empty_b ())
+         Interval li (Separation_item::width (lb));
+         Interval ri (Separation_item::conditional_width (r, lb));
+         if (!li.is_empty () && !ri.is_empty ())
            {
              Rod rod;
 
              rod.item_l_drul_[LEFT] = lb;
              rod.item_l_drul_[RIGHT] = r;
 
-             rod.distance_f_ = li[RIGHT] - ri[LEFT];
-       
-             rod.columnize ();
+             rod.distance_ = li[RIGHT] - ri[LEFT] + padding;
              rod.add_to_cols ();
            }
        }
 
-      Interval li (Separation_item::my_width (l));
-      if (!li.empty_b ())
+      Interval li (Separation_item::width (l));
+      Interval ri (Separation_item::conditional_width (r, l));
+      if (!li.is_empty () && !ri.is_empty ())
        {
          Rod rod;
 
          rod.item_l_drul_[LEFT] =l;
          rod.item_l_drul_[RIGHT]=r;
 
-         rod.distance_f_ = li[RIGHT] - ri[LEFT];
+         rod.distance_ = li[RIGHT] - ri[LEFT] + padding;
        
-         rod.columnize ();
          rod.add_to_cols ();
-
          break;
        }
-      else
-       /*
-         this grob doesn't cause a constraint. We look further until we
-         find one that does.  */
-       ;
+
+      /*
+       this grob doesn't cause a constraint. We look further until we
+       find one that does.
+      */
+
     }
 }
 
@@ -76,14 +77,15 @@ SCM
 Separating_group_spanner::set_spacing_rods (SCM smob)
 {
   Grob*me = unsmob_grob (smob);
+  Real padding = robust_scm2double (me->get_grob_property ("padding"), 0.1);
   
-  for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s) && gh_pair_p (gh_cdr (s)); s = gh_cdr (s))
+  for (SCM s = me->get_grob_property ("elements"); gh_pair_p (s) && gh_pair_p (ly_cdr (s)); s = ly_cdr (s))
     {
       /*
        Order of elements is reversed!
        */
-      SCM elt = gh_car (s);
-      Item *r = dynamic_cast<Item*> (unsmob_grob (elt));
+      SCM elt = ly_car (s);
+      Item *r = unsmob_item (elt);
 
       if (!r)
        continue;
@@ -91,48 +93,25 @@ Separating_group_spanner::set_spacing_rods (SCM smob)
       Item *rb
        = dynamic_cast<Item*> (r->find_prebroken_piece (LEFT));
       
-      find_rods (r, gh_cdr (s));
+      find_rods (r, ly_cdr (s), padding);
       if (rb)
-       find_rods (rb, gh_cdr (s));
+       find_rods (rb, ly_cdr (s), padding);
     }
 
-#if 0
-  /*
-    TODO; restore this.
-   */
-  /*
-    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 ();
-#endif
   return SCM_UNSPECIFIED ;
 }
 
 void
 Separating_group_spanner::add_spacing_unit (Grob* me ,Item*i)
 {
-  Pointer_group_interface::add_element (me, "elements",i);
+  Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), i);
   me->add_dependency (i);
 }
 
 
-void
-Separating_group_spanner::set_interface (Grob*)
-{
-}
 
-bool
-Separating_group_spanner::has_interface (Grob*)
-{//todo
-  assert (false);
-}
+
+
+ADD_INTERFACE (Separating_group_spanner,"separation-spanner-interface",
+  "Spanner that containing @code{separation-item-interface} grobs to calculate rods",
+  "");