]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/spring-spacer.hh
release: 1.0.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--1998 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 "plist.hh"
15 #include "col-info.hh"
16 #include "colhpos.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     TODO: make item widths work per Staff.
43
44 */
45
46 class Spring_spacer : public Line_spacer {
47   friend class Durations_iter;
48   
49     
50   Pointer_list<Idealspacing *> ideal_p_list_;
51   Array<Column_info> cols_;
52   Array<Column_info> loose_col_arr_;
53   Array<Spacer_rod> rods_;
54   
55   /// mark column #i# as being loose.
56   void loosen_column (int i);
57   /// the index of #c# in #cols#
58   int col_id (Paper_column const *c) const;
59
60   /// generate an (nonoptimal) solution
61   Vector find_initial_solution() const;
62
63   /// does #this# contain the column #w#? 
64   bool contains_b (Paper_column const *w);
65
66   /// make the energy function
67   void make_matrices (Matrix &quad, Vector &lin,Real&) const;
68   void get_ruling_durations(Array<Moment>&, Array<Moment>&);
69
70   /// generate the LP constraints
71   void make_constraints (Mixed_qp& lp) const;
72
73
74   void handle_loose_cols();
75   void position_loose_cols (Vector &) const;
76   bool try_initial_solution_and_tell (Vector&)const;
77   Vector try_initial_solution() const;
78   void calc_idealspacing();
79   void set_fixed_cols (Mixed_qp&) const;
80
81   Score_column* scol_l (int);
82   void connect (int i,int j, Real,Real);
83   Line_of_cols error_pcol_l_arr() const;
84   Real calculate_energy_f (Vector) const;
85 public:
86   static Line_spacer *constructor();
87   Real energy_normalisation_f_;
88   Spring_spacer ();
89   virtual void solve (Column_x_positions*) const;
90   virtual void lower_bound_solution (Column_x_positions*) const;
91   virtual void add_column (Paper_column  *, bool fixed=false, Real fixpos=0.0);
92  
93
94   virtual Vector default_solution() const;
95   virtual bool check_constraints (Vector v) const;
96   virtual void OK() const;
97   virtual void print() const;
98   virtual void prepare();
99   virtual ~Spring_spacer(){}
100 };
101
102 #endif // SPRING_SPACER_HH