2 constrained-breaking.hh -- declare a line breaker that
3 supports limits on the number of systems
5 source file of the GNU LilyPond music typesetter
7 (c) 2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #ifndef CONSTRAINED_BREAKING_HH
11 #define CONSTRAINED_BREAKING_HH
13 #include "break-algorithm.hh"
14 #include "lily-guile.hh"
18 Real extent_; /* Y-extent of the system */
19 Real padding_; /* compulsory space after this system (if we're not last on a page) */
21 Real space_; /* spring length */
24 SCM break_permission_;
39 break_permission_ = ly_symbol2scm ("allow");
40 page_permission_ = ly_symbol2scm ("allow");
41 turn_permission_ = ly_symbol2scm ("allow");
49 Helper to trace back an optimal path
51 struct Constrained_break_node
53 /* the number of bars in all the systems before this one
57 /* unlike the Gourlay breaker, this is the sum of all demerits up to,
58 * and including, this line */
60 struct Line_details details_;
62 Constrained_break_node ()
65 demerits_ = infinity_f;
70 printf ("prev break %d, demerits %f\n", prev_, demerits_);
75 A dynamic programming solution to breaking scores into lines
77 class Constrained_breaking : public Break_algorithm
80 vector<Column_x_positions> solve ();
81 Constrained_breaking ();
82 Constrained_breaking (vector<vsize> const &start_col_posns);
84 vector<Column_x_positions> get_solution(vsize start, vsize end, vsize sys_count);
85 vector<Line_details> get_details (vsize start, vsize end, vsize sys_count);
86 int get_max_systems (vsize start, vsize end);
87 int get_min_systems (vsize start, vsize end);
89 void resize (vsize systems);
95 /* the (i,j)th entry is the configuration for breaking between
97 vector<Line_details> lines_;
100 /* the [i](j,k)th entry is the score for fitting the first k bars onto the
101 first j systems, starting at the i'th allowed starting column */
102 vector<vector<Constrained_break_node> > state_;
104 vector<vsize> start_; /* the columns at which we might be asked to start breaking */
105 vector<vsize> starting_breakpoints_; /* the corresponding index in breaks_ */
108 vector<vsize> breaks_;
110 Column_x_positions space_line (vsize start_col, vsize end_col);
111 void prepare_solution (vsize start, vsize end, vsize sys_count, vsize *rank, vsize *brk);
113 Real combine_demerits (Real force, Real prev_force);
115 bool calc_subproblem(vsize start, vsize systems, vsize max_break_index);
117 #endif /* CONSTRAINED_BREAKING_HH */