]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
release: 1.1.41
[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   Real note_distance = staff_line_leading_f ()/2;
55   Molecule *octave_mol_p = 0;
56   int lastoct = -100;
57   
58   for  (int i = 0; i <  accidental_arr_.size(); i++) 
59     {
60       Musical_pitch p (accidental_arr_[i].pitch_);
61       // do one octave
62       if (p.octave_i_ != lastoct) 
63         {
64           if (octave_mol_p)
65             {
66               Real dy =lastoct*7* note_distance;
67               octave_mol_p->translate_axis (dy, Y_AXIS);
68               output->add_molecule (*octave_mol_p);
69               delete octave_mol_p;
70             }
71           octave_mol_p= new Molecule;
72         }
73       
74       lastoct = p.octave_i_;
75       Real dy =
76         (c0_position_i_ + p.notename_i_)
77         * note_distance;
78       Molecule m (lookup_l ()->accidental (p.accidental_i_, 
79                                            accidental_arr_[i].cautionary_b_));
80
81       m.translate_axis (dy, Y_AXIS);
82       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
83     }
84
85   if (octave_mol_p)
86     {
87       Real dy =lastoct*7*note_distance;
88       octave_mol_p->translate_axis (dy, Y_AXIS);
89       output->add_molecule (*octave_mol_p);
90       delete octave_mol_p;
91     }
92   
93  if (accidental_arr_.size()) 
94     {
95       Box b(Interval (0, 0.6 * note_distance), Interval (0,0));
96       Molecule m (lookup_l ()->fill (b));
97       output->add_at_edge (X_AXIS, RIGHT, m, 0);
98     }
99
100   Interval x_int;
101   for (int i=0; i < support_items_.size(); i++) 
102     {
103       Dimension_cache *common = 
104         common_group (support_items_[i], X_AXIS);
105
106       Real x = support_items_[i]->relative_coordinate (common, X_AXIS)
107         - relative_coordinate (common, X_AXIS);
108
109       x_int.unite (x + support_items_[i]->extent (X_AXIS));
110     }
111
112   if (x_int.empty_b ())
113     x_int = Interval(0,0);
114   
115   output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS);
116   
117   return output;
118 }
119
120
121
122 void
123 Local_key_item::do_substitute_element_pointer (Score_element*o,Score_element*n)
124 {
125   if (Item* o_l = dynamic_cast <Item *> (o))
126     support_items_.substitute (o_l,dynamic_cast <Item *> (n));
127 }