]> git.donarmstrong.com Git - lilypond.git/blob - src/calcideal.cc
release: 0.0.18
[lilypond.git] / src / calcideal.cc
1 #include "tstream.hh"
2 #include "score.hh"
3 #include "pscore.hh"
4 #include "staff.hh"
5 #include "paper.hh"
6 #include "sccol.hh"
7 #include "debug.hh"
8 #include "dimen.hh"
9
10
11 void
12 Score::do_connect(PCol *c1, PCol *c2, Real d, Real h)
13 {
14     if (!c1 || !c2 )
15         return;
16     Idealspacing*sp=pscore_->get_spacing(c1,c2);
17         
18     if (!sp->hooke){
19         sp->hooke = h;
20         sp->space =d;
21     }
22 }
23
24 void
25 Score::connect(PCol* c1, PCol *c2, Real d, Real h)
26 {
27     do_connect(c1,c2,d,h);
28     do_connect(c1->postbreak, c2,d,h);
29     do_connect(c1, c2->prebreak,d,h);
30     do_connect(c1->postbreak, c2->prebreak,d,h);
31 }
32
33 /* this needs A LOT of rethinking.
34
35     generate springs between columns.
36     */
37 void
38 Score::calc_idealspacing()
39 {
40     PCursor<Score_column*> i(cols_);
41
42     for (; i.ok(); i++) {
43         assert(i->used());
44         PCursor<Score_column*> j (i+1);
45         if (i->musical) {
46             assert(j.ok());
47             for (int n=0; n < i->durations.sz(); n++) {
48                 Real d = i->durations[n];
49                 Real dist = paper_->duration_to_dist(d);
50                 while (j->when < d + i->when)
51                     j++;
52                 
53                 assert( distance(j->when, d+i->when) < 1e-8);
54
55                 connect(i->pcol_, j->pcol_, dist);
56                 if (!j->musical && (j+1).ok() 
57                     && (j+1)->when == j->when) {
58                     j++;
59                     connect(i->pcol_, j->pcol_,  dist);
60                 }
61             }
62         } else if (j.ok()) {
63             
64             /* attach i to the next column in use. This exists, since
65               the last col is breakable, and therefore in use
66               */
67             
68             Real d = j->when - i->when;
69             Real dist = (d) ? paper_->duration_to_dist(d) :
70                 convert_dimen(2,"pt"); // todo
71             
72             connect(i->pcol_, j->pcol_, dist, (d) ? 1.0:1.0);
73         }
74             // !j.ok() might hold if we're at the last col.
75         
76     }
77 }
78
79