]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/spring-spacer.hh
release: 1.2.8
[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--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef SPRING_SPACER_HH
11 #define SPRING_SPACER_HH
12
13 #include "line-spacer.hh"
14 #include "cons.hh"
15 #include "col-info.hh"
16 #include "column-x-positions.hh"
17 #include "moment.hh"
18
19
20
21 /** 
22   Determine positions of columns connected by springs and held apart by rods.
23   
24   
25     Generate a spacing which
26     \begin{itemize}
27     \item
28     Satisfies spacing constraints (notes can't be printed through each other)
29     \item
30     Looks good, ie tries to conform to  an ideal spacing as much as possible.
31     \end{itemize}
32   
33     This is converted by regarding idealspacing as "springs" attached
34     to columns. The equilibrium of one spring is the ideal
35     distance. The columns have a size, this imposes "hard" constraints
36     on the distances. This transforms the problem into a quadratic
37     programming problem with linear constraints.
38
39     The quality is given by the total potential energy in the
40     springs. The lower the energy, the better the configuration.
41
42
43     TODO: too complicated.  Revise.
44     Use force iso. energy.  Also optimise for uniform density
45 */
46
47 class Spring_spacer : public Line_spacer {
48   friend class Durations_iter;
49 private:
50   // can't copy me.
51   Spring_spacer (Spring_spacer const&s);
52   Cons<Idealspacing> *ideal_p_list_;
53   Array<Column_info> cols_;
54   Real indent_f_;
55   
56   /// the index of #c# in #cols#
57   int col_id (Paper_column const *c) const;
58
59   /// generate an (nonoptimal) solution
60   Vector find_initial_solution() const;
61
62   /// does #this# contain the column #w#? 
63   bool contains_b (Paper_column const *w);
64
65   /// make the energy function
66   void make_matrices (Matrix &quad, Vector &lin,Real&) const;
67
68
69   /// generate the LP constraints
70   void make_constraints (Mixed_qp& lp) const;
71
72
73   void handle_loose_cols();
74   bool try_initial_solution_and_tell (Vector&)const;
75   Vector try_initial_solution() const;
76
77   void set_fixed_cols (Mixed_qp&) const;
78
79   Score_column* scol_l (int);
80   void connect (int i,int j, Real,Real);
81   Real calculate_energy_f (Vector) const;
82 public:
83   static Line_spacer *constructor();
84   Real energy_normalisation_f_;
85   Spring_spacer ();
86   virtual ~Spring_spacer ();  
87   virtual void solve (Column_x_positions*) const;
88   virtual void lower_bound_solution (Column_x_positions*) const;
89   virtual void add_columns (Link_array<Paper_column>);
90   void add_column (Paper_column *, bool,  Real);  
91
92   virtual Vector default_solution() const;
93   virtual bool check_constraints (Vector v) const;
94   virtual void OK() const;
95   virtual void print() const;
96   virtual void prepare();
97 };
98
99 #endif // SPRING_SPACER_HH