]> 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 329a77a7dd0daf425d68950c90ba2bd572519e5b..0570741117b0a4e36b2bb4f08113fccfc5329d65 100644 (file)
 /*
-  spacing-loose-columns.cc --  implement loose column spacing.
+  spacing-loose-columns.cc -- implement loose column spacing.
 
   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.  */
 void
-set_loose_columns (Systemwhich, Column_x_positions const *posns)
+set_loose_columns (System *which, Column_x_positions const *posns)
 {
   int loose_col_count = posns->loose_cols_.size ();
+  if (!loose_col_count)
+    return;
+
+  Real default_padding = 1.0;
   for (int i = 0; i < loose_col_count; i++)
     {
       int divide_over = 1;
-      Item *loose = dynamic_cast<Item*> (posns->loose_cols_[i]);
-      Paper_column* col = dynamic_cast<Paper_column*> (loose);
-      
-      if (col->system_)
+      Item *loose = dynamic_cast<Item *> (posns->loose_cols_[i]);
+      Paper_column *col = dynamic_cast<Paper_column *> (loose);
+
+      if (col->get_system ())
        continue;
-      
+
       Item *left = 0;
       Item *right = 0;
+
+      vector<Item*> clique;
       while (1)
        {
-         SCM between = loose->get_property ("between-cols");
+         SCM between = loose->get_object ("between-cols");
          if (!scm_is_pair (between))
            break;
 
-         Item *le = dynamic_cast<Item*> (unsmob_grob (scm_car (between)));
-         Item *re = dynamic_cast<Item*> (unsmob_grob (scm_cdr (between)));
+         Item *le = dynamic_cast<Item *> (unsmob_grob (scm_car (between)));
+         Item *re = dynamic_cast<Item *> (unsmob_grob (scm_cdr (between)));
 
-         if (!(le && re))
+         if (! (le && re))
            break;
-         
+
          if (!left && le)
            {
              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 ();
        }
 
       if (!right->get_system ())
        right = right->find_prebroken_piece (LEFT);
-      
+
+      clique.push_back (right);
+
       Grob *common = right->common_refpoint (left, X_AXIS);
+      Item *finished_right_column = clique.back ();
 
-      int count = 0;
-      Real total_space = 0.0;  
-      Real total_fixed = 0.0; 
-      for (SCM wish = col->get_property ("spacing-wishes"); scm_is_pair (wish); wish = scm_cdr (wish))
+      for (vsize j = clique.size () - 2; j > 0; j--)
        {
-         Grob *spacing = unsmob_grob (scm_car (wish));
-         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;
+             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;
-             count ++;
+             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] + 1.0;
-         right_point = right->extent (common, X_AXIS)[LEFT];
-       }
-#if 0
-      Real left_point = left->extent (common, X_AXIS)[RIGHT];
+             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 space_left = ((right_point - left_point) >? 0.0)
-       - (my_extent.is_empty() ? 0.0 : my_extent.length ());
+         Real my_offset = right_point - distance_to_next;
 
-      Real padding = (space_left / 2) <? 1.0;
-      /*
-       Put it just left of the right column, with a bit of extra space 
-       */
-#endif
-      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;
+       }
     }
 }