]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
release: 0.0.41
[lilypond.git] / lily / local-key-item.cc
1 #include "local-key-item.hh"
2 #include "molecule.hh"
3 #include "scalar.hh"
4 #include "lookup.hh"
5 #include "paper-def.hh"
6 #include "musical-request.hh"
7 #include "notehead.hh"
8 #include "misc.hh"
9
10
11
12 Local_key_item::Local_key_item(int i)
13 {
14     c0_position  = i;
15 }
16
17 void
18 Local_key_item::add(Item*head_l)
19 {
20     support_items_.push(head_l);
21     add_dependency(head_l);
22 }
23
24 void
25 Local_key_item::add(Melodic_req*m_l)
26 {
27     add(m_l->octave_i_, m_l->notename_i_, m_l->accidental_i_);
28 }
29 void
30 Local_key_item::add (int o, int p , int a)
31 {
32     Local_acc l;
33     l.octave = o;
34     l.name = p;
35     l.acc = a;
36     accs.push(l);
37 }
38
39 void
40 Local_key_item::do_pre_processing()
41 {
42     accs.sort(Local_acc::compare);
43 }
44
45 Molecule*
46 Local_key_item::brew_molecule_p()const
47 {
48     Molecule* output = new Molecule;
49     Molecule*octmol = 0;
50     int lastoct = -100;
51     for  (int i = 0; i <  accs.size(); i++) {
52         // do one octave
53         if (accs[i].octave != lastoct) {
54             if (octmol){
55                 Real dy =lastoct*7*paper()->internote();
56                 octmol->translate(Offset(0, dy));
57                 output->add(*octmol);
58                 delete octmol;
59             }
60             octmol= new Molecule;
61         }
62         lastoct = accs[i].octave;
63         Symbol s =paper()->lookup_l()->accidental(accs[i].acc);   
64         Atom a(s);
65         Real dy = (accs[i].name + c0_position) * paper()->internote();
66         a.translate(Offset(0,dy));
67
68         octmol->add_right(a);
69     }
70
71     if (octmol){
72         Real dy =lastoct*7*paper()->internote();
73         octmol->translate(Offset(0, dy));
74         output->add(*octmol);
75         delete octmol;
76     }
77
78     Interval head_width=itemlist_width(support_items_);
79     output->translate(Offset(-output->extent().x.right + head_width.left ,0));
80     
81     return output;
82 }
83
84 int
85 Local_acc::compare(Local_acc&a, Local_acc&b)
86 {
87     if (a.octave - b.octave)
88         return a.octave - b.octave;
89     if (a.name - b.name)
90         return a.name - b.name;
91     
92     assert(false);
93 };