]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/constrained-breaking.hh
GCC 4 fix.
[lilypond.git] / lily / include / constrained-breaking.hh
1 /*
2   constrained-breaking.hh -- declare a line breaker that
3   supports limits on the number of systems
4
5   source file of the GNU LilyPond music typesetter
6
7   (c) 2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
9
10 #ifndef CONSTRAINED_BREAKING_HH
11 #define CONSTRAINED_BREAKING_HH
12
13 #include "break-algorithm.hh"
14
15 enum Fordfor {
16   FORBID = -1,
17   DEFAULT = 0,
18   FORCE = 1
19 };
20
21 struct Line_details {
22   Real force_;
23   Real extent_;   /* Y-extent of the system */
24   Real padding_;  /* compulsory space after this system (if we're not last on a page) */
25   Real space_;    /* spring length (stretches over extent_ but not over padding_) */
26   Real inverse_hooke_;
27
28   Fordfor line_break_;
29   Fordfor page_break_;
30   Fordfor page_turn_;
31   Real break_penalty_;
32   Real page_penalty_;
33   Real turn_penalty_;
34
35   Line_details ()
36   {
37     force_ = infinity_f;
38     extent_ = 0;
39     padding_ = 0;
40     space_ = 0;
41     inverse_hooke_ = 1;
42     line_break_ = DEFAULT;
43     page_break_ = DEFAULT;
44     page_turn_ = DEFAULT;
45     break_penalty_ = 0;
46     page_penalty_ = 0;
47     turn_penalty_ = 0;
48   }
49 };
50
51 /*
52    Helper to trace back an optimal path
53 */
54 struct Constrained_break_node
55 {
56   /* the number of bars in all the systems before this one
57   */
58   int prev_;
59
60   /* unlike the Gourlay breaker, this is the sum of all demerits up to,
61    * and including, this line */
62   Real demerits_;
63   struct Line_details details_;
64
65   Constrained_break_node ()
66   {
67     prev_ = -1;
68     demerits_ = infinity_f;
69   }
70
71   void print () const
72   {
73     printf ("prev break %d, demerits %f\n", prev_, demerits_);
74   }
75 };
76
77 /*
78    A dynamic programming solution to breaking scores into lines
79 */
80 class Constrained_breaking : public Break_algorithm
81 {
82 public:
83   vector<Column_x_positions> solve ();
84   Constrained_breaking ();
85   Constrained_breaking (vector<vsize> const &start_col_posns);
86
87   vector<Column_x_positions> get_solution(vsize start, vsize end, vsize sys_count);
88   vector<Line_details> get_details (vsize start, vsize end, vsize sys_count);
89   int get_max_systems (vsize start, vsize end);
90   int get_min_systems (vsize start, vsize end);
91
92   void resize (vsize systems);
93
94 private:
95   vsize valid_systems_;
96   vsize systems_;
97
98   /* the (i,j)th entry is the configuration for breaking between
99     columns i and j */
100   vector<Line_details> lines_;
101   vsize lines_rank_;
102
103   /* the [i](j,k)th entry is the score for fitting the first k bars onto the
104     first j systems, starting at the i'th allowed starting column */
105   vector<vector<Constrained_break_node> > state_;
106
107   vector<vsize> start_;         /* the columns at which we might be asked to start breaking */
108   vector<vsize> starting_breakpoints_; /* the corresponding index in breaks_ */
109
110   vector<Grob*> all_;
111   vector<vsize> breaks_;
112
113   Column_x_positions space_line (vsize start_col, vsize end_col);
114   void prepare_solution (vsize start, vsize end, vsize sys_count, vsize *rank, vsize *brk);
115
116   Real combine_demerits (Real force, Real prev_force);
117
118   bool calc_subproblem(vsize start, vsize systems, vsize max_break_index);
119 };
120 #endif /* CONSTRAINED_BREAKING_HH */