2 local-key-item.cc -- implement Local_key_item, Musical_pitch
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 #include "local-key-item.hh"
12 #include "paper-def.hh"
13 #include "musical-request.hh"
14 #include "note-head.hh"
17 Local_key_item::Local_key_item ()
23 Local_key_item::add_support (Item*head_l)
25 if (support_items_.find_l(head_l))
27 support_items_.push (head_l);
28 add_dependency (head_l);
32 Local_key_item::add (Musical_pitch p)
34 for (int i=0; i< accidental_pitch_arr_.size(); i++)
35 if (!Musical_pitch::compare (p, accidental_pitch_arr_[i]))
38 accidental_pitch_arr_.push (p);
42 Local_key_item::do_pre_processing()
44 accidental_pitch_arr_.sort (Musical_pitch::compare);
48 Local_key_item::do_brew_molecule_p() const
50 Molecule*output = new Molecule;
52 Molecule *octave_mol_p = 0;
54 for (int i = 0; i < accidental_pitch_arr_.size(); i++)
57 if (accidental_pitch_arr_[i].octave_i_ != lastoct)
61 Real dy =lastoct*7*paper()->internote_f ();
62 octave_mol_p->translate_axis (dy, Y_AXIS);
63 output->add_molecule (*octave_mol_p);
66 octave_mol_p= new Molecule;
69 lastoct = accidental_pitch_arr_[i].octave_i_;
71 (c0_position_i_ + accidental_pitch_arr_[i].notename_i_)
72 * paper()->internote_f ();
73 Molecule m (lookup_l ()->accidental (accidental_pitch_arr_[i].accidental_i_,
74 accidental_pitch_arr_[i].cautionary_b_));
76 m.translate_axis (dy, Y_AXIS);
77 octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
82 Real dy =lastoct*7*paper()->internote_f ();
83 octave_mol_p->translate_axis (dy, Y_AXIS);
84 output->add_molecule (*octave_mol_p);
88 if (accidental_pitch_arr_.size())
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, 0);
96 for (int i=0; i < support_items_.size(); i++)
98 Dimension_cache *common =
99 common_group (support_items_[i], X_AXIS);
101 Real x = support_items_[i]->relative_coordinate (common, X_AXIS)
102 - relative_coordinate (common, X_AXIS);
104 x_int.unite (x + support_items_[i]->extent (X_AXIS));
106 if (x_int.empty_b ())
107 x_int = Interval(0,0);
109 output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS);
117 Local_key_item::do_substitute_dependency (Score_element*o,Score_element*n)
119 Item* o_l = dynamic_cast <Item *> (o);
120 Item* n_l = n?dynamic_cast <Item *> (n):0;
122 support_items_.substitute (o_l, n_l);