2 do calculations for breaking problem
6 #include "linespace.hh"
8 #include "scoreline.hh"
11 // construct an appropriate Spacing_problem and solve it.
13 PScore::solve_line(svec<const PCol *> curline) const
17 sp.add_column(curline[0], true, 0.0);
18 for (int i=1; i< curline.sz()-1; i++)
19 sp.add_column(curline[i]);
20 sp.add_column(curline.last(), true, paper_->linewidth);
22 // misschien moeven uit Spacing_problem?
23 for (PCursor<Idealspacing *> i(suz); i.ok(); i++) {
26 svec<Real> the_sol=sp.solve();
31 PScore::feasible(svec<const PCol *> curline) const
34 for (int i=0; i < curline.sz(); i++)
35 l +=curline[i]->width().length();
36 return l < paper_->linewidth;
40 PScore::problem_OK() const
43 error("PScore::problem_OK(): Score does not have any columns");
44 PCursor<PCol *> start(cols);
45 PCursor<PCol *> end (((PScore*)this)->cols.bottom());
47 assert(start->breakable());
48 assert(end->breakable());
51 struct Col_configuration {
52 svec<const PCol*> line;
59 void add(const PCol*c) { line.add(c);}
60 void setsol(svec<Real> sol) {
62 energy = config.last();
67 mtor << "energy : " << energy << '\n';
68 mtor << "line of " << config.sz() << " cols\n";
73 /// wordwrap type algorithm
74 /* el stupido. This should be done more accurately:
76 It would be nice to have a Dynamic Programming type of algorithm
82 PScore::calc_breaking()
86 PCursor<PCol *> curcol(cols);
88 svec<const PCol *> breakpoints(find_breaks());
89 assert(breakpoints.sz()>=2);
90 for (int i=0 ; i < breakpoints.sz() -1; ) {
91 Col_configuration minimum;
92 Col_configuration current;
95 PCol *post = breakpoints[i]->postbreak;
97 curcol++; // skip the breakable.
100 while (i < breakpoints.sz()) {
102 // add another measure.
103 while (breakpoints[i] != curcol.ptr()){
108 current.add(breakpoints[i]->prebreak );
109 if (!feasible(current.line)) {
110 if (!minimum.line.sz())
111 error("sorry, this measure is too long");
114 current.setsol(solve_line(current.line));
117 if (current.energy < minimum.energy) {
119 } else { // we're one col too far.
121 while (curcol.ptr() != breakpoints[i])
127 current.line.last()=breakpoints[i];
131 mtor << "Adding line, next breakpoint " << i << '\n';
132 add_line(minimum.line, minimum.config);