lilypond-1.1.44
[lilypond.git] / lily / include / linespace.hh
blob8b230ff5161035ef9c9c1518678e5380f814b0ea
1 /*
2 linespace.hh -- declare Spacing_problem
4 source file of the GNU LilyPond music typesetter
6 (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #error
11 #ifndef LINESPACE_HH
12 #define LINESPACE_HH
14 #include "plist.hh"
15 #include "array.hh"
16 #include "vector.hh"
17 #include "interval.hh"
18 #include "pointer.hh"
21 /** the problem, given by the columns (which include constraints) and
22 intercolumn spacing. The problem is:
24 Generate a spacing which
25 \begin{itemize}
26 \item
27 Satisfies spacing constraints (notes can't be printed through each other)
28 \item
29 Looks good, ie tries to conform to an ideal spacing as much as possible.
30 \end{itemize}
31 This is converted by regarding idealspacing as "springs" attached
32 to columns. The equilibrium of one spring is the ideal
33 distance. The columns have a size, this imposes "hard" constraints
34 on the distances. This transforms the problem into a quadratic
35 programming problem with linear constraints.
37 The quality is given by the total potential energy in the
38 springs. The lower the energy, the better the configuration.
40 TODO: make item widths work per pstaff.
43 class Spacing_problem {
44 PointerList<Idealspacing *> ideal_p_list_;
45 Array<Column_info> cols;
46 Array<Column_info> loose_col_arr_;
48 /// mark column #i# as being loose.
49 void loosen_column (int i);
50 /// the index of #c# in #cols#
51 int col_id (Paper_column const *c) const;
53 /// generate an (nonoptimal) solution
54 Vector find_initial_solution() const;
56 /// check if problem is too tight
57 bool check_feasible() const;
59 /// does #this# contain the column #w#?
60 bool contains (Paper_column const *w);
62 /// make the energy function
63 void make_matrices (Matrix &quad, Vector &lin,Real&) const;
65 /// generate the LP constraints
66 void make_constraints (Mixed_qp& lp) const;
69 void handle_loose_cols();
70 void position_loose_cols (Vector &) const;
71 void print_ideal (Idealspacing const *) const;
72 Vector try_initial_solution() const;
73 void calcideal();
75 Score_column* scol_l (int);
76 void connect (int i,int j, Real,Real);
77 public:
78 static Line_spacer *constructor() {
79 return new Line_spacer;
81 Array<Paper_column*> error_pcol_l_arr() const;
83 virtual Array<Real> solve() const;
84 virtual void add_column (Paper_column *, bool fixed=false, Real fixpos=0.0);
87 virtual Vector default_solution() contains {
88 return try_initial_solution() ;
90 virtual bool check_constraints (Vector v) const;
91 virtual void OK() const;
92 virtual void print() const;
93 virtual void prepare();