]> git.donarmstrong.com Git - lilypond.git/blob - src/calcideal.cc
a656482e7dca39507df33c16aa3a760da04ec3e6
[lilypond.git] / src / calcideal.cc
1 #include "idealspacing.hh"
2 #include "score.hh"
3 #include "pscore.hh"
4 #include "paperdef.hh"
5 #include "sccol.hh"
6 #include "dimen.hh"
7
8
9 /**
10   this needs A LOT of rethinking.
11
12   generate springs between columns.
13
14   */
15 void
16 Score::calc_idealspacing()
17 {
18     iter_top(cols_,i);
19
20     for (; i.ok(); i++) {
21         assert(i->used());
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);
30                 
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);
35                 
36                 pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, strength);
37             }
38         } else if (j.ok()) {
39             
40             /* attach i to the next column in use. This exists, since
41               the last col is breakable, and therefore in use
42               */
43             
44             Moment d = j->when() - i->when();
45             Real dist = (d) ? paper_p_->duration_to_dist(d) : 2 PT; // todo
46             
47             pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, (d) ? 1.0:1.0);
48         }
49         // !j.ok() might hold if we're at the last col.
50     }
51 }
52
53