]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-item.cc
release: 0.0.53
[lilypond.git] / lily / key-item.cc
1 #include "key-item.hh"
2 #include "key.hh"
3 #include "debug.hh"
4 #include "molecule.hh"
5 #include "paper-def.hh"
6 #include "lookup.hh"
7 //#include "clef-reg.hh"
8 #include "key-reg.hh"
9
10 const int FLAT_TOP_PITCH=2; /* fes,ges,as and bes typeset in lower octave */
11 const int SHARP_TOP_PITCH=4; /*  ais and bis typeset in lower octave */
12
13
14
15 Key_item::Key_item(int c)
16 {
17     set_c_position(c);
18 }
19
20 void
21 Key_item::read(Key_register const & key_reg_r)
22 {
23     assert(!key_reg_r.key_.multi_octave_b_);
24     const Array<int> &idx_arr =key_reg_r.accidental_idx_arr_; 
25     for (int i = 0 ; i< idx_arr.size(); i++) {
26         int note = idx_arr[i];
27         int acc = ((Key &) key_reg_r.key_).oct(0).acc(note);
28
29         add(note, acc);
30     }
31 }
32
33 void 
34 Key_item::set_c_position(int c0)
35 {
36     int octaves =(abs(c0) / 7) +1 ;
37     c_position=(c0 + 7*octaves)%7;
38 }
39
40
41 void
42 Key_item::add(int p, int a)
43 {
44     if ((a<0 && p>FLAT_TOP_PITCH) ||
45         (a>0 && p>SHARP_TOP_PITCH)) {
46       p -= 7; /* Typeset below c_position */
47     }
48     pitch.push(p);
49     acc.push(a);
50 }
51
52
53 Molecule*
54 Key_item::brew_molecule_p()const
55 {
56     Molecule*output = new Molecule;
57     Real inter = paper()->internote();
58     
59     for (int i =0; i < pitch.size(); i++) {
60         Symbol s= paper()->lookup_l()->accidental(acc[i]);
61         Atom a(s);
62         a.translate(Offset(0,(c_position + pitch[i]) * inter));
63         Molecule m(a);
64         output->add_right(m);   
65     }
66     Molecule m(paper()->lookup_l()->fill(Box(
67         Interval(0, paper()->note_width()),
68         Interval(0,0))));
69     output->add_right(m);
70     return output;
71 }
72 IMPLEMENT_STATIC_NAME(Key_item);