]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/gourlay-breaking.cc
* lily/simple-spacer.cc: Remove class Simple_spacer_wrapper.
[lilypond.git] / lily / gourlay-breaking.cc
index 9f0f2252134c0ecb6b9d507c6e8c5e6dc0b75a36..06233738e8889cfecf4933c05bfa1d6d283bf745 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "gourlay-breaking.hh"
 #include <cstdio>
 using namespace std;
 
-#include "warn.hh"
+#include "international.hh"
 #include "main.hh"
+#include "output-def.hh"
 #include "paper-column.hh"
 #include "paper-score.hh"
-#include "output-def.hh"
 #include "simple-spacer.hh"
 #include "system.hh"
+#include "warn.hh"
 
 /// How often to print operator pacification marks?
-const int HAPPY_DOTS_I = 3;
+const int HAPPY_DOTS = 3;
 
 /**
    Helper to trace back an optimal path
@@ -56,9 +57,9 @@ struct Break_node
 };
 
 void
-print_break_nodes (Array<Break_node> const &arr)
+print_break_nodes (vector<Break_node> const &arr)
 {
-  for (int i = 0; i < arr.size (); i++)
+  for (vsize i = 0; i < arr.size (); i++)
     {
       printf ("node %d: ", i);
       arr[i].print ();
@@ -73,23 +74,23 @@ print_break_nodes (Array<Break_node> const &arr)
    TODO: should rewrite. See the function in scm/page-layout.scm for
    inspiration.
 */
-Array<Column_x_positions>
-Gourlay_breaking::do_solve () const
+vector<Column_x_positions>
+Gourlay_breaking::solve () 
 {
-  Array<Break_node> optimal_paths;
-  Link_array<Grob> all
+  vector<Break_node> optimal_paths;
+  vector<Grob*> all
     = pscore_->root_system ()->columns ();
 
-  Array<int> breaks = find_break_indices ();
+  vector<vsize> breaks = pscore_->find_break_indices ();
 
   Break_node first_node;
-  optimal_paths.push (first_node);
+  optimal_paths.push_back (first_node);
 
-  bool ragged_right = to_boolean (pscore_->layout ()->c_variable ("raggedright"));
-  bool ragged_last = to_boolean (pscore_->layout ()->c_variable ("raggedlast"));
+  bool ragged_right = to_boolean (pscore_->layout ()->c_variable ("ragged-right"));
+  bool ragged_last = to_boolean (pscore_->layout ()->c_variable ("ragged-last"));
 
   Real worst_force = 0.0;
-  for (int break_idx = 1; break_idx < breaks.size (); break_idx++)
+  for (vsize break_idx = 1; break_idx < breaks.size (); break_idx++)
     {
       /*
        start with a short line, add measures. At some point
@@ -101,27 +102,18 @@ Gourlay_breaking::do_solve () const
 
       Real minimal_demerits = infinity_f;
 
-      for (int start_idx = break_idx; start_idx--;)
+      for (vsize start_idx = break_idx; start_idx--;)
        {
-         Link_array<Grob> line = all.slice (breaks[start_idx], breaks[break_idx] + 1);
-
-         line[0] = dynamic_cast<Item *> (line[0])->find_prebroken_piece (RIGHT);
-         line.top () = dynamic_cast<Item *> (line.top ())->find_prebroken_piece (LEFT);
-
-         Column_x_positions cp;
-         cp.cols_ = line;
+         vector<Grob*> line (all.begin () + breaks[start_idx],
+                             all.begin () + breaks[break_idx] + 1);
 
          Interval line_dims
            = line_dimensions_int (pscore_->layout (), optimal_paths[start_idx].line_);
-         Simple_spacer_wrapper *sp = generate_spacing_problem (line, line_dims);
          bool last_line = break_idx == breaks.size () - 1;
-         bool ragged = ragged_right
-           || (last_line && ragged_last);
-
-         sp->solve (&cp, ragged);
-
-         delete sp;
+         bool ragged = ragged_right || (last_line && ragged_last);
 
+         Column_x_positions cp = get_line_configuration (line, line_dims[RIGHT] - line_dims[LEFT],
+                                                         line_dims[LEFT], ragged);
          if (ragged && last_line)
            cp.force_ = 0.0;
 
@@ -171,26 +163,26 @@ Gourlay_breaking::do_solve () const
          bnod.line_config_ = minimal_sol;
        }
       bnod.line_ = optimal_paths[bnod.prev_break_].line_ + 1;
-      optimal_paths.push (bnod);
+      optimal_paths.push_back (bnod);
 
-      if (! (break_idx % HAPPY_DOTS_I))
-       progress_indication (String ("[") + to_string (break_idx) + "]");
+      if (! (break_idx % HAPPY_DOTS))
+       progress_indication (string ("[") + to_string (break_idx) + "]");
     }
 
   /* do the last one */
-  if (breaks.size () % HAPPY_DOTS_I)
-    progress_indication (String ("[") + to_string (breaks.size ()) + "]");
+  if (breaks.size () % HAPPY_DOTS)
+    progress_indication (string ("[") + to_string (breaks.size ()) + "]");
 
   progress_indication ("\n");
 
-  Array<int> final_breaks;
-  Array<Column_x_positions> lines;
+  vector<int> final_breaks;
+  vector<Column_x_positions> lines;
 
   /* skip 0-th element, since it is a "dummy" elt*/
-  for (int i = optimal_paths.size () - 1; i > 0;)
+  for (vsize i = optimal_paths.size () - 1; i > 0;)
     {
-      final_breaks.push (i);
-      int prev = optimal_paths[i].prev_break_;
+      final_breaks.push_back (i);
+      vsize prev = optimal_paths[i].prev_break_;
       assert (i > prev);
       i = prev;
     }
@@ -198,17 +190,17 @@ Gourlay_breaking::do_solve () const
   if (be_verbose_global)
     {
       message (_f ("Optimal demerits: %f",
-                  optimal_paths.top ().demerits_) + "\n");
+                  optimal_paths.back ().demerits_) + "\n");
     }
 
-  if (optimal_paths.top ().demerits_ >= infinity_f)
+  if (optimal_paths.back ().demerits_ >= infinity_f)
     warning (_ ("no feasible line breaking found"));
 
-  for (int i = final_breaks.size (); i--;)
+  for (vsize i = final_breaks.size (); i--;)
     {
       Column_x_positions cp (optimal_paths[final_breaks[i]].line_config_);
 
-      lines.push (cp);
+      lines.push_back (cp);
       if (!cp.satisfies_constraints_)
        warning (_ ("can't find line breaking that satisfies constraints"));
     }
@@ -231,7 +223,7 @@ Gourlay_breaking::combine_demerits (Column_x_positions const &prev,
                                    Column_x_positions const &this_one) const
 {
   Real break_penalties = 0.0;
-  Grob *pc = this_one.cols_.top ();
+  Grob *pc = this_one.cols_.back ();
   if (pc->original ())
     {
       SCM pen = pc->get_property ("penalty");