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