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