X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbreak.cc;h=fbda8d4279553612647bc2f734cfacf5ac71c254;hb=6ce61146edb1c36647b514778c29cdc9beedab6a;hp=7d219186372aa1ed179bea4fc310bc3e988c3c64;hpb=daee8243ff1c66bc714455a2d265ab02f03546ec;p=lilypond.git diff --git a/lily/break.cc b/lily/break.cc index 7d21918637..fbda8d4279 100644 --- a/lily/break.cc +++ b/lily/break.cc @@ -1,61 +1,97 @@ /* - do calculations for breaking problem - */ + break.cc -- implement Break_algorithm + + source file of the GNU LilyPond music typesetter + + (c) 1996, 1997 Han-Wen Nienhuys +*/ + + #include "break.hh" #include "paper-def.hh" -#include "linespace.hh" +#include "line-spacer.hh" #include "debug.hh" #include "scoreline.hh" -#include "pscore.hh" +#include "p-score.hh" +#include "p-col.hh" - -/* - return all breakable columns - */ +/// return all breakable columns 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); - assert(retval.top() == pscore_.cols.bottom().ptr()); + } + if ( linelength <=0) + while ( retval.size() >2) + retval.del(1); + return retval; } + +Line_spacer* +Break_algorithm::generate_spacing_problem(Line_of_cols curline)const +{ + 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]); + + if ( linelength > 0) + sp->add_column(curline.top(), true, linelength); + else + sp->add_column(curline.top()); + return sp; +} -// construct an appropriate Spacing_problem and solve it. Col_hpositions -Break_algorithm::solve_line(Line_of_cols curline) const +Break_algorithm::stupid_solution(Line_of_cols curline)const { - Spacing_problem sp; - - 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.top(), true, linelength); + 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; +} - // misschien moeven uit Spacing_problem? - for (iter_top(pscore_.suz,i); i.ok(); i++) { - sp.add_ideal(i); - } - 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.OK(); - return col_hpos; +/// construct an appropriate Spacing_problem and solve it. +Col_hpositions +Break_algorithm::solve_line(Line_of_cols curline) const +{ + 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(); + delete sp; + + return col_hpos; } Break_algorithm::Break_algorithm(PScore&s) - :pscore_(s) { - linelength = s.paper_l_->linewidth; + pscore_l_ = &s; + get_line_spacer =0; + linelength = s.paper_l_->linewidth_f(); } bool Break_algorithm::feasible(Line_of_cols curline) const { + if (linelength <= 0) + return true; + Real l =0; for (int i=0; i < curline.size(); i++) l +=curline[i]->width().length(); @@ -65,13 +101,26 @@ 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()); #endif } + +Array +Break_algorithm::solve()const +{ + return do_solve(); +} +