]> git.donarmstrong.com Git - lilypond.git/blob - calcideal.cc
bddd4f28970f7b76ac0deb5b8c8eebc2b0fba4c3
[lilypond.git] / calcideal.cc
1 #include "tstream.hh"
2 #include "score.hh"
3 #include "pscore.hh"
4 #include "staff.hh"
5 #include "paper.hh"
6 #include "misc.hh"
7 #include "sccol.hh"
8 #include "debug.hh"
9
10
11 void
12 Score::do_connect(PCol *c1, PCol *c2, Real d)
13 {
14     Idealspacing*sp=pscore_->get_spacing(c1,c2);
15         
16     if (!sp->hooke){
17         sp->hooke = 1.0;
18         sp->space =d;
19     }
20 }
21
22 void
23 Score::connect_nonmus(PCol* c1, PCol *c2, Real d)
24 {
25     if (c2->used && c1->used) {
26         do_connect(c1,c2,d);
27
28         // alert! this is broken!
29         if (c1->breakable) {
30             do_connect(c1->postbreak, c2,d);
31         }
32         if (c2->breakable) {
33             do_connect(c1, c2->prebreak,d);
34         }
35         if (c1->breakable &&c2->breakable) {
36             do_connect(c1->postbreak, c2->prebreak,d);      
37         }       
38     }
39 }
40 /* this needs A LOT of rethinking.
41
42     generate springs between columns.
43     */
44 void
45 Score::calc_idealspacing()
46 {
47     PCursor<Score_column*> sc(cols_);
48
49     for (; sc.ok(); sc++) {
50         if (sc->musical)
51             for (int i=0; i < sc->durations.sz(); i++) {
52                 Mtime d = sc->durations[i];
53                 Real dist = duration_to_idealspace(d, paper->whole_width);
54                 PCol * c2 = find_col(sc->when + d,true)->pcol;
55                 connect_nonmus(sc->pcol, c2, dist);
56                 c2 = find_col(sc->when + d,false)->pcol;
57                 connect_nonmus(sc->pcol, c2,  dist);
58             }
59         else if (sc->used()) {  // ignore empty columns
60             PCol * c2 = find_col(sc->when,true)->pcol;
61             connect_nonmus(sc->pcol,c2,0.0);
62         }
63     }           
64 }
65
66