]> git.donarmstrong.com Git - lilypond.git/blob - lily/break.cc
release: 0.0.54
[lilypond.git] / lily / break.cc
1 /*
2   break.cc -- implement Break_algorithm
3
4   source file of the LilyPond music typesetter
5
6   (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #include "break.hh"
11 #include "paper-def.hh"
12 #include "linespace.hh"
13 #include "debug.hh"
14 #include "scoreline.hh"
15 #include "p-score.hh"
16
17
18 ///  return all breakable columns
19 Line_of_cols
20 Break_algorithm::find_breaks() const
21 {
22     Line_of_cols retval;
23     for (iter_top(pscore_.cols,c); c.ok(); c++)
24         if (c->breakable_b())
25             retval.push(c);
26     assert(retval.top() == pscore_.cols.bottom().ptr());
27     return retval;
28 }
29
30 /// construct an appropriate Spacing_problem and solve it. 
31 Col_hpositions
32 Break_algorithm::solve_line(Line_of_cols curline) const
33 {
34    Spacing_problem sp;
35
36    sp.add_column(curline[0], true, 0.0);
37    for (int i=1; i< curline.size()-1; i++)
38        sp.add_column(curline[i]);
39    sp.add_column(curline.top(), true, linelength);
40
41    // misschien  moeven uit Spacing_problem? 
42    for (iter_top(pscore_.suz,i); i.ok(); i++) {
43        sp.add_ideal(i);
44    }
45    Array<Real> the_sol=sp.solve();
46    Col_hpositions col_hpos;
47    col_hpos.cols = curline;
48    col_hpos.energy = the_sol.pop();
49    col_hpos.config = the_sol;
50    col_hpos.OK();
51    return col_hpos;
52 }
53
54 Break_algorithm::Break_algorithm(PScore&s)
55     :pscore_(s)
56 {
57     linelength = s.paper_l_->linewidth;
58 }
59
60 bool
61 Break_algorithm::feasible(Line_of_cols curline) const
62 {
63     Real l =0;
64     for (int i=0; i < curline.size(); i++)
65         l +=curline[i]->width().length();
66     return l < linelength;    
67 }
68
69 void
70 Break_algorithm::problem_OK() const
71 {
72     if (!pscore_.cols.size())
73         error("Score does not have any columns");
74 #ifndef NDEBUG
75     iter_top(pscore_.cols,start);
76     PCursor<PCol *> end (pscore_.cols.bottom());
77     
78     assert(start->breakable_b());    
79     assert(end->breakable_b());
80 #endif
81 }