]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/spring-spacer.hh
55864615a24dbc49d801b91a5eec6d6d4509b680
[lilypond.git] / lily / include / spring-spacer.hh
1 /*
2   spring-spacer.hh -- declare Spring_spacer
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #ifndef SPRING_SPACER_HH
11 #define SPRING_SPACER_HH
12
13 #include "line-spacer.hh"
14 #include "plist.hh"
15 #include "col-info.hh"
16
17 /** the problem, given by the columns (which include constraints) and
18     intercolumn spacing. The problem is:
19
20     Generate a spacing which
21     \begin{itemize}
22     \item
23     Satisfies spacing constraints (notes can't be printed through each other)
24     \item
25     Looks good, ie tries to conform to  an ideal spacing as much as possible.
26     \end{itemize}
27     This is converted by regarding idealspacing as "springs" attached
28     to columns. The equilibrium of one spring is the ideal
29     distance. The columns have a size, this imposes "hard" constraints
30     on the distances. This transforms the problem into a quadratic
31     programming problem with linear constraints.
32
33     The quality is given by the total potential energy in the
34     springs. The lower the energy, the better the configuration.
35
36     TODO: make item widths work per pstaff.
37
38 */
39
40 class Spring_spacer : public Line_spacer {
41     friend class Durations_iter;
42     
43     Pointer_list<Idealspacing *> ideal_p_list_;
44     Array<Colinfo> cols;
45     Array<Colinfo> loose_col_arr_;
46     
47     /// mark column #i# as being loose.
48     void loosen_column(int i);
49     /// the index of #c# in #cols#
50     int col_id(PCol const *c) const;
51
52     /// generate an (nonoptimal) solution
53     Vector find_initial_solution() const;
54
55     /// check if problem is too tight
56     bool check_feasible() const;
57
58     /// does #this# contain the column #w#? 
59     bool contains(PCol const *w);
60
61     /// make the energy function
62     void make_matrices(Matrix &quad, Vector &lin,Real&) const;
63
64     /// generate the LP constraints
65     void make_constraints(Mixed_qp& lp) const;
66
67
68     void handle_loose_cols();
69     void position_loose_cols(Vector &) const;
70    /**
71        add a idealspacing to the problem.
72       
73     One pair of columns can have no, one or more idealspacings,
74     since they can be "summed" if the columns to which #i# refers are
75     not in this problem, the spacing is ignored.
76     */
77     void add_ideal(Idealspacing const *i);
78     Vector try_initial_solution() const;
79     void calc_idealspacing();
80
81     Score_column* scol_l(int);
82     void connect(int i,int j, Real,Real);
83 public:
84     static Line_spacer *constructor();
85     Array<PCol*> error_pcol_l_arr() const;
86
87     virtual   Array<Real> solve() const;
88     virtual  void add_column(PCol  *, bool fixed=false, Real fixpos=0.0);
89  
90
91     virtual Vector default_solution() const;
92     virtual   bool check_constraints(Vector v) const;
93     virtual    void OK() const;
94     virtual    void print() const;
95     virtual    void prepare();
96     virtual ~Spring_spacer(){}
97 };
98
99 #endif // SPRING_SPACER_HH