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 Joe Neeman <joeneeman@gmail.com>
10 #ifndef CONSTRAINED_BREAKING_HH
11 #define CONSTRAINED_BREAKING_HH
13 #include "break-algorithm.hh"
14 #include "lily-guile.hh"
20 Interval extent_; /* Y-extent of the system */
21 Real padding_; /* compulsory space after this system (if we're not last on a page) */
23 Real space_; /* spring length */
26 SCM break_permission_;
40 break_permission_ = ly_symbol2scm ("allow");
41 page_permission_ = ly_symbol2scm ("allow");
42 turn_permission_ = ly_symbol2scm ("allow");
48 Line_details (Prob *pb)
51 extent_ = unsmob_stencil (pb->get_property ("stencil")) ->extent (Y_AXIS);
55 break_permission_ = ly_symbol2scm ("allow");
56 page_permission_ = pb->get_property ("page-break-permission");
57 turn_permission_ = pb->get_property ("page-turn-permission");
59 page_penalty_ = robust_scm2double (pb->get_property ("page-break-penalty"), 0);
60 turn_penalty_ = robust_scm2double (pb->get_property ("page-turn-penalty"), 0);
65 Helper to trace back an optimal path
67 struct Constrained_break_node
69 /* the number of bars in all the systems before this one
73 /* unlike the Gourlay breaker, this is the sum of all demerits up to,
74 * and including, this line */
76 struct Line_details details_;
78 Constrained_break_node ()
81 demerits_ = infinity_f;
86 printf ("prev break %d, demerits %f\n", prev_, demerits_);
91 A dynamic programming solution to breaking scores into lines
93 class Constrained_breaking : public Break_algorithm
96 vector<Column_x_positions> solve ();
97 Constrained_breaking ();
98 Constrained_breaking (vector<vsize> const &start_col_posns);
100 vector<Column_x_positions> get_solution (vsize start, vsize end, vsize sys_count);
101 vector<Column_x_positions> get_best_solution (vsize start, vsize end);
102 vector<Line_details> get_details (vsize start, vsize end, vsize sys_count);
103 int get_max_systems (vsize start, vsize end);
104 int get_min_systems (vsize start, vsize end);
106 void resize (vsize systems);
109 vsize valid_systems_;
112 /* the (i,j)th entry is the configuration for breaking between
114 Matrix<Line_details> lines_;
116 /* the [i](j,k)th entry is the score for fitting the first k bars onto the
117 first j systems, starting at the i'th allowed starting column */
118 vector<Matrix<Constrained_break_node> > state_;
120 vector<vsize> start_; /* the columns at which we might be asked to start breaking */
121 vector<vsize> starting_breakpoints_; /* the corresponding index in breaks_ */
124 vector<vsize> breaks_;
126 Column_x_positions space_line (vsize start_col, vsize end_col);
127 vsize prepare_solution (vsize start, vsize end, vsize sys_count);
129 Real combine_demerits (Real force, Real prev_force);
131 bool calc_subproblem(vsize start, vsize systems, vsize max_break_index);
133 #endif /* CONSTRAINED_BREAKING_HH */