lilypond-0.0.40
[lilypond.git] / src / calcideal.cc
blob5ead08dd396ef25d556d1d8df92031a9bf952c28
1 #include "idealspacing.hh"
2 #include "score.hh"
3 #include "pscore.hh"
4 #include "paper-def.hh"
5 #include "score-column.hh"
6 #include "dimen.hh"
9 /**
10 this needs A LOT of rethinking.
12 generate springs between columns.
15 void
16 Score::calc_idealspacing()
18 iter_top(cols_,i);
20 for (; i.ok(); i++) {
21 assert(i->used_b());
22 PCursor<Score_column*> j(i+1);
23 if (i->musical_b()) {
24 assert(j.ok());
25 for (int n=0; n < i->durations.size(); n++) {
26 Moment d = i->durations[n];
27 Real dist = paper_p_->duration_to_dist(d);
28 Real strength = i->durations[0]/i->durations[n];
29 assert(strength <= 1.0);
31 while (j->when() < d + i->when())
32 j++;
33 Moment delta_desired = j->when() - (d+i->when());
34 dist += paper_p_->duration_to_dist(delta_desired);
36 pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, strength);
38 } else if (j.ok()) {
40 /* attach i to the next column in use. This exists, since
41 the last col is breakable, and therefore in use
44 Moment d = j->when() - i->when();
45 Real dist = (d) ? paper_p_->duration_to_dist(d) : 2 PT; // todo
47 pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, (d) ? 1.0:1.0);
49 // !j.ok() might hold if we're at the last col.