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