From f2ab9616f7298f0cf497dc118cba1c4db4ae2d80 Mon Sep 17 00:00:00 2001
From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Mon, 1 Jan 2007 14:36:33 +0100
Subject: [PATCH] even more robust attachment of loose columns.

---
 lily/include/spacing-spanner.hh | 18 ++++++++----------
 lily/spacing-loose-columns.cc   | 16 +++++++++++++++-
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/lily/include/spacing-spanner.hh b/lily/include/spacing-spanner.hh
index 49db288606..f1e6116b33 100644
--- a/lily/include/spacing-spanner.hh
+++ b/lily/include/spacing-spanner.hh
@@ -14,23 +14,15 @@
 #include "rational.hh"
 #include "std-vector.hh"
 
-/*
-  TODO: prune to public interface.
-*/
 class Spacing_spanner
-
 {
-public:
+private:
   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,
 				     Spacing_options const *options);
-  static void standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
-						 Real *fixed, Real *space,
-						 Spacing_options const *);
   static Real default_bar_spacing (Grob *, Grob *, Grob *, Moment);
-  static Real note_spacing (Grob *, Grob *, Grob *, Spacing_options const *, bool *);
   static Real get_duration_space (Moment dur, Spacing_options const *, bool *);
   static Rational effective_shortest_duration (Grob *me, vector<Grob*> const &all);
   static void breakable_column_spacing (Grob *, Item *l, Item *r, Spacing_options const *);
@@ -40,7 +32,13 @@ public:
   static void generate_springs (Grob *me, vector<Grob*> const &cols, Spacing_options const *);
   static void musical_column_spacing (Grob *, Item *, Item *, Spacing_options const *);
   static vector<Grob*> get_columns (Spanner *me);
-
+  
+public:
+  static Real note_spacing (Grob *, Grob *, Grob *, Spacing_options const *, bool *);
+  static void standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
+						 Real *fixed, Real *space,
+						 Spacing_options const *);
+  
   DECLARE_SCHEME_CALLBACK (set_springs, (SCM));
   DECLARE_SCHEME_CALLBACK (calc_common_shortest_duration, (SCM));
   static bool has_interface (Grob *);
diff --git a/lily/spacing-loose-columns.cc b/lily/spacing-loose-columns.cc
index 069ff0e231..4102ecdecc 100644
--- a/lily/spacing-loose-columns.cc
+++ b/lily/spacing-loose-columns.cc
@@ -77,9 +77,23 @@ set_loose_columns (System *which, Column_x_positions const *posns)
       else
 	{
 	  clique.back ()->programming_error ("Loose column does not have right side to attach to.");
-	  right = which->get_bound (RIGHT);
+	  System *base_system = dynamic_cast<System*> (which->original ());
+	  int j = Paper_column::get_rank (clique.back ()) + 1;
+	  int end_rank = Paper_column::get_rank (which->get_bound (RIGHT));
+	  extract_grob_set (base_system, "columns", base_cols);
+	  for (; j < end_rank; j++)
+	    {
+	      if (base_cols[j]->get_system () == which)
+		right = dynamic_cast<Item*> ((Grob*)base_cols[j]);
+	    }
 	}
       
+
+      if (!right)
+	{
+	  programming_error ("Can't attach loose column sensibly. Attaching to end of system.");
+	  right = which->get_bound (RIGHT);
+	}
       Grob *common = right->common_refpoint (left, X_AXIS);
 
       clique.push_back (right);
-- 
2.39.5