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