From: fred Date: Tue, 8 Oct 1996 09:05:27 +0000 (+0000) Subject: lilypond-0.0.1 X-Git-Tag: release/1.5.59~7146 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=374b12604857b52186bda33221550594124c4ac2;p=lilypond.git lilypond-0.0.1 --- diff --git a/break.cc b/break.cc new file mode 100644 index 0000000000..8f76d13fdc --- /dev/null +++ b/break.cc @@ -0,0 +1,106 @@ +/* + do calculations for breaking problem + + */ + +#include "linespace.hh" +#include "debug.hh" +#include "line.hh" +#include "pscore.hh" + +// construct an appropriate Spacing_problem and solve it. +svec +PScore::solve_line(svec curline) const +{ + Spacing_problem sp; + // mtor << "line of " << curline.sz() << " cols\n"; + sp.add_column(curline[0], true, 0.0); + for (int i=1; i< curline.sz()-1; i++) + sp.add_column(curline[i]); + sp.add_column(curline.last(), true, linewidth); + + // misschien moeven uit Spacing_problem? + for (PCursor i(suz); i.ok(); i++) { + sp.add_ideal(i); + } + svec the_sol=sp.solve(); + return the_sol; +} + + +void +PScore::problem_OK() +{ + if (!cols.size()) + error("PScore::problem_OK(): Score does not have any columns"); + PCursor start(cols); + PCursor end (cols.bottom()); + + assert(start->breakable); + assert(end->breakable); +} + +struct Col_configuration { + svec line; + svec config; + Real energy; + + Col_configuration() { + energy = INFTY; + } + void add(const PCol*c) { line.add(c);} + void setsol(svec sol) { + config = sol; + energy = config.last(); + config.pop(); + } +}; + +/// wordwrap type algorithm +/* el stupido. This should be optimised... + */ + +void +PScore::calc_breaking() +{ + problem_OK(); + PCursor curcol(cols); + + svec breakpoints(find_breaks()); + assert(breakpoints.sz()>=2); + for (int i=0 ; i < breakpoints.sz() -1; ) { + Col_configuration minimum; + Col_configuration current; + + // do another line + current.add(breakpoints[i]->postbreak ); + curcol++; // skip the breakable. + i++; + + while (i < breakpoints.sz()) { + + // add another measure. + while(breakpoints[i] !=curcol){ + + current.add(curcol); + curcol++; + } + current.add(breakpoints[i]->prebreak ); + current.setsol(solve_line(current.line)); + + + if (current.energy < minimum.energy) { + minimum = current; + } else { + break; + } + + current.line.last()=breakpoints[i]; + curcol ++; + i++; + } + + add_line(minimum.line, minimum.config); + } +} +