]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/spacing-loose-columns.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / spacing-loose-columns.cc
index a2f87ba6bf91a2682525026effe15284b1cb31e4..0570741117b0a4e36b2bb4f08113fccfc5329d65 100644 (file)
@@ -3,15 +3,18 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
-
 #include "system.hh"
 #include "paper-column.hh"
 #include "column-x-positions.hh"
 #include "pointer-group-interface.hh"
 #include "staff-spacing.hh"
+#include "note-spacing.hh"
+#include "spacing-spanner.hh"
+
+#include "moment.hh"
 
 /* Find the loose columns in POSNS, and drape them around the columns
    specified in BETWEEN-COLS.  */
@@ -20,7 +23,7 @@ set_loose_columns (System *which, Column_x_positions const *posns)
 {
   int loose_col_count = posns->loose_cols_.size ();
   if (!loose_col_count)
-    return; 
+    return;
 
   Real default_padding = 1.0;
   for (int i = 0; i < loose_col_count; i++)
@@ -34,6 +37,8 @@ set_loose_columns (System *which, Column_x_positions const *posns)
 
       Item *left = 0;
       Item *right = 0;
+
+      vector<Item*> clique;
       while (1)
        {
          SCM between = loose->get_object ("between-cols");
@@ -51,8 +56,12 @@ set_loose_columns (System *which, Column_x_positions const *posns)
              left = le->get_column ();
              if (!left->get_system ())
                left = left->find_prebroken_piece (RIGHT);
+
+             clique.push_back (left);
            }
 
+         clique.push_back (loose);
+
          divide_over++;
          loose = right = re->get_column ();
        }
@@ -60,50 +69,73 @@ set_loose_columns (System *which, Column_x_positions const *posns)
       if (!right->get_system ())
        right = right->find_prebroken_piece (LEFT);
 
-      Grob *common = right->common_refpoint (left, X_AXIS);
+      clique.push_back (right);
 
-      int count = 0;
-      Real total_space = 0.0;
-      Real total_fixed = 0.0;
+      Grob *common = right->common_refpoint (left, X_AXIS);
+      Item *finished_right_column = clique.back ();
 
-      extract_grob_set (col, "spacing-wishes", wishes);
-      for (int i = 0; i < wishes.size (); i++)
+      for (vsize j = clique.size () - 2; j > 0; j--)
        {
-         Grob *spacing = wishes[i];
-         if (Staff_spacing::has_interface (spacing))
+         int count = 0;
+         Real total_space = 0.0;
+         Real total_fixed = 0.0;
+
+         extract_grob_set (col, "spacing-wishes", wishes);
+         for (vsize i = 0; i < wishes.size (); i++)
            {
+             Grob *spacing = wishes[i];
              Real space = 0.0;
              Real fixed = 0.0;
-             Staff_spacing::get_spacing_params (spacing, &space, &fixed);
 
-             total_fixed += fixed;
-             total_space += space;
+             if (Staff_spacing::has_interface (spacing))
+               Staff_spacing::get_spacing_params (spacing, &space, &fixed);
+             else if (Note_spacing::has_interface (spacing))
+               {
+                 Spacing_options options;
+                 options.init ();
+
+                 fixed = robust_relative_extent (col, col, X_AXIS)[RIGHT];
+
+                 Moment dt = Paper_column::when_mom (right) - Paper_column::when_mom (col);
+                 bool expand;
+                 space = options.get_duration_space (dt, &expand);
+                 Note_spacing::get_spacing (spacing, right, space, options.increment_,
+                                            &space, &fixed);
+               }
+             else
+               continue;
+
              count++;
+
+             total_space += space;
+             total_fixed += fixed;
            }
-       }
 
-      Real right_point = 0.0;
-      Real distance_to_next = 0.0;
-      if (count)
-       {
-         total_space /= count;
-         total_fixed /= count;
+         Real distance_to_next = 0.0;
+         Real right_point = 0.0;
+         if (count)
+           {
+             total_space /= count;
+             total_fixed /= count;
 
-         distance_to_next = total_space;
-         right_point = right->relative_coordinate (common, X_AXIS);
-       }
-      else
-       {
-         Interval my_extent = col->extent (col, X_AXIS);
-         distance_to_next = my_extent[RIGHT] + default_padding;
-         right_point = right->extent (common, X_AXIS)[LEFT];
-       }
+             distance_to_next = total_space;
+             right_point
+               = finished_right_column->relative_coordinate (common, X_AXIS);
+           }
+         else
+           {
+             Interval my_extent = robust_relative_extent (col, col, X_AXIS);
+             distance_to_next = my_extent[RIGHT] + default_padding;
+             right_point = robust_relative_extent (finished_right_column, common, X_AXIS)[LEFT];
+           }
 
-      Real my_offset = right_point - distance_to_next;
+         Real my_offset = right_point - distance_to_next;
 
-      col->system_ = which;
-      col->translate_axis (my_offset - col->relative_coordinate (common, X_AXIS), X_AXIS);
+         col->system_ = which;
+         col->translate_axis (my_offset - col->relative_coordinate (common, X_AXIS), X_AXIS);
+
+         finished_right_column = col;
+       }
     }
 }
 
-