]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/gourlay-breaking.cc
release: 1.2.8
[lilypond.git] / lily / gourlay-breaking.cc
index 58e08b959c4f473e40840ec97d5bb2e26feb24f7..e9d0ecb801aa80167c4b4c8762dfb890e31ffcc2 100644 (file)
@@ -3,18 +3,21 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "gourlay-breaking.hh"
-#include "colhpos.hh"
+#include "column-x-positions.hh"
 #include "spring-spacer.hh"
 #include "debug.hh"
-#include "p-col.hh"
-#include "p-score.hh"
+#include "paper-column.hh"
+#include "paper-score.hh"
 #include "paper-def.hh"
 
-const HAPPY_DOTS_I = 3;
+#include "killing-cons.tcc"
+
+/// How often to print operator pacification marks?
+const int HAPPY_DOTS_I = 3;
 
 /**
   Helper to trace back an optimal path 
@@ -25,9 +28,14 @@ struct Break_node {
     
     */
   int prev_break_i_;
+  /**
+     Which system number so far?
+   */
   int line_i_;
+
   Real energy_f_;
-  Col_hpositions line_config_;
+  Column_x_positions line_config_;
+  
   Break_node () 
   {
     prev_break_i_ = -1;
@@ -36,14 +44,13 @@ struct Break_node {
 };
 
 /**
-  This algorithms is adapted from 
+  This algorithms is adapted from the OSU Tech report on breaking lines.
  */
-
-Array<Col_hpositions>
+Array<Column_x_positions>
 Gourlay_breaking::do_solve () const
 {
   Array<Break_node> optimal_paths;
-  Line_of_cols all = all_cols ();
+  Line_of_cols all = pscore_l_->col_l_arr_ ;
   Array<int> breaks = find_break_indices ();
   
   optimal_paths.set_size (breaks.size ());
@@ -56,12 +63,11 @@ Gourlay_breaking::do_solve () const
   optimal_paths[0] = first_node; 
   int break_idx=1;
 
-  
   for (; break_idx< breaks.size (); break_idx++) 
     {
       Array<int> candidates;
-      Array<Col_hpositions> candidate_lines;
-      Pointer_list<Line_spacer*> spacer_p_list;
+      Array<Column_x_positions> candidate_lines;
+      Cons_list<Line_spacer> spacer_p_list;
        
       /*
        start with a short line, add measures. At some point 
@@ -74,25 +80,26 @@ Gourlay_breaking::do_solve () const
 
          if (optimal_paths[start_idx].prev_break_i_ < 0
              && optimal_paths[start_idx].line_config_.energy_f_)
-               
            continue;
-           
-         Line_of_cols line = all.slice (breaks[start_idx], breaks[break_idx]+1);
 
-         line[0] = line[0]->postbreak_l ();
-         line.top () = line.top ()->prebreak_l ();
+
+         
+         Line_of_cols line = all.slice (breaks[start_idx], breaks[break_idx]+1);
+  
+         line[0] = dynamic_cast<Paper_column*>(line[0]->find_prebroken_piece (RIGHT));
+         line.top () =  dynamic_cast<Paper_column*>(line.top ()->find_prebroken_piece (LEFT));
            
          if (!feasible (line))
            break;
            
-         Col_hpositions approx;
-         approx.cols = line;
+         Column_x_positions approx;
+         approx.cols_ = line;
            
          approx.spacer_l_ = generate_spacing_problem (line, 
            pscore_l_->paper_l_->line_dimensions_int (optimal_paths[start_idx].line_i_));
-         spacer_p_list.bottom ().add (approx.spacer_l_);
+         spacer_p_list.append (new Killing_cons<Line_spacer> (approx.spacer_l_,0));
 
-         ( (Break_algorithm*)this)->approx_stats_.add (approx.cols);
+         ( (Break_algorithm*)this)->approx_stats_.add (approx.cols_);
          approx.approximate_solve_line ();
            
          if  (approx.energy_f_  > energy_bound_f_)
@@ -120,7 +127,7 @@ Gourlay_breaking::do_solve () const
          if (!candidate_lines[j].satisfies_constraints_b_) 
            {
              candidate_lines[j].solve_line ();
-             ( (Break_algorithm*)this)->exact_stats_.add (candidate_lines[j].cols);
+             ( (Break_algorithm*)this)->exact_stats_.add (candidate_lines[j].cols_);
            }
            
          Real this_energy 
@@ -148,15 +155,17 @@ Gourlay_breaking::do_solve () const
        }
 
       if (! (break_idx % HAPPY_DOTS_I))
-       *mlog << "[" << break_idx << "]"<<flush;
+       *mlog << "[" << break_idx << "]" << flush;
+
+      spacer_p_list.junk ();
     }
 
   if  (break_idx % HAPPY_DOTS_I) 
-    *mlog << "[" << break_idx << "]"<<flush;
+    *mlog << "[" << break_idx << "]" << flush;
 
   Array<int> final_breaks;
 
-  Array<Col_hpositions> lines;
+  Array<Column_x_positions> lines;
 
   /* skip 0-th element, since it is a "dummy" elt*/
   for (int i = optimal_paths.size ()-1; i> 0;) 
@@ -165,7 +174,7 @@ Gourlay_breaking::do_solve () const
       assert (i > optimal_paths[i].prev_break_i_);
 
       // there was no "feasible path"
-      if (!optimal_paths[i].line_config_.config.size ()) {
+      if (!optimal_paths[i].line_config_.config_.size ()) {
        final_breaks.set_size (0);
        break;
       }
@@ -182,7 +191,6 @@ Gourlay_breaking::do_solve () const
 
 Gourlay_breaking::Gourlay_breaking ()
 {
-  get_line_spacer = Spring_spacer::constructor;
   energy_bound_f_ = infinity_f;
   max_measures_i_ = INT_MAX;
 }