2 break.cc -- implement Break_algorithm
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
11 #include "paper-def.hh"
12 #include "line-spacer.hh"
14 #include "scoreline.hh"
17 #include "cpu-timer.hh"
20 Col_stats::str() const {
24 s
+= String (Real (cols_i_
)/count_i_
, _(", (with an average of %.1f columns)"));
30 Col_stats::add (Line_of_cols
const& line
)
33 cols_i_
+= line
.size();
37 Col_stats::Col_stats()
43 /* **************************************************************** */
46 Break_algorithm::all_cols() const
49 for (PCursor
<Paper_column
*> c (pscore_l_
->col_p_list_
.top());
59 Break_algorithm::find_break_indices() const
61 Line_of_cols
all (all_cols());
64 for (int i
=0; i
< all
.size(); i
++)
65 if (all
[i
]->breakable_b_
)
69 while (retval
.size() >2)
75 /// return all breakable columns
77 Break_algorithm::find_breaks() const
79 Line_of_cols
all (all_cols());
82 for (int i
=0; i
< all
.size(); i
++)
83 if (all
[i
]->breakable_b_
)
88 while (retval
.size() >2)
99 Break_algorithm::generate_spacing_problem (Line_of_cols curline
) const
101 Line_spacer
* sp
= (*get_line_spacer
)();
103 sp
->paper_l_
= pscore_l_
->paper_l_
;
104 sp
->add_column (curline
[0], true, 0.0);
105 for (int i
=1; i
< curline
.size()-1; i
++)
106 sp
->add_column (curline
[i
]);
109 sp
->add_column (curline
.top(), true, linelength
);
111 sp
->add_column (curline
.top());
117 Break_algorithm::Break_algorithm()
125 Break_algorithm::set_pscore (Paper_score
*s
)
128 linelength
= s
->paper_l_
->linewidth_f();
133 Break_algorithm::feasible (Line_of_cols curline
) const
139 for (int i
=0; i
< curline
.size(); i
++)
140 l
+=curline
[i
]->width().length ();
141 return l
< linelength
;
145 Break_algorithm::problem_OK() const
147 if (!pscore_l_
->col_p_list_
.size())
148 error (_("Score does not have any columns"));
153 Break_algorithm::OK() const
156 iter_top (pscore_l_
->col_p_list_
,start
);
157 PCursor
<Paper_column
*> end (pscore_l_
->col_p_list_
.bottom());
159 assert (start
->breakable_b_
);
160 assert (end
->breakable_b_
);
164 Array
<Col_hpositions
>
165 Break_algorithm::solve() const
169 Array
<Col_hpositions
> h
= do_solve();
171 if (approx_stats_
.count_i_
)
172 *mlog
<< _("\nApproximated: ") << approx_stats_
.str() << "\n";
173 if (exact_stats_
.count_i_
)
174 *mlog
<< _("Calculated exactly: ") << exact_stats_
.str() << "\n";
175 *mlog
<< _("Time: ") << String(timer
.read (), "%.2f") << _(" seconds\n");
181 Break_algorithm::do_set_pscore()