lilypond-1.3.8
[lilypond.git] / src / local-key-item.cc
blob425982120c0b839ffa42324bb59f2a614cf1361d
1 #include "local-key-item.hh"
2 #include "molecule.hh"
3 #include "scalar.hh"
4 #include "lookup.hh"
5 #include "paper-def.hh"
6 #include "musicalrequest.hh"
7 #include "notehead.hh"
8 #include "misc.hh"
12 Local_key_item::Local_key_item(int i)
14 c0_position = i;
17 void
18 Local_key_item::add(Item*head_l)
20 support_items_.push(head_l);
21 add_dependency(head_l);
24 void
25 Local_key_item::add(Melodic_req*m_l)
27 add(m_l->octave_i_, m_l->notename_i_, m_l->accidental_i_);
29 void
30 Local_key_item::add (int o, int p , int a)
32 Local_acc l;
33 l.octave = o;
34 l.name = p;
35 l.acc = a;
36 accs.push(l);
39 void
40 Local_key_item::do_pre_processing()
42 accs.sort(Local_acc::compare);
45 Molecule*
46 Local_key_item::brew_molecule_p()const
48 Molecule* output = new Molecule;
49 Molecule*octmol = 0;
50 int lastoct = -100;
51 for (int i = 0; i < accs.size(); i++) {
52 // do one octave
53 if (accs[i].octave != lastoct) {
54 if (octmol){
55 Real dy =lastoct*7*paper()->internote();
56 octmol->translate(Offset(0, dy));
57 output->add(*octmol);
58 delete octmol;
60 octmol= new Molecule;
62 lastoct = accs[i].octave;
63 Symbol s =paper()->lookup_p_->accidental(accs[i].acc);
64 Atom a(s);
65 Real dy = (accs[i].name + c0_position) * paper()->internote();
66 a.translate(Offset(0,dy));
68 octmol->add_right(a);
71 if (octmol){
72 Real dy =lastoct*7*paper()->internote();
73 octmol->translate(Offset(0, dy));
74 output->add(*octmol);
75 delete octmol;
78 Interval head_width=itemlist_width(support_items_);
79 output->translate(Offset(-output->extent().x.right + head_width.left ,0));
81 return output;
84 int
85 Local_acc::compare(Local_acc&a, Local_acc&b)
87 if (a.octave - b.octave)
88 return a.octave - b.octave;
89 if (a.name - b.name)
90 return a.name - b.name;
92 assert(false);