]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-item.cc
release: 1.1.0
[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< accidental_pitch_arr_.size(); i++)
35     if (!Musical_pitch::compare (p, accidental_pitch_arr_[i]))
36       return;
37   
38   accidental_pitch_arr_.push (p);
39 }
40
41 void
42 Local_key_item::do_pre_processing()
43 {
44   accidental_pitch_arr_.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 <  accidental_pitch_arr_.size(); i++) 
55     {
56       // do one octave
57       if (accidental_pitch_arr_[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       
69       lastoct = accidental_pitch_arr_[i].octave_i_;
70       Real dy =
71         (c0_position_i_ + accidental_pitch_arr_[i].notename_i_)
72         * paper()->internote_f ();
73       Atom a (lookup_l ()->accidental (accidental_pitch_arr_[i].accidental_i_));
74
75       a.translate_axis (dy, Y_AXIS);
76       Molecule m(a);
77       octave_mol_p->add_at_edge (X_AXIS, RIGHT, m);
78     }
79
80   if (octave_mol_p)
81     {
82       Real dy =lastoct*7*paper()->internote_f ();
83       octave_mol_p->translate_axis (dy, Y_AXIS);
84       output->add_molecule (*octave_mol_p);
85       delete octave_mol_p;
86     }
87   
88  if (accidental_pitch_arr_.size()) 
89     {
90       Box b(Interval (0, paper()->internote_f ()), Interval (0,0));
91       Molecule m (lookup_l ()->fill (b));
92       output->add_at_edge (X_AXIS, RIGHT, m);
93     }
94
95   Interval x_int;
96   for (int i=0; i < support_items_.size(); i++) 
97     {
98       Graphical_axis_group *common = 
99         common_group (support_items_[i], X_AXIS);
100
101       Real x = support_items_[i]->relative_coordinate (common, X_AXIS)  
102         -relative_coordinate (common, X_AXIS);
103
104       x_int.unite (x + support_items_[i]->width());
105     }
106   if (x_int.empty_b ())
107     x_int = Interval(0,0);
108   
109   output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS);
110   
111   return output;
112 }
113
114 IMPLEMENT_IS_TYPE_B1(Local_key_item,Item);
115
116 void
117 Local_key_item::do_substitute_dependency (Score_element*o,Score_element*n)
118 {
119   Item* o_l = dynamic_cast <Item *> (o);
120   Item* n_l = n?dynamic_cast <Item *> (n):0;
121
122   support_items_.substitute (o_l, n_l);
123 }