]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
564b66ea9a9d131f97bcb48d6d8c6cb0edba0dd0
[lilypond.git] / lily / local-key-item.cc
1 /*
2   local-key-item.cc -- implement Local_key_item, Musical_pitch
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "local-key-item.hh"
9 #include "molecule.hh"
10 #include "scalar.hh"
11 #include "lookup.hh"
12 #include "paper-def.hh"
13 #include "musical-request.hh"
14 #include "note-head.hh"
15 #include "misc.hh"
16
17 Local_key_item::Local_key_item ()
18 {
19   c0_position_i_  = 0;
20 }
21
22 void
23 Local_key_item::add_support (Item*head_l)
24 {
25   if (support_items_.find_l(head_l))
26     return ;
27   support_items_.push (head_l);
28   add_dependency (head_l);
29 }
30
31 void
32 Local_key_item::add (Musical_pitch p)
33 {
34   for (int i=0; i< accs.size(); i++)
35     if (!Musical_pitch::compare (p, accs[i]))
36       return;
37   
38   accs.push (p);
39 }
40
41 void
42 Local_key_item::do_pre_processing()
43 {
44   accs.sort (Musical_pitch::compare);
45 }
46
47 Molecule*
48 Local_key_item::brew_molecule_p() const
49 {
50   Molecule*output = new Molecule;
51
52   Molecule *octave_mol_p = 0;
53   int lastoct = -100;
54   for  (int i = 0; i <  accs.size(); i++) 
55     {
56       // do one octave
57       if (accs[i].octave_i_ != lastoct) 
58         {
59           if (octave_mol_p)
60             {
61               Real dy =lastoct*7*paper()->internote_f ();
62               octave_mol_p->translate_axis (dy, Y_AXIS);
63               output->add_molecule (*octave_mol_p);
64               delete octave_mol_p;
65             }
66           octave_mol_p= new Molecule;
67         }
68       lastoct = accs[i].octave_i_;
69       Real dy = (accs[i].notename_i_ + c0_position_i_) * paper()->internote_f ();
70       Atom a (lookup_l ()->accidental (accs[i].accidental_i_));
71
72       a.translate_axis (dy, Y_AXIS);
73       Molecule m(a);
74       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m);
75     }
76
77   if (octave_mol_p)
78     {
79       Real dy =lastoct*7*paper()->internote_f ();
80       octave_mol_p->translate_axis (dy, Y_AXIS);
81       output->add_molecule (*octave_mol_p);
82       delete octave_mol_p;
83     }
84   
85  if (accs.size()) 
86     {
87       Box b(Interval (0, paper()->internote_f ()), Interval (0,0));
88       Molecule m (lookup_l ()->fill (b));
89       output->add_at_edge (X_AXIS, RIGHT, m);
90     }
91
92   Interval x_int;
93   for (int i=0; i < support_items_.size(); i++) 
94     {
95       Graphical_axis_group *common = 
96         common_group (support_items_[i], X_AXIS);
97
98       Real x = support_items_[i]->relative_coordinate (common, X_AXIS)  
99         -relative_coordinate (common, X_AXIS);
100
101       x_int.unite (x + support_items_[i]->width());
102     }
103   if (x_int.empty_b ())
104     x_int = Interval(0,0);
105   
106   output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS);
107   
108   return output;
109 }
110
111 IMPLEMENT_IS_TYPE_B1(Local_key_item,Item);
112
113 void
114 Local_key_item::do_substitute_dependency (Score_element*o,Score_element*n)
115 {
116   Item* o_l = o->access_Item ();
117   Item* n_l = n?n->access_Item ():0;
118
119   support_items_.substitute (o_l, n_l);
120 }