2 local-key-item.cc -- implement Local_key_item, Musical_pitch
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 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_pitch (Musical_pitch p, bool cautionary)
34 for (int i=0; i< accidental_arr_.size(); i++)
35 if (!Musical_pitch::compare (p, accidental_arr_[i].pitch_))
38 Local_key_cautionary_tuple t;
40 t.cautionary_b_ = cautionary;
41 accidental_arr_.push (t);
45 Local_key_item::do_pre_processing()
47 accidental_arr_.sort (Local_key_cautionary_tuple::compare);
51 Local_key_item::do_brew_molecule_p() const
53 Molecule*output = new Molecule;
55 Molecule *octave_mol_p = 0;
57 for (int i = 0; i < accidental_arr_.size(); i++)
59 Musical_pitch p (accidental_arr_[i].pitch_);
61 if (p.octave_i_ != lastoct)
65 Real dy =lastoct*7*paper()->internote_f ();
66 octave_mol_p->translate_axis (dy, Y_AXIS);
67 output->add_molecule (*octave_mol_p);
70 octave_mol_p= new Molecule;
73 lastoct = p.octave_i_;
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_));
80 m.translate_axis (dy, Y_AXIS);
81 octave_mol_p->add_at_edge (X_AXIS, RIGHT, m, 0);
86 Real dy =lastoct*7*paper()->internote_f ();
87 octave_mol_p->translate_axis (dy, Y_AXIS);
88 output->add_molecule (*octave_mol_p);
92 if (accidental_arr_.size())
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);
100 for (int i=0; i < support_items_.size(); i++)
102 Dimension_cache *common =
103 common_group (support_items_[i], X_AXIS);
105 Real x = support_items_[i]->relative_coordinate (common, X_AXIS)
106 - relative_coordinate (common, X_AXIS);
108 x_int.unite (x + support_items_[i]->extent (X_AXIS));
110 if (x_int.empty_b ())
111 x_int = Interval(0,0);
113 output->translate_axis (-output->extent()[X_AXIS][RIGHT] + x_int[LEFT], X_AXIS);
121 Local_key_item::do_substitute_element_pointer (Score_element*o,Score_element*n)
123 if (Item* o_l = dynamic_cast <Item *> (o))
124 support_items_.substitute (o_l,dynamic_cast <Item *> (n));