]> git.donarmstrong.com Git - lilypond.git/blob - src/calcideal.cc
47ca885adecf9cd2fd64be3370bea884e1c1d371
[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 #if 1
41     PCursor<Score_column*> i(cols_);
42
43     for (; i.ok(); i++) {
44         assert(i->used());
45         PCursor<Score_column*> j (i+1);
46         if (i->musical) {
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(j->when == d+i->when);
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");
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 #else
78     PCursor<Score_column*> sc(cols_);
79
80     for (; sc.ok(); sc++) {
81         if (sc->musical)
82             for (int i=0; i < sc->durations.sz(); i++) {
83                 Real d = sc->durations[i];
84                 Real dist = paper_->duration_to_dist(d);
85                 PCol * c2 = find_col(sc->when + d,true)->pcol_;
86                 connect(sc->pcol_, c2, dist);
87                 c2 = find_col(sc->when + d,false)->pcol_;
88                 connect(sc->pcol_, c2,  dist);
89             }
90         else if (sc->used()) {  // ignore empty columns
91             PCol * c2 = find_col(sc->when,true)->pcol_;
92             connect(sc->pcol_, c2, 0.0);
93         }
94 #endif
95 }
96
97