lilypond-1.5.9
[lilypond.git] / lily / calcideal.cc
blob11c1aa2d2cb0b42ed9999c5338614f9f9329f13b
1 /*
2 calcideal.cc -- implement Score::calc_idealspacing()
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "idealspacing.hh"
10 #include "score.hh"
11 #include "p-score.hh"
12 #include "paper-def.hh"
13 #include "score-column.hh"
14 #include "dimen.hh"
17 /**
18 generate springs between columns.
20 TODO: This needs A LOT of rethinking. Spacing should take optical
21 effects into account, should be local (measure wide), should check
22 smallest divisions.
24 plus, calc_idealspacing() should be called per line.
26 void
27 Score::calc_idealspacing()
29 iter_top(cols_,i);
31 for (; i.ok(); i++) {
32 if (!i->used_b())
33 continue;
35 PCursor<Score_column*> j(i+1);
37 if (i->musical_b()) {
38 assert(j.ok());
39 for (int n=0; n < i->durations.size(); n++) {
40 Moment d = i->durations[n];
41 Real dist = paper_p_->duration_to_dist(d);
42 Real strength = i->durations[0]/i->durations[n];
43 assert(strength <= 1.0);
45 while (j.ok()) {
46 if (j->used_b() && j->when() >= d + i->when() )
47 break;
48 j++;
50 Moment delta_desired = j->when() - (d+i->when());
51 dist += paper_p_->duration_to_dist(delta_desired);
52 if (!j->musical_b())
53 dist += 1 PT; // ugh
54 pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, strength);
56 } else if (j.ok()) {
57 while (!j->used_b())
58 j++;
60 /* attach i to the next column in use. This exists, since
61 the last col is breakable, and therefore in use
64 Moment d = j->when() - i->when();
65 Real dist = (d) ? paper_p_->duration_to_dist(d) : 2 PT; // todo
67 pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, (d) ? 1.0:1.0);
69 // !j.ok() might hold if we're at the last col.