]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-item.cc
release: 0.1.15
[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     {
37       int note = idx_arr[i];
38       int acc = ((Key &) key_grav_r.key_).oct (0).acc (note);
39
40       add (note, acc);
41     }
42 }
43
44 void 
45 Key_item::set_c_position (int c0)
46 {
47   int octaves =(abs (c0) / 7) +1 ;
48   c_position=(c0 + 7*octaves)%7;
49 }
50
51
52 void
53 Key_item::add (int p, int a)
54 {
55   if ((a<0 && p>FLAT_TOP_PITCH) ||
56       (a>0 && p>SHARP_TOP_PITCH)) 
57     {
58       p -= 7; /* Typeset below c_position */
59     }
60   pitch.push (p);
61   acc.push (a);
62 }
63
64
65 Molecule*
66 Key_item::brew_molecule_p() const
67 {
68   Molecule*output = new Molecule;
69   Real inter = paper()->internote_f ();
70   
71   for (int i =0; i < pitch.size(); i++) 
72     {
73       Atom a =paper()->lookup_l ()->accidental (acc[i]);
74       a.translate ((c_position + pitch[i]) * inter, Y_AXIS);
75       Molecule m (a);
76       output->add_at_edge (X_AXIS, RIGHT, m);   
77     }
78   if (pitch.size()) 
79     {
80       Molecule m (paper()->lookup_l ()->fill (Box (
81                                                    Interval (0, paper()->note_width ()),
82                                                    Interval (0,0))));
83
84       output->add_at_edge (X_AXIS, RIGHT, m);
85     }
86   return output;
87 }
88
89 IMPLEMENT_IS_TYPE_B1(Key_item,Item);
90
91 void 
92 Key_item::do_pre_processing()
93 {
94   if (default_b_) 
95     {
96       transparent_b_ = (break_status_i() != 1);
97       set_empty (transparent_b_);
98     }
99 }