]> git.donarmstrong.com Git - lilypond.git/blob - src/localkeyitem.cc
b210dbdac3ee2c5a0762fca35151c8f51fa516dc
[lilypond.git] / src / localkeyitem.cc
1 #include "localkeyitem.hh"
2 #include "molecule.hh"
3 #include "scalar.hh"
4 #include "lookup.hh"
5 #include "paper.hh"
6 #include "notehead.hh"
7 Local_key_item::Local_key_item(int i)
8 {
9     c0_position  = i;
10 }
11
12 void
13 Local_key_item::add (int o, int p , int a,Notehead*head_p)
14 {
15     Local_acc l;
16     l.octave = o;
17     l.name = p;
18     l.acc = a;
19     accs.add(l);
20     group.add(head_p);
21     dependencies.add(head_p);
22 }
23
24 void
25 Local_key_item::do_pre_processing()
26 {
27     accs.sort(Local_acc::compare);
28 }
29 Molecule*
30 Local_key_item::brew_molecule_p()const
31 {
32
33     Molecule*    output = new Molecule;
34     Molecule*octmol = 0;
35     int lastoct = -100;
36     for  (int i = 0; i <  accs.size(); i++) {
37         if (accs[i].octave != lastoct) {
38             if (octmol){
39                 Real dy =lastoct*7*paper()->interline()/2;
40                 octmol->translate(Offset(0, dy));
41                 output->add(*octmol);
42                 delete octmol;
43             }
44             octmol= new Molecule;
45         }
46         lastoct = accs[i].octave;
47         Symbol s =paper()->lookup_p_->accidental(accs[i].acc);   
48         Atom a(s);
49         Real dy = (accs[i].name + c0_position) * paper()->interline()/2;
50         a.translate(Offset(0,dy));
51
52         octmol->add_right(a);
53     }
54
55     if (octmol){
56         Real dy =lastoct*7*paper()->interline()/2;
57         octmol->translate(Offset(0, dy));
58         output->add(*octmol);
59         delete octmol;
60     }
61     return output;
62 }
63
64 int
65 Local_acc::compare(Local_acc&a, Local_acc&b)
66 {
67     if (a.octave - b.octave)
68         return a.octave - b.octave;
69     if (a.name - b.name)
70         return a.name - b.name;
71     
72     assert(false);
73 };