lilypond-0.1.15
[lilypond.git] / lily / local-key-item.cc
blob65c5ad7253c070cbdd0d3ad43f9ebb631681cf85
1 /*
2 local-key-item.cc -- implement Local_key_item, Local_acc
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "local-key-item.hh"
10 #include "molecule.hh"
11 #include "scalar.hh"
12 #include "lookup.hh"
13 #include "paper-def.hh"
14 #include "musical-request.hh"
15 #include "note-head.hh"
16 #include "misc.hh"
20 Local_key_item::Local_key_item (int i)
22 c0_position = i;
25 void
26 Local_key_item::add_support (Item*head_l)
28 support_items_.push (head_l);
29 add_dependency (head_l);
32 void
33 Local_key_item::add (Melodic_req*m_l)
35 add (m_l->octave_i_, m_l->notename_i_, m_l->accidental_i_);
38 void
39 Local_key_item::add (int o, int p , int a)
41 Local_acc l;
42 l.octave_i_ = o;
43 l.name_i_ = p;
44 l.accidental_i_ = a;
45 for (int i=0; i< accs.size(); i++)
46 if (!Local_acc::compare (l, accs[i]))
47 return;
49 accs.push (l);
52 void
53 Local_key_item::do_pre_processing()
55 accs.sort (Local_acc::compare);
58 Molecule*
59 Local_key_item::brew_molecule_p() const
61 Molecule* output = new Molecule;
62 Molecule*octmol = 0;
63 int lastoct = -100;
64 for (int i = 0; i < accs.size(); i++)
66 // do one octave
67 if (accs[i].octave_i_ != lastoct)
69 if (octmol)
71 Real dy =lastoct*7*paper()->internote_f ();
72 octmol->translate (dy, Y_AXIS);
73 output->add (*octmol);
74 delete octmol;
76 octmol= new Molecule;
78 lastoct = accs[i].octave_i_;
80 Real dy = (accs[i].name_i_ + c0_position) * paper()->internote_f ();
81 Atom a (paper()->lookup_l ()->accidental (accs[i].accidental_i_));
82 a.translate (dy, Y_AXIS);
83 Molecule m(a);
84 octmol->add_at_edge (X_AXIS, RIGHT, m);
87 if (octmol)
89 Real dy =lastoct*7*paper()->internote_f ();
90 octmol->translate (dy, Y_AXIS);
91 output->add (*octmol);
92 delete octmol;
95 Interval head_width=itemlist_width (support_items_);
96 output->translate (-output->extent().x ().right + head_width.left , X_AXIS);
98 return output;
102 Local_acc::compare (Local_acc&a, Local_acc&b)
104 if (a.octave_i_ - b.octave_i_)
105 return a.octave_i_ - b.octave_i_;
106 if (a.name_i_ - b.name_i_)
107 return a.name_i_ - b.name_i_;
109 return a.accidental_i_ - b.accidental_i_;
112 IMPLEMENT_IS_TYPE_B1(Local_key_item,Item);
114 void
115 Local_key_item::do_substitute_dependency (Score_elem*o,Score_elem*n)
117 Item* o_l = o->item();
118 Item* n_l = n?n->item():0;
120 support_items_.substitute (o_l, n_l);