lilypond-0.1.35
[lilypond.git] / lily / local-key-grav.cc
blob7201acf173020b1664d7e2f14ceb3d23a5f5e0bd
1 /*
2 local-key-reg.cc -- implement Local_key_engraver
4 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
5 */
7 #include "musical-request.hh"
8 #include "command-request.hh"
9 #include "local-key-grav.hh"
10 #include "local-key-item.hh"
11 #include "key-grav.hh"
12 #include "debug.hh"
13 #include "key-item.hh"
14 #include "tie.hh"
15 #include "note-head.hh"
16 #include "time-description.hh"
18 Local_key_engraver::Local_key_engraver()
20 key_C_ = 0;
23 void
24 Local_key_engraver::do_pre_move_processing()
26 Local_key_item *key_item_p = 0;
27 if (mel_l_arr_.size())
29 for (int i=0; i < mel_l_arr_.size(); i++)
31 Item * support_l = support_l_arr_[i];
32 Note_req * note_l = mel_l_arr_[i];
34 if (tied_l_arr_.find_l (support_l) &&
35 !note_l->forceacc_b_)
36 continue;
38 if (!note_l->forceacc_b_ &&
39 local_key_.oct (note_l->octave_i_).acc (note_l->notename_i_)
40 == note_l->accidental_i_)
41 continue;
42 if (!key_item_p)
44 int c0_i=0;
46 Staff_info inf = get_staff_info();
47 if (inf.c0_position_i_l_)
48 c0_i = *get_staff_info().c0_position_i_l_;
50 key_item_p = new Local_key_item (c0_i);
52 key_item_p->add (note_l);
53 key_item_p->add_support (support_l);
54 local_key_.oct (note_l->octave_i_)
55 .set (note_l->notename_i_, note_l->accidental_i_);
59 if (key_item_p)
61 for (int i=0; i < support_l_arr_.size(); i++)
62 key_item_p->add_support (support_l_arr_[i]);
64 announce_element (Score_elem_info (key_item_p, 0)); // ugh ugh ugh
65 typeset_element (key_item_p);
68 mel_l_arr_.clear();
69 tied_l_arr_.clear();
70 support_l_arr_.clear();
71 forced_l_arr_.clear();
75 whoah .. this looks hairy!
77 void
78 Local_key_engraver::acknowledge_element (Score_elem_info info)
80 Score_elem * elem_l = info.elem_l_;
81 if (info.req_l_->musical() && info.req_l_->musical ()->note ())
83 Note_req * note_l = info.req_l_->musical()->note ();
84 Item * item_l = info.elem_l_->item();
86 mel_l_arr_.push (note_l);
87 support_l_arr_.push (item_l);
90 else if (info.req_l_->command()
91 && info.req_l_->command()->keychange ())
93 Key_engraver * key_grav_l =
94 (Key_engraver*)info.origin_grav_l_arr_[0];
95 key_C_ = &key_grav_l->key_;
96 local_key_ = *key_C_;
98 else if (elem_l->is_type_b (Key_item::static_name ()))
100 Key_engraver * key_grav_l =
101 (Key_engraver*)info.origin_grav_l_arr_[0];
102 key_C_ = &key_grav_l->key_;
104 else if (elem_l->is_type_b (Tie::static_name ()))
106 Tie * tie_l = (Tie*)elem_l->spanner();
107 if (tie_l->same_pitch_b_)
108 tied_l_arr_.push (tie_l-> head_l_drul_[RIGHT]);
112 void
113 Local_key_engraver::do_process_requests()
115 Time_description const * time_C_ = get_staff_info().time_C_;
116 if (time_C_ && !time_C_->whole_in_measure_)
118 if (key_C_)
119 local_key_= *key_C_;
124 IMPLEMENT_IS_TYPE_B1(Local_key_engraver,Engraver);
125 ADD_THIS_TRANSLATOR(Local_key_engraver);