]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/spacing-basic.cc
Merge branch 'master' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / lily / spacing-basic.cc
index 4a11d75b48bf90f15af2d4662b3a47ff3927bb8c..63d97f265246b3eff0b5f8f74ad419838463f12b 100644 (file)
@@ -3,13 +3,17 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "spacing-spanner.hh"
+
+#include "spacing-options.hh"
 #include "moment.hh"
 #include "paper-column.hh"
 #include "warn.hh"
+#include "pointer-group-interface.hh"
+#include "system.hh"
 
 /*
   LilyPond spaces by taking a simple-minded spacing algorithm, and
@@ -75,6 +79,27 @@ Spacing_spanner::standard_breakable_column_spacing (Grob *me, Item *l, Item *r,
     }
 }
 
+Moment *
+get_measure_length (Grob *column)
+{
+  Grob * sys = column->get_parent (X_AXIS);
+
+  extract_grob_set (sys, "columns", cols);
+
+  vsize col_idx = Paper_column::get_rank (column);
+  
+  do
+    {
+      if (Moment *len = unsmob_moment (cols[col_idx]->get_property ("measure-length")))
+       {
+         return len;
+       }
+    }
+  while (col_idx-- != 0);
+  
+  return 0;
+}
+
 Real
 Spacing_spanner::note_spacing (Grob *me, Grob *lc, Grob *rc,
                               Spacing_options const *options,
@@ -90,7 +115,7 @@ Spacing_spanner::note_spacing (Grob *me, Grob *lc, Grob *rc,
 
   if (! shortest_playing_len.to_bool ())
     {
-      programming_error ("can't find a ruling note at " + Paper_column::when_mom (lc).to_string ());
+      programming_error ("cannot find a ruling note at: " + Paper_column::when_mom (lc).to_string ());
       shortest_playing_len = 1;
     }
 
@@ -98,25 +123,25 @@ Spacing_spanner::note_spacing (Grob *me, Grob *lc, Grob *rc,
   Moment rwhen = Paper_column::when_mom (rc);
 
   Moment delta_t = rwhen - lwhen;
-  if (!Paper_column::is_musical (rc))
+
+  /*
+    when toying with mmrests, it is possible to have musical
+    column on the left and non-musical on the right, spanning
+    several measures.
+
+    TODO: efficiency: measure length can be cached, or stored as
+    property in paper-column.
+  */
+
+  if (Moment *measure_len = get_measure_length (lc))
     {
+      delta_t = min (delta_t, *measure_len);
+
       /*
-       when toying with mmrests, it is possible to have musical
-       column on the left and non-musical on the right, spanning
-       several measures.
+       The following is an extra safety measure, such that
+       the length of a mmrest event doesn't cause havoc.
       */
-
-      Moment *dt = unsmob_moment (rc->get_property ("measure-length"));
-      if (dt)
-       {
-         delta_t = min (delta_t, *dt);
-
-         /*
-           The following is an extra safety measure, such that
-           the length of a mmrest event doesn't cause havoc.
-         */
-         shortest_playing_len = min (shortest_playing_len, *dt);
-       }
+      shortest_playing_len = min (shortest_playing_len, *measure_len);
     }
 
   Real dist = 0.0;
@@ -139,8 +164,6 @@ Spacing_spanner::note_spacing (Grob *me, Grob *lc, Grob *rc,
        {
          Spacing_options grace_opts;
          grace_opts.init_from_grob (grace_spacing);
-
-
          bool bla;
          dist = grace_opts.get_duration_space (delta_t.grace_part_, &bla);
        }