From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Sun, 17 Dec 2006 15:22:37 +0000 (+0100)
Subject: Fix #176.
X-Git-Tag: release/2.10.4-1~18
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=775b2452612b545669d0a34a0f0b1ef0dfd1e356;p=lilypond.git

Fix #176.

Robustness/cleanups for borderline cases with floating grace notes.
---

diff --git a/lily/include/spacing-spanner.hh b/lily/include/spacing-spanner.hh
index b1467225b7..49db288606 100644
--- a/lily/include/spacing-spanner.hh
+++ b/lily/include/spacing-spanner.hh
@@ -18,8 +18,10 @@
   TODO: prune to public interface.
 */
 class Spacing_spanner
+
 {
 public:
+  static void set_distances_for_loose_col (Grob *me, Grob *c, Drul_array<Item *> next_door, Spacing_options const *);
   static void generate_pair_spacing (Grob *me,
 				     Paper_column *l, Paper_column *r,
 				     Paper_column *nextr,
diff --git a/lily/pointer-group-interface.cc b/lily/pointer-group-interface.cc
index 2d58941b72..3b556f0c11 100644
--- a/lily/pointer-group-interface.cc
+++ b/lily/pointer-group-interface.cc
@@ -74,7 +74,9 @@ ly_scm2link_array (SCM x)
 vector<Grob*> const &
 internal_extract_grob_array (Grob const *elt, SCM symbol)
 {
-  return ly_scm2link_array (elt->internal_get_object (symbol));
+  return elt
+    ? ly_scm2link_array (elt->internal_get_object (symbol))
+    : empty_array;
 }
 
 vector<Item*>
diff --git a/lily/spacing-determine-loose-columns.cc b/lily/spacing-determine-loose-columns.cc
index ccb37a29d5..a6a90d9846 100644
--- a/lily/spacing-determine-loose-columns.cc
+++ b/lily/spacing-determine-loose-columns.cc
@@ -36,18 +36,19 @@ is_loose_column (Grob *l, Grob *col, Grob *r, Spacing_options const *options)
   if (!to_boolean (col->get_property ("allow-loose-spacing")))
     return false;
   
+
   if ((options->float_nonmusical_columns_
        ||options->float_grace_columns_)
       && Paper_column::when_mom (col).grace_part_)
-    return true;
+    {
+      return true;
+    }
 
+  
   if (Paper_column::is_musical (col)
       || Paper_column::is_breakable (col))
     return false;
 
-  extract_grob_set (col, "right-neighbors", rns);
-  extract_grob_set (col, "left-neighbors", lns);
-
   /*
     If this column doesn't have a proper neighbor, we should really
     make it loose, but spacing it correctly is more than we can
@@ -69,9 +70,14 @@ is_loose_column (Grob *l, Grob *col, Grob *r, Spacing_options const *options)
     such a borderline case.)
 
   */
+
+  extract_grob_set (col, "right-neighbors", rns);
+  extract_grob_set (col, "left-neighbors", lns);
+
   if (lns.empty () || rns.empty ())
     return false;
 
+  
   Item *l_neighbor = dynamic_cast<Item *> (lns[0]);
   Item *r_neighbor = dynamic_cast<Item *> (rns[0]);
 
@@ -125,6 +131,68 @@ is_loose_column (Grob *l, Grob *col, Grob *r, Spacing_options const *options)
   return true;
 }
 
+void
+Spacing_spanner::set_distances_for_loose_col (Grob *me, Grob *c,
+					      Drul_array<Item *> next_door,
+					      Spacing_options const *options)
+{
+  Direction d = LEFT;
+  Drul_array<Real> dists (0, 0);
+
+  do
+    {
+      Item *lc = dynamic_cast<Item *> ((d == LEFT) ? next_door[LEFT] : c);
+      Item *rc = dynamic_cast<Item *> (d == LEFT ? c : next_door[RIGHT]);
+
+      extract_grob_set (lc, "spacing-wishes", wishes);
+      for (vsize k = wishes.size (); k--;)
+	{
+	  Grob *sp = wishes[k];
+	  if (Note_spacing::left_column (sp) != lc
+	      || Note_spacing::right_column (sp) != rc)
+	    continue;
+
+	  if (Note_spacing::has_interface (sp))
+	    {
+	      /*
+		The note spacing should be taken from the musical
+		columns.
+	      */
+	      Real space = 0.0;
+	      Real fixed = 0.0;
+	      bool dummy = false;
+		  
+	      Real base = note_spacing (me, lc, rc, options, &dummy);
+	      Note_spacing::get_spacing (sp, rc, base, options->increment_,
+					 &space, &fixed);
+
+	      space -= options->increment_;
+
+	      dists[d] = max (dists[d], space);
+	    }
+	  else if (Staff_spacing::has_interface (sp))
+	    {
+	      Real space = 0;
+	      Real fixed_space = 0;
+	      Staff_spacing::get_spacing_params (sp,
+						 &space, &fixed_space);
+
+	      dists[d] = max (dists[d], fixed_space);
+	    }
+	  else
+	    programming_error ("Subversive spacing wish");
+	}
+    }
+  while (flip (&d) != LEFT);
+
+  Rod r;
+  r.distance_ = dists[LEFT] + dists[RIGHT];
+  r.item_drul_ = next_door;
+ 
+  r.add_to_cols (); 
+}
+
+
 /*
   Remove columns that are not tightly fitting from COLS. In the
   removed columns, set 'between-cols to the columns where it is in
@@ -157,71 +225,28 @@ Spacing_spanner::prune_loose_columns (Grob *me, vector<Grob*> *cols,
 	  */
 
 	  extract_grob_set (unsmob_grob (rns), "right-items", right_items);
-	  c->set_object ("between-cols", scm_cons (lns,
-						   right_items[0]->self_scm ()));
-
-	  /*
-	    Set distance constraints for loose columns
-	  */
-	  Drul_array<Grob *> next_door (cols->at (i - 1),
-					cols->at (i + 1));
-	  Direction d = LEFT;
-	  Drul_array<Real> dists (0, 0);
-
-	  do
+	  if (right_items.size () == 0 || !unsmob_grob (lns))
 	    {
-	      Item *lc = dynamic_cast<Item *> ((d == LEFT) ? next_door[LEFT] : c);
-	      Item *rc = dynamic_cast<Item *> (d == LEFT ? c : next_door[RIGHT]);
-
-	      extract_grob_set (lc, "spacing-wishes", wishes);
-	      for (vsize k = wishes.size (); k--;)
-		{
-		  Grob *sp = wishes[k];
-		  if (Note_spacing::left_column (sp) != lc
-		      || Note_spacing::right_column (sp) != rc)
-		    continue;
-
-		  if (Note_spacing::has_interface (sp))
-		    {
-		      /*
-			The note spacing should be taken from the musical
-			columns.
-		      */
-		      Real space = 0.0;
-		      Real fixed = 0.0;
-		      bool dummy = false;
-		  
-		      Real base = note_spacing (me, lc, rc, options, &dummy);
-		      Note_spacing::get_spacing (sp, rc, base, options->increment_,
-						 &space, &fixed);
-
-		      space -= options->increment_;
-
-		      dists[d] = max (dists[d], space);
-		    }
-		  else if (Staff_spacing::has_interface (sp))
-		    {
-		      Real space = 0;
-		      Real fixed_space = 0;
-		      Staff_spacing::get_spacing_params (sp,
-							 &space, &fixed_space);
-
-		      dists[d] = max (dists[d], fixed_space);
-		    }
-		  else
-		    programming_error ("Subversive spacing wish");
-		}
+	      c->programming_error ("Can't determine neighbors for floating column. ");
+	      c->set_object ("between-cols", scm_cons (cols->at (i-1)->self_scm (),
+						       cols->at (i+1)->self_scm ()));
 	    }
-	  while (flip (&d) != LEFT);
+	  else
+	    {
+	      c->set_object ("between-cols", scm_cons (lns,
+						       right_items[0]->self_scm ()));
 
-	  Rod r;
-	  r.distance_ = dists[LEFT] + dists[RIGHT];
-	  r.item_drul_[LEFT] = dynamic_cast<Item *> (cols->at (i - 1));
-	  r.item_drul_[RIGHT] = dynamic_cast<Item *> (cols->at (i + 1));
+	      /*
+		Set distance constraints for loose columns
+	      */
+	      Drul_array<Item *> next_door (dynamic_cast<Item*> (cols->at (i - 1)),
+					    dynamic_cast<Item*> (cols->at (i + 1)));
 
-	  r.add_to_cols ();
+	      set_distances_for_loose_col (me, c, next_door, options);
+	    }
 	}
-      else
+
+      if (!loose)
 	newcols.push_back (c);
     }