lilypond-0.0.2
[lilypond.git] / break.cc
blob8f76d13fdca6e3cc7a5a144f556ab36bacf730b5
1 /*
2 do calculations for breaking problem
4 */
6 #include "linespace.hh"
7 #include "debug.hh"
8 #include "line.hh"
9 #include "pscore.hh"
11 // construct an appropriate Spacing_problem and solve it.
12 svec<Real>
13 PScore::solve_line(svec<const PCol *> curline) const
15 Spacing_problem sp;
16 // mtor << "line of " << curline.sz() << " cols\n";
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, linewidth);
22 // misschien moeven uit Spacing_problem?
23 for (PCursor<Idealspacing *> i(suz); i.ok(); i++) {
24 sp.add_ideal(i);
26 svec<Real> the_sol=sp.solve();
27 return the_sol;
31 void
32 PScore::problem_OK()
34 if (!cols.size())
35 error("PScore::problem_OK(): Score does not have any columns");
36 PCursor<PCol *> start(cols);
37 PCursor<PCol *> end (cols.bottom());
39 assert(start->breakable);
40 assert(end->breakable);
43 struct Col_configuration {
44 svec<const PCol*> line;
45 svec<Real> config;
46 Real energy;
48 Col_configuration() {
49 energy = INFTY;
51 void add(const PCol*c) { line.add(c);}
52 void setsol(svec<Real> sol) {
53 config = sol;
54 energy = config.last();
55 config.pop();
59 /// wordwrap type algorithm
60 /* el stupido. This should be optimised...
63 void
64 PScore::calc_breaking()
66 problem_OK();
67 PCursor<PCol *> curcol(cols);
69 svec<const PCol *> breakpoints(find_breaks());
70 assert(breakpoints.sz()>=2);
71 for (int i=0 ; i < breakpoints.sz() -1; ) {
72 Col_configuration minimum;
73 Col_configuration current;
75 // do another line
76 current.add(breakpoints[i]->postbreak );
77 curcol++; // skip the breakable.
78 i++;
80 while (i < breakpoints.sz()) {
82 // add another measure.
83 while(breakpoints[i] !=curcol){
85 current.add(curcol);
86 curcol++;
88 current.add(breakpoints[i]->prebreak );
89 current.setsol(solve_line(current.line));
92 if (current.energy < minimum.energy) {
93 minimum = current;
94 } else {
95 break;
98 current.line.last()=breakpoints[i];
99 curcol ++;
100 i++;
103 add_line(minimum.line, minimum.config);