]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-item.cc
release: 0.1.7
[lilypond.git] / lily / key-item.cc
1 /*
2   key-item.cc -- implement Key_item
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
7
8   keyplacement by Mats Bengtsson
9 */
10
11 #include "key-item.hh"
12 #include "key.hh"
13 #include "debug.hh"
14 #include "molecule.hh"
15 #include "paper-def.hh"
16 #include "lookup.hh"
17
18 #include "key-grav.hh"
19
20 const int FLAT_TOP_PITCH=2; /* fes,ges,as and bes typeset in lower octave */
21 const int SHARP_TOP_PITCH=4; /*  ais and bis typeset in lower octave */
22
23 Key_item::Key_item(int c)
24 {
25     breakable_b_ =true;
26     default_b_ = false;
27     set_c_position(c);
28 }
29
30 void
31 Key_item::read(Key_engraver const & key_grav_r)
32 {
33     assert(!key_grav_r.key_.multi_octave_b_);
34     const Array<int> &idx_arr =key_grav_r.accidental_idx_arr_; 
35     for (int i = 0 ; i< idx_arr.size(); i++) {
36         int note = idx_arr[i];
37         int acc = ((Key &) key_grav_r.key_).oct(0).acc(note);
38
39         add(note, acc);
40     }
41 }
42
43 void 
44 Key_item::set_c_position(int c0)
45 {
46     int octaves =(abs(c0) / 7) +1 ;
47     c_position=(c0 + 7*octaves)%7;
48 }
49
50
51 void
52 Key_item::add(int p, int a)
53 {
54     if ((a<0 && p>FLAT_TOP_PITCH) ||
55         (a>0 && p>SHARP_TOP_PITCH)) {
56       p -= 7; /* Typeset below c_position */
57     }
58     pitch.push(p);
59     acc.push(a);
60 }
61
62
63 Molecule*
64 Key_item::brew_molecule_p()const
65 {
66     Molecule*output = new Molecule;
67     Real inter = paper()->internote_f();
68     
69     for (int i =0; i < pitch.size(); i++) {
70         Symbol s= paper()->lookup_l()->accidental(acc[i]);
71         Atom a(s);
72         a.translate((c_position + pitch[i]) * inter, Y_AXIS);
73         Molecule m(a);
74         output->add_right(m);   
75     }
76     if ( pitch.size() ) {
77         Molecule m(paper()->lookup_l()->fill(Box(
78         Interval(0, paper()->note_width()),
79         Interval(0,0))));
80
81         output->add_right(m);
82     }
83     return output;
84 }
85
86 IMPLEMENT_IS_TYPE_B1(Key_item,Item);
87
88 void 
89 Key_item::do_pre_processing()
90 {
91     if (default_b_ ) {
92         empty_b_ = transparent_b_ = (break_status_i() != 1);
93     }
94 }