]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/linespace.hh
release: 1.0.1
[lilypond.git] / lily / include / linespace.hh
1 /*
2   linespace.hh -- declare  Spacing_problem
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996, 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #error
10
11 #ifndef LINESPACE_HH
12 #define LINESPACE_HH
13
14 #include "plist.hh"
15 #include "array.hh"
16 #include "vector.hh"
17 #include "interval.hh"
18 #include "pointer.hh"
19
20
21 /** the problem, given by the columns (which include constraints) and
22     intercolumn spacing. The problem is:
23
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.
36
37     The quality is given by the total potential energy in the
38     springs. The lower the energy, the better the configuration.
39
40     TODO: make item widths work per pstaff.
41
42 */
43 class Spacing_problem {
44     PointerList<Idealspacing *> ideal_p_list_;
45     Array<Column_info> cols;
46     Array<Column_info> loose_col_arr_;
47     
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;
52
53     /// generate an (nonoptimal) solution
54     Vector find_initial_solution() const;
55
56     /// check if problem is too tight
57     bool check_feasible() const;
58
59     /// does #this# contain the column #w#? 
60     bool contains (Paper_column const *w);
61
62     /// make the energy function
63     void make_matrices (Matrix &quad, Vector &lin,Real&) const;
64
65     /// generate the LP constraints
66     void make_constraints (Mixed_qp& lp) const;
67
68
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();
74
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;
80     }
81     Array<Paper_column*> error_pcol_l_arr() const;
82
83     virtual   Array<Real> solve() const;
84     virtual void add_column (Paper_column  *, bool fixed=false, Real fixpos=0.0);
85  
86
87     virtual Vector default_solution() contains { 
88         return try_initial_solution() ; 
89     }
90     virtual   bool check_constraints (Vector v) const;
91     virtual    void OK() const;
92     virtual    void print() const;
93     virtual    void prepare();
94 };