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