From: fred Date: Sun, 24 Mar 2002 19:48:30 +0000 (+0000) Subject: lilypond-0.0.76 X-Git-Tag: release/1.5.59~4430 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=910db915f290056e85d9b837e0670cce1b804627;p=lilypond.git lilypond-0.0.76 --- diff --git a/lily/break.cc b/lily/break.cc index 826346f4b3..fbda8d4279 100644 --- a/lily/break.cc +++ b/lily/break.cc @@ -9,7 +9,7 @@ #include "break.hh" #include "paper-def.hh" -#include "linespace.hh" +#include "line-spacer.hh" #include "debug.hh" #include "scoreline.hh" #include "p-score.hh" @@ -20,7 +20,7 @@ Line_of_cols Break_algorithm::find_breaks() const { Line_of_cols retval; - for (iter_top(pscore_.cols,c); c.ok(); c++) { + for (iter_top(pscore_l_->col_p_list_,c); c.ok(); c++) { if (c->breakable_b()) retval.push(c); } @@ -30,59 +30,59 @@ Break_algorithm::find_breaks() const return retval; } - -void -Break_algorithm::generate_spacing_problem(Line_of_cols curline, Spacing_problem & sp)const + +Line_spacer* +Break_algorithm::generate_spacing_problem(Line_of_cols curline)const { - sp.add_column(curline[0], true, 0.0); + Line_spacer * sp= (*get_line_spacer)(); + sp->paper_l_ = pscore_l_->paper_l_; + sp->add_column(curline[0], true, 0.0); for (int i=1; i< curline.size()-1; i++) - sp.add_column(curline[i]); + sp->add_column(curline[i]); if ( linelength > 0) - sp.add_column(curline.top(), true, linelength); + sp->add_column(curline.top(), true, linelength); else - sp.add_column(curline.top()); + sp->add_column(curline.top()); + return sp; } Col_hpositions Break_algorithm::stupid_solution(Line_of_cols curline)const { - Spacing_problem sp; - generate_spacing_problem(curline, sp); - Col_hpositions colhpos; - colhpos.cols = curline; - colhpos.energy = INFTY; - colhpos.ugh_b_ = true; - colhpos.config = sp.try_initial_solution(); - return colhpos; + Line_spacer *sp =generate_spacing_problem(curline); + Col_hpositions colhpos; + colhpos.cols = curline; + colhpos.energy = INFTY; + colhpos.ugh_b_ = true; + colhpos.config = sp->default_solution(); + delete sp; + return colhpos; } /// construct an appropriate Spacing_problem and solve it. Col_hpositions Break_algorithm::solve_line(Line_of_cols curline) const { - Spacing_problem sp; - generate_spacing_problem(curline, sp); - - // misschien moeven uit Spacing_problem? - for (iter_top(pscore_.suz,i); i.ok(); i++) { - sp.add_ideal(i); - } - sp.prepare(); + Line_spacer *sp = generate_spacing_problem(curline); + sp->prepare(); - Array the_sol=sp.solve(); - Col_hpositions col_hpos; - col_hpos.cols = curline; - col_hpos.energy = the_sol.pop(); - col_hpos.config = the_sol; - col_hpos.error_col_l_arr_ = sp.error_pcol_l_arr(); - col_hpos.OK(); - return col_hpos; + Array the_sol=sp->solve(); + Col_hpositions col_hpos; + col_hpos.cols = curline; + col_hpos.energy = the_sol.pop(); + col_hpos.config = the_sol; + col_hpos.error_col_l_arr_ = sp->error_pcol_l_arr(); + col_hpos.OK(); + delete sp; + + return col_hpos; } Break_algorithm::Break_algorithm(PScore&s) - :pscore_(s) { + pscore_l_ = &s; + get_line_spacer =0; linelength = s.paper_l_->linewidth_f(); } @@ -101,11 +101,17 @@ Break_algorithm::feasible(Line_of_cols curline) const void Break_algorithm::problem_OK() const { - if (!pscore_.cols.size()) + if (!pscore_l_->col_p_list_.size()) error("Score does not have any columns"); + OK(); +} + +void +Break_algorithm::OK()const +{ #ifndef NDEBUG - iter_top(pscore_.cols,start); - PCursor end (pscore_.cols.bottom()); + iter_top(pscore_l_->col_p_list_,start); + PCursor end (pscore_l_->col_p_list_.bottom()); assert(start->breakable_b()); assert(end->breakable_b()); @@ -115,7 +121,6 @@ Break_algorithm::problem_OK() const Array Break_algorithm::solve()const { - return do_solve(); } diff --git a/lily/include/break.hh b/lily/include/break.hh index 703f9bb816..bb37f4aeab 100644 --- a/lily/include/break.hh +++ b/lily/include/break.hh @@ -21,9 +21,9 @@ */ class Break_algorithm { - void generate_spacing_problem(Line_of_cols,Spacing_problem&)const; + Line_spacer* generate_spacing_problem(Line_of_cols)const; protected: - PScore &pscore_; + PScore *pscore_l_; Real linelength; /// search all pcols which are breakable. @@ -41,18 +41,15 @@ protected: Col_hpositions stupid_solution(Line_of_cols) const; virtual Array do_solve()const=0; public: + Line_spacer* (*get_line_spacer)(); + Break_algorithm(PScore&); /// check if the spacing/breaking problem is well-stated void problem_OK()const; - + void OK()const; Array solve()const; }; -/// wordwrap type algorithm: move to next line if current is optimal. -struct Word_wrap : Break_algorithm { - virtual Array do_solve()const; - Word_wrap(PScore&); -}; #endif // BREAK_HH