]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-item.cc
release: 0.0.72pre
[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-grav.hh"
8 #include "key-grav.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 Key_item::Key_item(int c)
14 {
15     default_b_ = false;
16     set_c_position(c);
17 }
18
19 void
20 Key_item::read(Key_engraver const & key_grav_r)
21 {
22     assert(!key_grav_r.key_.multi_octave_b_);
23     const Array<int> &idx_arr =key_grav_r.accidental_idx_arr_; 
24     for (int i = 0 ; i< idx_arr.size(); i++) {
25         int note = idx_arr[i];
26         int acc = ((Key &) key_grav_r.key_).oct(0).acc(note);
27
28         add(note, acc);
29     }
30 }
31
32 void 
33 Key_item::set_c_position(int c0)
34 {
35     int octaves =(abs(c0) / 7) +1 ;
36     c_position=(c0 + 7*octaves)%7;
37 }
38
39
40 void
41 Key_item::add(int p, int a)
42 {
43     if ((a<0 && p>FLAT_TOP_PITCH) ||
44         (a>0 && p>SHARP_TOP_PITCH)) {
45       p -= 7; /* Typeset below c_position */
46     }
47     pitch.push(p);
48     acc.push(a);
49 }
50
51
52 Molecule*
53 Key_item::brew_molecule_p()const
54 {
55     Molecule*output = new Molecule;
56     Real inter = paper()->internote_f();
57     
58     for (int i =0; i < pitch.size(); i++) {
59         Symbol s= paper()->lookup_l()->accidental(acc[i]);
60         Atom a(s);
61         a.translate_y((c_position + pitch[i]) * inter);
62         Molecule m(a);
63         output->add_right(m);   
64     }
65     if ( pitch.size() ) {
66         Molecule m(paper()->lookup_l()->fill(Box(
67         Interval(0, paper()->note_width()),
68         Interval(0,0))));
69
70         output->add_right(m);
71     }
72     return output;
73 }
74 IMPLEMENT_STATIC_NAME(Key_item);
75 IMPLEMENT_IS_TYPE_B1(Key_item,Item);
76
77 void 
78 Key_item::do_pre_processing()
79 {
80     if (default_b_ ) {
81         empty_b_ = transparent_b_ = (break_status_i() != 1);
82     }
83 }