]> git.donarmstrong.com Git - lilypond.git/blob - lily/calcideal.cc
11c1aa2d2cb0b42ed9999c5338614f9f9329f13b
[lilypond.git] / lily / calcideal.cc
1 /*
2   calcideal.cc -- implement Score::calc_idealspacing()
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
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"
15
16
17 /**
18   generate springs between columns.
19
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.
23     
24   plus, calc_idealspacing() should be called per line.
25   */
26 void
27 Score::calc_idealspacing()
28 {
29     iter_top(cols_,i);
30
31     for (; i.ok(); i++) {
32         if (!i->used_b())
33             continue;
34         
35         PCursor<Score_column*> j(i+1);
36
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);
44                 
45                 while (j.ok()) {
46                     if (j->used_b() && j->when() >= d + i->when() )
47                         break;
48                     j++;
49                 }
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);
55             }
56         } else if (j.ok()) {
57             while  (!j->used_b())
58                 j++;
59             
60             /* attach i to the next column in use. This exists, since
61               the last col is breakable, and therefore in use
62               */
63             
64             Moment d = j->when() - i->when();
65             Real dist = (d) ? paper_p_->duration_to_dist(d) : 2 PT; // todo
66             
67             pscore_p_->connect(i->pcol_l_, j->pcol_l_, dist, (d) ? 1.0:1.0);
68         }
69         // !j.ok() might hold if we're at the last col.
70     }
71 }
72
73