]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/spacing-determine-loose-columns.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / spacing-determine-loose-columns.cc
index 610b96b32081074d8c78ef1db6afd682b42dc2e8..34f4c97214c50bab299e42aa6f13717abef1d32d 100644 (file)
@@ -4,21 +4,20 @@
 
   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 "staff-spacing.hh"
 
 #include "system.hh"
 #include "paper-column.hh"
 #include "column-x-positions.hh"
-#include "staff-spacing.hh"
 #include "pointer-group-interface.hh"
 #include "spacing-spanner.hh"
 #include "note-spacing.hh"
-
+#include "moment.hh"
 #include "break-align-interface.hh"
+#include "warn.hh"
 
 /*
   Return whether COL is fixed to its neighbors by some kind of spacing
   (Otherwise, we might risk core dumps, and other weird stuff.)
 */
 static bool
-is_loose_column (Grob *l, Grob *c, Grob *r)
+is_loose_column (Grob *l, Grob *c, Grob *r, Spacing_options const *options)
 {
+  if (options->float_nonmusical_columns_
+      && Paper_column::when_mom (c).grace_part_)
+    return true;
+
+  if (Paper_column::is_musical (c)
+      || Paper_column::is_breakable (c))
+    return false;
+
   extract_grob_set (c, "right-neighbors", rns);
   extract_grob_set (c, "left-neighbors", lns);
-  
+
   /*
     If this column doesn't have a proper neighbor, we should really
     make it loose, but spacing it correctly is more than we can
@@ -57,7 +64,7 @@ is_loose_column (Grob *l, Grob *c, Grob *r)
     such a borderline case.)
 
   */
-  if (lns.is_empty () || rns.is_empty ())
+  if (lns.empty () || rns.empty ())
     return false;
 
   Item *l_neighbor = dynamic_cast<Item *> (lns[0]);
@@ -80,11 +87,9 @@ is_loose_column (Grob *l, Grob *c, Grob *r)
     some cases (two isolated, consecutive clef changes) won't be
     nicely folded, but hey, then don't do that.
   */
-  if (! ((Paper_column::is_musical (l_neighbor) || Item::is_breakable (l_neighbor))
-        && (Paper_column::is_musical (r_neighbor) || Item::is_breakable (r_neighbor))))
-    {
-      return false;
-    }
+  if (! ((Paper_column::is_musical (l_neighbor) || Paper_column::is_breakable (l_neighbor))
+        && (Paper_column::is_musical (r_neighbor) || Paper_column::is_breakable (r_neighbor))))
+    return false;
 
   /*
     A rather hairy check, but we really only want to move around
@@ -93,13 +98,13 @@ is_loose_column (Grob *l, Grob *c, Grob *r)
     in any case, we don't want to move bar lines.
   */
   extract_grob_set (c, "elements", elts);
-  for (int i = elts.size (); i--; )
+  for (vsize i = elts.size (); i--;)
     {
       Grob *g = elts[i];
       if (g && Break_align_interface::has_interface (g))
        {
          extract_grob_set (g, "elements", gelts);
-         for (int j = gelts.size (); j--; )
+         for (vsize j = gelts.size (); j--;)
            {
              Grob *h = gelts[j];
 
@@ -121,29 +126,26 @@ is_loose_column (Grob *l, Grob *c, Grob *r)
   between.
 */
 void
-Spacing_spanner::prune_loose_columns (Grob *me, Link_array<Grob> *cols,
+Spacing_spanner::prune_loose_columns (Grob *me, vector<Grob*> *cols,
                                      Spacing_options const *options)
 {
-  Link_array<Grob> newcols;
-  Real increment = robust_scm2double (me->get_property ("spacing-increment"), 1.2);
-  for (int i = 0; i < cols->size (); i++)
+  vector<Grob*> newcols;
+
+  for (vsize i = 0; i < cols->size (); i++)
     {
-      if (Item::is_breakable (cols->elem (i))
-         || Paper_column::is_musical (cols->elem (i)))
-       {
-         newcols.push (cols->elem (i));
-         continue;
-       }
+      Grob *c = cols->at (i);
 
-      Grob *c = cols->elem (i);
-      if (is_loose_column (cols->elem (i - 1), c, cols->elem (i + 1)))
+      bool loose = (i > 0 && i < cols->size () - 1)
+       && is_loose_column (cols->at (i - 1), c, cols->at (i + 1), options);
+
+      if (loose)
        {
          extract_grob_set (c, "right-neighbors", rns_arr);
          extract_grob_set (c, "left-neighbors", lns_arr);
-         
-         SCM lns = lns_arr.size () ? lns_arr.top()->self_scm () : SCM_BOOL_F;
-         SCM rns = rns_arr.size () ? rns_arr.top()->self_scm () : SCM_BOOL_F;
-         
+
+         SCM lns = lns_arr.size () ? lns_arr.back ()->self_scm () : SCM_BOOL_F;
+         SCM rns = rns_arr.size () ? rns_arr.back ()->self_scm () : SCM_BOOL_F;
+
          /*
            Either object can be non existent, if the score ends
            prematurely.
@@ -157,8 +159,8 @@ Spacing_spanner::prune_loose_columns (Grob *me, Link_array<Grob> *cols,
            Set distance constraints for loose columns
          */
          Drul_array<Grob *> next_door;
-         next_door[LEFT] = cols->elem (i - 1);
-         next_door[RIGHT] = cols->elem (i + 1);
+         next_door[LEFT] = cols->at (i - 1);
+         next_door[RIGHT] = cols->at (i + 1);
          Direction d = LEFT;
          Drul_array<Real> dists (0, 0);
 
@@ -168,9 +170,8 @@ Spacing_spanner::prune_loose_columns (Grob *me, Link_array<Grob> *cols,
              Item *lc = dynamic_cast<Item *> ((d == LEFT) ? next_door[LEFT] : c);
              Item *rc = dynamic_cast<Item *> (d == LEFT ? c : next_door[RIGHT]);
 
-
              extract_grob_set (lc, "spacing-wishes", wishes);
-             for (int k = wishes.size(); k--;)
+             for (vsize k = wishes.size (); k--;)
                {
                  Grob *sp = wishes[k];
                  if (Note_spacing::left_column (sp) != lc
@@ -181,7 +182,7 @@ Spacing_spanner::prune_loose_columns (Grob *me, Link_array<Grob> *cols,
                  fixed = 0.0;
                  bool dummy;
 
-                 if (d == LEFT)
+                 if (Note_spacing::has_interface (sp))
                    {
                      /*
                        The note spacing should be taken from the musical
@@ -189,13 +190,13 @@ Spacing_spanner::prune_loose_columns (Grob *me, Link_array<Grob> *cols,
 
                      */
                      Real base = note_spacing (me, lc, rc, options, &dummy);
-                     Note_spacing::get_spacing (sp, rc, base, increment, &space, &fixed);
+                     Note_spacing::get_spacing (sp, rc, base, options->increment_, &space, &fixed);
 
-                     space -= increment;
+                     space -= options->increment_;
 
                      dists[d] = max (dists[d], space);
                    }
-                 else
+                 else if (Staff_spacing::has_interface (sp))
                    {
                      Real space, fixed_space;
                      Staff_spacing::get_spacing_params (sp,
@@ -203,21 +204,21 @@ Spacing_spanner::prune_loose_columns (Grob *me, Link_array<Grob> *cols,
 
                      dists[d] = max (dists[d], fixed_space);
                    }
+                 else
+                   programming_error ("Subversive spacing wish");
                }
            }
          while (flip (&d) != LEFT);
 
          Rod r;
          r.distance_ = dists[LEFT] + dists[RIGHT];
-         r.item_drul_[LEFT] = dynamic_cast<Item *> (cols->elem (i - 1));
-         r.item_drul_[RIGHT] = dynamic_cast<Item *> (cols->elem (i + 1));
+         r.item_drul_[LEFT] = dynamic_cast<Item *> (cols->at (i - 1));
+         r.item_drul_[RIGHT] = dynamic_cast<Item *> (cols->at (i + 1));
 
          r.add_to_cols ();
        }
       else
-       {
-         newcols.push (c);
-       }
+       newcols.push_back (c);
     }
 
   *cols = newcols;
@@ -227,18 +228,18 @@ Spacing_spanner::prune_loose_columns (Grob *me, Link_array<Grob> *cols,
   Set neighboring columns determined by the spacing-wishes grob property.
 */
 void
-Spacing_spanner::set_explicit_neighbor_columns (Link_array<Grob> const &cols)
+Spacing_spanner::set_explicit_neighbor_columns (vector<Grob*> const &cols)
 {
-  for (int i = 0; i < cols.size (); i++)
+  for (vsize i = 0; i < cols.size (); i++)
     {
       SCM right_neighbors = Grob_array::make_array ();
       Grob_array *rn_arr = unsmob_grob_array (right_neighbors);
       int min_rank = 100000;   // inf.
 
       extract_grob_set (cols[i], "spacing-wishes", wishes);
-      for (int k = wishes.size(); k--;)
+      for (vsize k = wishes.size (); k--;)
        {
-         Item *wish = dynamic_cast<Item *> ( wishes[k]);
+         Item *wish = dynamic_cast<Item *> (wishes[k]);
 
          Item *lc = wish->get_column ();
          Grob *right = Note_spacing::right_column (wish);
@@ -271,13 +272,13 @@ Spacing_spanner::set_explicit_neighbor_columns (Link_array<Grob> const &cols)
          extract_grob_set (rc, "left-neighbors", lns_arr);
          if (lns_arr.size ())
            {
-             Item *it = dynamic_cast<Item *> (lns_arr.top());
+             Item *it = dynamic_cast<Item *> (lns_arr.back ());
              maxrank = Paper_column::get_rank (it->get_column ());
            }
 
          if (left_rank >= maxrank)
            {
-             
+
              if (left_rank > maxrank)
                {
                  Grob_array *ga = unsmob_grob_array (rc->get_object ("left-neighbors"));
@@ -290,9 +291,7 @@ Spacing_spanner::set_explicit_neighbor_columns (Link_array<Grob> const &cols)
        }
 
       if (rn_arr->size ())
-       {
-         cols[i]->set_object ("right-neighbors", right_neighbors);
-       }
+       cols[i]->set_object ("right-neighbors", right_neighbors);
     }
 }
 
@@ -301,12 +300,12 @@ Spacing_spanner::set_explicit_neighbor_columns (Link_array<Grob> const &cols)
   yet. Only do breakable non-musical columns, and musical columns.
 */
 void
-Spacing_spanner::set_implicit_neighbor_columns (Link_array<Grob> const &cols)
+Spacing_spanner::set_implicit_neighbor_columns (vector<Grob*> const &cols)
 {
-  for (int i = 0; i < cols.size (); i++)
+  for (vsize i = 0; i < cols.size (); i++)
     {
       Item *it = dynamic_cast<Item *> (cols[i]);
-      if (!Item::is_breakable (it) && !Paper_column::is_musical (it))
+      if (!Paper_column::is_breakable (it) && !Paper_column::is_musical (it))
        continue;
 
       // it->breakable || it->musical
@@ -315,19 +314,19 @@ Spacing_spanner::set_implicit_neighbor_columns (Link_array<Grob> const &cols)
        sloppy with typing left/right-neighbors should take list, but paper-column found instead.
       */
       extract_grob_set (cols[i], "left-neighbors", lns);
-      if (lns.is_empty () && i )
+      if (lns.empty () && i)
        {
-         SCM ga_scm = Grob_array::make_array();
+         SCM ga_scm = Grob_array::make_array ();
          Grob_array *ga = unsmob_grob_array (ga_scm);
-         ga->add (cols[i-1]);
+         ga->add (cols[i - 1]);
          cols[i]->set_object ("left-neighbors", ga_scm);
        }
       extract_grob_set (cols[i], "right-neighbors", rns);
-      if (rns.is_empty () && i < cols.size () - 1)
+      if (rns.empty () && i < cols.size () - 1)
        {
-         SCM ga_scm = Grob_array::make_array();
+         SCM ga_scm = Grob_array::make_array ();
          Grob_array *ga = unsmob_grob_array (ga_scm);
-         ga->add (cols[i+1]);
+         ga->add (cols[i + 1]);
          cols[i]->set_object ("right-neighbors", ga_scm);
        }
     }