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"
19 Col_stats::str() const {
23 s += String(Real(cols_i_)/count_i_, ", (with an average of %.1f columns)");
29 Col_stats::add(Line_of_cols const& line)
32 cols_i_ += line.size();
36 Col_stats::Col_stats()
42 /* **************************************************************** */
45 Break_algorithm::all_cols()const
48 for (PCursor<PCol*> c(pscore_l_->col_p_list_.top());
57 Break_algorithm::find_break_indices() const
59 Line_of_cols all(all_cols());
62 for (int i=0; i < all.size(); i++)
63 if (all[i]->breakable_b())
67 while ( retval.size() >2)
73 /// return all breakable columns
75 Break_algorithm::find_breaks() const
77 Line_of_cols all(all_cols());
80 for (int i=0; i < all.size(); i++)
81 if (all[i]->breakable_b())
86 while ( retval.size() >2)
97 Break_algorithm::generate_spacing_problem(Line_of_cols curline)const
99 Line_spacer * sp= (*get_line_spacer)();
101 sp->paper_l_ = pscore_l_->paper_l_;
102 sp->add_column(curline[0], true, 0.0);
103 for (int i=1; i< curline.size()-1; i++)
104 sp->add_column(curline[i]);
107 sp->add_column(curline.top(), true, linelength);
109 sp->add_column(curline.top());
115 Break_algorithm::Break_algorithm()
123 Break_algorithm::set_pscore(PScore*s)
126 linelength = s->paper_l_->linewidth_f();
131 Break_algorithm::feasible(Line_of_cols curline) const
137 for (int i=0; i < curline.size(); i++)
138 l +=curline[i]->width().length();
139 return l < linelength;
143 Break_algorithm::problem_OK() const
145 if (!pscore_l_->col_p_list_.size())
146 error("Score does not have any columns");
151 Break_algorithm::OK()const
154 iter_top(pscore_l_->col_p_list_,start);
155 PCursor<PCol *> end (pscore_l_->col_p_list_.bottom());
157 assert(start->breakable_b());
158 assert(end->breakable_b());
162 Array<Col_hpositions>
163 Break_algorithm::solve()const
169 Break_algorithm::do_set_pscore()
175 Break_algorithm::print_stats()const
177 if (approx_stats_.count_i_)
178 *mlog << "\nApproximated: " << approx_stats_.str() << "\n";
179 if (exact_stats_.count_i_)
180 *mlog << "Calculated exactly: " << exact_stats_.str() << "\n";