]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
release: 0.1.19
[lilypond.git] / lily / local-key-item.cc
1 /*
2   local-key-item.cc -- implement Local_key_item, Local_acc
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "dimen.hh"
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"
17
18
19
20 Local_key_item::Local_key_item (int i)
21 {
22   c0_position  = i;
23 }
24
25 void
26 Local_key_item::add_support (Item*head_l)
27 {
28   support_items_.push (head_l);
29   add_dependency (head_l);
30 }
31
32 void
33 Local_key_item::add (Melodic_req*m_l)
34 {
35   add (m_l->octave_i_, m_l->notename_i_, m_l->accidental_i_);
36 }
37
38 void
39 Local_key_item::add (int o, int p , int a)
40 {
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;
48   
49   accs.push (l);
50 }
51
52 void
53 Local_key_item::do_pre_processing()
54 {
55   accs.sort (Local_acc::compare);
56 }
57
58 Molecule*
59 Local_key_item::brew_molecule_p() const
60 {
61   Molecule*output = new Molecule;
62
63   Molecule *octave_mol_p = 0;
64   int lastoct = -100;
65   for  (int i = 0; i <  accs.size(); i++) 
66     {
67       // do one octave
68       if (accs[i].octave_i_ != lastoct) 
69         {
70           if (octave_mol_p)
71             {
72               Real dy =lastoct*7*paper()->internote_f ();
73               octave_mol_p->translate (dy, Y_AXIS);
74               output->add (*octave_mol_p);
75               delete octave_mol_p;
76             }
77           octave_mol_p= new Molecule;
78         }
79       lastoct = accs[i].octave_i_;
80       
81       Real dy = (accs[i].name_i_ + c0_position) * paper()->internote_f ();
82       Atom a (paper()->lookup_l ()->accidental (accs[i].accidental_i_));
83       a.dim_[X_AXIS] += 1 PT; // todo
84       a.translate (dy, Y_AXIS);
85       Molecule m(a);
86       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m);
87     }
88
89   if (octave_mol_p)
90     {
91       Real dy =lastoct*7*paper()->internote_f ();
92       octave_mol_p->translate (dy, Y_AXIS);
93       output->add (*octave_mol_p);
94       delete octave_mol_p;
95     }
96   
97  if (accs.size()) 
98     {
99       Box b(Interval (0, paper()->internote_f ()), Interval (0,0));
100       Molecule m (paper()->lookup_l ()->fill (b));
101       output->add_at_edge (X_AXIS, RIGHT, m);
102     }
103   Interval head_width=itemlist_width (support_items_);
104   output->translate (-output->extent().x ().right + head_width.left , X_AXIS);
105   
106   return output;
107 }
108
109 int
110 Local_acc::compare (Local_acc&a, Local_acc&b)
111 {
112   if (a.octave_i_ - b.octave_i_)
113     return a.octave_i_ - b.octave_i_;
114   if (a.name_i_ - b.name_i_)
115     return a.name_i_ - b.name_i_;
116   
117   return a.accidental_i_ - b.accidental_i_;
118 };
119
120 IMPLEMENT_IS_TYPE_B1(Local_key_item,Item);
121
122 void
123 Local_key_item::do_substitute_dependency (Score_elem*o,Score_elem*n)
124 {
125   Item* o_l = o->item();
126   Item* n_l = n?n->item():0;
127
128   support_items_.substitute (o_l, n_l);
129 }