]> git.donarmstrong.com Git - lilypond.git/blob - src/slur.cc
release: 0.0.11
[lilypond.git] / src / slur.cc
1 #include "slur.hh"
2 #include "lookup.hh"
3 #include "paper.hh"
4 #include "notehead.hh"
5 #include "pcol.hh"
6 #include "molecule.hh"
7 #include "debug.hh"
8 #include "boxes.hh"
9
10 void
11 Slur::add(Notehead*n)
12 {
13     encompass.add(n);
14     dir = 0;
15     open_right=open_left=false;
16 }
17
18 Interval
19 Slur::height() const
20 {
21     return Interval(0,0);       // todo
22 }
23
24 void
25 Slur::set_default_dir()
26 {
27     int sumpos=0;
28     for (int i=0; i < encompass.sz(); i ++) {
29         sumpos += encompass[i]->position;
30     }
31
32     /* should consult stems */
33     Real meanpos = sumpos/Real(encompass.sz());
34     if (meanpos < 5)            // todo
35         dir = -1;
36     else
37         dir = 1;    
38 }
39
40 void
41 Slur::print()const
42 {
43     mtor << "Slur.\n";   
44 }
45
46 void
47 Slur::preprocess()
48 {
49     right  = encompass.last()->pcol_;
50     left = encompass[0]->pcol_;    
51 }
52
53 Spanner*
54 Slur::broken_at(const PCol*l, const PCol*r) const
55 {
56     assert(l->line == r->line);
57     Slur*ret = new Slur(*this);
58     ret->encompass.set_size(0);
59     for (int i =0; i < encompass.sz(); i++) {
60         if (encompass[i]->pcol_->line==l->line)
61             ret->encompass.add(encompass[i]);
62     }
63     if (right != r)
64         ret->open_right = true;
65     if (left != l)
66         ret->open_left = true;
67
68     ret->left = l;
69     ret->right = r;
70     return ret;
71 }
72
73 void
74 Slur::process()
75 {
76     set_default_dir();
77     brew_molecule();
78 }
79
80 void
81 Slur::brew_molecule()
82 {
83     output = new Molecule;
84     assert(left->line == right->line);
85     int minp=1000, maxp=-1000;  // todo
86     for (int i=0; i<encompass.sz(); i++) {
87         minp = MIN(encompass[i]->position, minp);
88         maxp = MAX(encompass[i]->position, maxp);
89     }
90     
91     assert(encompass.sz()>0);   // todo
92     int pos1 = encompass.last()->position;
93     int pos2 = encompass[0]->position;
94
95     int dy =  pos1-pos2;
96
97     Real w = width().length();
98     Real nw = paper()->note_width();
99     w -= nw;
100     Symbol sl = paper()->lookup_->slur(dy , w, dir);
101     Atom a(sl);
102     a.translate(Offset(nw,pos2*paper()->internote()));
103     output->add(a);
104 }
105