]> git.donarmstrong.com Git - lilypond.git/commitdiff
more cleanups, convert-to-springs and code removals
authorJoe Neeman <joeneeman@gmail.com>
Tue, 19 Jun 2007 08:05:03 +0000 (18:05 +1000)
committerJoe Neeman <joeneeman@gmail.com>
Tue, 26 Jun 2007 12:40:30 +0000 (15:40 +0300)
lily/include/paper-column.hh
lily/include/spacing-spanner.hh
lily/include/spring.hh
lily/paper-column.cc
lily/spacing-basic.cc
lily/spacing-interface.cc
lily/spacing-loose-columns.cc
lily/spacing-spanner.cc

index 0157eb6bb9a64079af671078cca25d0f2102e3a1..9109e4e6971fd18f3e23c8cb70bfc948a37182fd 100644 (file)
@@ -48,6 +48,7 @@ public:
   static Moment when_mom (Grob *);
   static bool is_used (Grob *);
   static bool is_breakable (Grob *);
+  static Real minimum_distance (Grob *l, Grob *r);
 };
 
 #endif // PAPER_COLUMN_HH
index 60302736bdf66ee6c1f9144afec41230aa46b070..9193a187d476324cc4fa5332239d7078efc1d596 100644 (file)
@@ -13,6 +13,7 @@
 #include "rational.hh"
 #include "std-vector.hh"
 #include "grob-interface.hh"
+#include "spring.hh"
 
 class Spacing_spanner
 {
@@ -34,9 +35,7 @@ private:
 public:
   static vector<Grob*> get_columns (Grob *me);
   static Real note_spacing (Grob *, Grob *, Grob *, Spacing_options const *);
-  static void standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
-                                                Real *fixed, Real *space,
-                                                Spacing_options const *);
+  static Spring standard_breakable_column_spacing (Grob *me, Item *l, Item *r, Spacing_options const *);
   
   DECLARE_SCHEME_CALLBACK (set_springs, (SCM));
   DECLARE_SCHEME_CALLBACK (calc_common_shortest_duration, (SCM));
index d9b40cca4654b3c02ef3ad2c9c1c2f0ca49ee041..a5c2ef0a4b5d89482d57bd4af20a96b925174d0e 100644 (file)
@@ -34,6 +34,7 @@ public:
   void set_min_distance (Real);
   void set_inverse_stretch_strength (Real);
   void set_inverse_compress_strength (Real);
+  void set_default_strength ();
 
   void operator*= (Real);
   Grob *other_;
index e3f462894acae72e750eb702083073e59922af83..d09518a590d8671de27d3502f37e367b83f5b6b5 100644 (file)
@@ -22,6 +22,7 @@
 #include "system.hh"
 #include "spring.hh"
 #include "lookup.hh"
+#include "separation-item.hh"
 #include "string-convert.hh"
 
 Grob *
@@ -136,6 +137,30 @@ Paper_column::is_breakable (Grob *me)
   return scm_is_symbol (me->get_property ("line-break-permission"));
 }
 
+Real
+Paper_column::minimum_distance (Grob *left, Grob *right)
+{
+  Drul_array<Grob*> cols (left, right);
+  Drul_array<Skyline> skys = Drul_array<Skyline> (Skyline (RIGHT), Skyline (LEFT));
+
+  Direction d = LEFT;
+  do
+    {
+      extract_grob_set (cols[d], "elements", elts);
+
+      for (vsize i = 0; i < elts.size (); i++)
+       if (Separation_item::has_interface (elts[i]))
+         {
+           Skyline_pair *sp = Skyline_pair::unsmob (elts[i]->get_property ("horizontal-skylines"));
+           if (sp)
+             skys[d].merge ((*sp)[-d]);
+         }
+    }
+  while (flip (&d) != LEFT);
+
+  return min (0.0, skys[LEFT].distance (skys[RIGHT]));
+}
+
 /*
   Print a vertical line and  the rank number, to aid debugging.
 */
index 0d73b4af0bebd07e5c3b82b90662d4aa55c156c8..e2f69b0bea114bfded7c67e7228788dfd4a3a79f 100644 (file)
@@ -14,6 +14,8 @@
 #include "warn.hh"
 #include "pointer-group-interface.hh"
 #include "system.hh"
+#include "spacing-interface.hh"
+#include "spring.hh"
 
 /*
   LilyPond spaces by taking a simple-minded spacing algorithm, and
   The one-size-fits all spacing. It doesn't take into account
   different spacing wishes from one to the next column.
 */
-void
-Spacing_spanner::standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
-                                                   Real *fixed, Real *space,
-                                                   Spacing_options const *options)
+Spring
+Spacing_spanner::standard_breakable_column_spacing (Grob *me, Item *l, Item *r, Spacing_options const *options)
 {
-  *fixed = 0.0;
-  Direction d = LEFT;
-  Drul_array<Item *> cols (l, r);
-
-  do
-    {
-      /*
-       TODO: this is fishy, the extent gets distorted due to wide
-       \marks, so better not do this.
-       */
-      if (!Paper_column::is_musical (cols[d]))
-       {
-         /*
-           Tied accidentals over barlines cause problems, so lets see
-           what happens if we do this for non musical columns only.
-         */
-         Interval lext = cols[d]->extent (cols [d], X_AXIS);
-         if (!lext.is_empty ())
-           *fixed += -d * lext[-d];
-       }
-    }
-  while (flip (&d) != LEFT);
+  Real min_dist = Paper_column::minimum_distance (l, r);
+  Real ideal;
 
   if (Paper_column::is_breakable (l) && Paper_column::is_breakable (r))
     {
@@ -61,7 +41,7 @@ Spacing_spanner::standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
 
       Real incr = robust_scm2double (me->get_property ("spacing-increment"), 1);
 
-      *space = *fixed + incr * double (mlen.main_part_ / options->global_shortest_) * 0.8;
+      ideal = min_dist + incr * double (mlen.main_part_ / options->global_shortest_) * 0.8;
     }
   else
     {
@@ -73,11 +53,12 @@ Spacing_spanner::standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
            In this case, Staff_spacing should handle the job,
            using dt when it is 0 is silly.
          */
-         *space = *fixed + 0.5;
+         ideal = min_dist + 0.5;
        }
       else
-       *space = *fixed + options->get_duration_space (dt.main_part_);
+       ideal = min_dist + options->get_duration_space (dt.main_part_);
     }
+  return Spring (ideal, min_dist);
 }
 
 Moment *
index 33a4e14d399c1d679fe2e4cbf99b091759f52299..b5974d301cad4809892a19a95981f9ad3cbc40e5 100644 (file)
@@ -30,7 +30,7 @@ Spacing_interface::minimum_distance (Grob *me)
      the broken piece.
 
      FIXME: this only works for the left column. There is only one spacing
-     grob for the original and non-original right column and we have no way
+     grob for both the original and non-original right columns and we have no way
      to tell which one we need */
 
   Grob *orig = me->original () ? me->original () : me;
index ee19b29ab766c14176bab2c7b7dce116ad463a23..a59fa7d0f9350734baa6717ab25017ed25ec59cf 100644 (file)
@@ -127,14 +127,11 @@ set_loose_columns (System *which, Column_x_positions const *posns)
                                                             &options);
          else
            {
-             Real fixed, space;
-             
-             Spacing_spanner::standard_breakable_column_spacing (spacing, 
-                                                                 loose_col, next_col,
-                                                                 &fixed, &space,
-                                                                 &options);
-
-             base_note_space = space;
+             Spring spring = Spacing_spanner::standard_breakable_column_spacing (spacing,
+                                                                                 loose_col, next_col,
+                                                                                 &options);
+
+             base_note_space = spring.distance ();
            }
 
          base_note_space = max (base_note_space,
index d158883dadf40a9c9ef5ee63e07bda5e9cf9dc2f..5394677d7c8c6e89c899ea4538be8f93c2323d20 100644 (file)
@@ -370,12 +370,8 @@ void
 Spacing_spanner::breakable_column_spacing (Grob *me, Item *l, Item *r,
                                           Spacing_options const *options)
 {
-  Real compound_fixed = 0.0;
-  Real compound_space = 0.0;
-  Real max_fixed = 0.0;
-  Real max_space = 0.0;
-  
-  int wish_count = 0;
+  vector<Spring> springs;
+  Spring spring;
 
   Moment dt = Paper_column::when_mom (r) - Paper_column::when_mom (l);
 
@@ -396,67 +392,40 @@ Spacing_spanner::breakable_column_spacing (Grob *me, Item *l, Item *r,
          */
          assert (spacing_grob->get_column () == l);
 
-         Spring sp = Staff_spacing::get_spacing (spacing_grob);
-         Real space = sp.distance ();
-         Real fixed = sp.min_distance ();
-
-         if (Paper_column::when_mom (r).grace_part_)
-           {
-             /*
-               Correct for grace notes.
-
-               Ugh. The 0.8 is arbitrary.
-             */
-             space *= 0.8;
-           }
-
-         max_space = max (max_space, space);
-         max_fixed = max (max_fixed, fixed);
-         
-         compound_space += space;
-         compound_fixed += fixed;
-         wish_count++;
+         springs.push_back (Staff_spacing::get_spacing (spacing_grob));
        }
     }
 
-  if (compound_space <= 0.0 || !wish_count)
-    {
-      standard_breakable_column_spacing (me, l, r, &compound_fixed, &compound_space,
-                                        options);
-      wish_count = 1;
-    }
+  if (springs.empty ())
+    spring = standard_breakable_column_spacing (me, l, r, options);
   else
+    spring = merge_springs (springs);
+
+  if (Paper_column::when_mom (r).grace_part_)
     {
-      if (to_boolean (me->get_property ("average-spacing-wishes")))
-       {
-         compound_space /= wish_count;
-         compound_fixed /= wish_count;
-       }
-      else
-       {
-         compound_fixed = max_fixed;
-         compound_space = max_space;
-       }
-      
+      /*
+       Correct for grace notes.
+       
+       Ugh. The 0.8 is arbitrary.
+      */
+      spring *= 0.8;
     }
 
   if (Paper_column::is_musical (r)
       && l->break_status_dir () == CENTER
       && fills_measure (me, l, r))
     {
-      compound_space += 1.0; 
+      spring.set_distance (spring.distance () + 1.0);
+      spring.set_default_strength ();
     }
   
   if (options->stretch_uniformly_ && l->break_status_dir () != RIGHT)
-    compound_fixed = 0.0;
-
-  assert (!isinf (compound_space));
-  compound_space = max (compound_space, compound_fixed);
-
-  Real inverse_strength = (compound_space - compound_fixed);
-  Real distance = compound_space;
+    {
+      spring.set_min_distance (0.0);
+      spring.set_default_strength ();
+    }
 
-  Spaceable_grob::add_spring (l, r, distance, inverse_strength);
+  Spaceable_grob::add_spring (l, r, spring);
 }
 
 ADD_INTERFACE (Spacing_spanner,