lilypond-0.1.57
[lilypond.git] / lily / key-item.cc
blobd80f01670dda03f6d76f5524e3708d7995004fe3
1 /*
2 key-item.cc -- implement Key_item
4 source file of the GNU LilyPond music typesetter
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
8 keyplacement by Mats Bengtsson
9 */
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"
18 #include "key-grav.hh"
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 */
23 Key_item::Key_item (int c)
25 breakable_b_ =true;
26 default_b_ = false;
27 set_c_position (c);
30 void
31 Key_item::read (Key_engraver const & key_grav_r)
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++)
37 int note = idx_arr[i];
38 int acc = ((Key &) key_grav_r.key_).oct (0).acc (note);
40 add (note, acc);
44 void
45 Key_item::set_c_position (int c0)
47 int from_bottom_pos = c0 + 4; // ugh
48 int octaves =(from_bottom_pos / 7) +1 ;
49 from_bottom_pos =(from_bottom_pos + 7*octaves)%7;
50 c_position = from_bottom_pos - 4;
54 void
55 Key_item::add (int p, int a)
57 if ((a<0 && ((p>FLAT_TOP_PITCH) || (p+c_position>4)) && (p+c_position>1))
59 (a>0 && ((p>SHARP_TOP_PITCH) || (p+c_position>5)) && (p+c_position>2)))
61 p -= 7; /* Typeset below c_position */
63 pitch.push (p);
64 acc.push (a);
68 Molecule*
69 Key_item::brew_molecule_p() const
71 Molecule*output = new Molecule;
72 Real inter = paper()->internote_f ();
74 for (int i =0; i < pitch.size(); i++)
76 Atom a =paper()->lookup_l ()->accidental (acc[i]);
77 a.translate_axis ((c_position + pitch[i]) * inter, Y_AXIS);
78 Molecule m (a);
79 output->add_at_edge (X_AXIS, RIGHT, m);
81 if (pitch.size())
83 Molecule m (paper()->lookup_l ()->fill (Box (
84 Interval (0, paper()->note_width ()),
85 Interval (0,0))));
87 output->add_at_edge (X_AXIS, RIGHT, m);
89 return output;
92 IMPLEMENT_IS_TYPE_B1(Key_item,Item);
94 void
95 Key_item::do_pre_processing()
97 if (default_b_)
99 transparent_b_ = (break_status_i() != 1);
100 set_empty (transparent_b_);