]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
release: 1.1.33
[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--1999 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_pitch (Musical_pitch p, bool cautionary)
33 {
34   for (int i=0; i< accidental_arr_.size(); i++)
35     if (!Musical_pitch::compare (p, accidental_arr_[i].pitch_))
36       return;
37
38   Local_key_cautionary_tuple t;
39   t.pitch_ = p;
40   t.cautionary_b_ = cautionary;
41   accidental_arr_.push (t);
42 }
43
44 void
45 Local_key_item::do_pre_processing()
46 {
47   accidental_arr_.sort (Local_key_cautionary_tuple::compare);
48 }
49
50 Molecule*
51 Local_key_item::do_brew_molecule_p() const
52 {
53   Molecule*output = new Molecule;
54
55   Molecule *octave_mol_p = 0;
56   int lastoct = -100;
57   for  (int i = 0; i <  accidental_arr_.size(); i++) 
58     {
59       Musical_pitch p (accidental_arr_[i].pitch_);
60       // do one octave
61       if (p.octave_i_ != lastoct) 
62         {
63           if (octave_mol_p)
64             {
65               Real dy =lastoct*7*paper()->internote_f ();
66               octave_mol_p->translate_axis (dy, Y_AXIS);
67               output->add_molecule (*octave_mol_p);
68               delete octave_mol_p;
69             }
70           octave_mol_p= new Molecule;
71         }
72       
73       lastoct = p.octave_i_;
74       Real dy =
75         (c0_position_i_ + p.notename_i_)
76         * paper()->internote_f ();
77       Molecule m (lookup_l ()->accidental (p.accidental_i_, 
78                                            accidental_arr_[i].cautionary_b_));
79
80       m.translate_axis (dy, Y_AXIS);
81       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
82     }
83
84   if (octave_mol_p)
85     {
86       Real dy =lastoct*7*paper()->internote_f ();
87       octave_mol_p->translate_axis (dy, Y_AXIS);
88       output->add_molecule (*octave_mol_p);
89       delete octave_mol_p;
90     }
91   
92  if (accidental_arr_.size()) 
93     {
94       Box b(Interval (0, paper()->internote_f ()), Interval (0,0));
95       Molecule m (lookup_l ()->fill (b));
96       output->add_at_edge (X_AXIS, RIGHT, m, 0);
97     }
98
99   Interval x_int;
100   for (int i=0; i < support_items_.size(); i++) 
101     {
102       Dimension_cache *common = 
103         common_group (support_items_[i], X_AXIS);
104
105       Real x = support_items_[i]->relative_coordinate (common, X_AXIS)
106         - relative_coordinate (common, X_AXIS);
107
108       x_int.unite (x + support_items_[i]->extent (X_AXIS));
109     }
110   if (x_int.empty_b ())
111     x_int = Interval(0,0);
112   
113   output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS);
114   
115   return output;
116 }
117
118
119
120 void
121 Local_key_item::do_substitute_element_pointer (Score_element*o,Score_element*n)
122 {
123   if (Item* o_l = dynamic_cast <Item *> (o))
124     support_items_.substitute (o_l,dynamic_cast <Item *> (n));
125 }