lilypond-1.3.80
[lilypond.git] / lily / local-key-grav.cc
blob8e492b621aea8f38ba7edc70cc25408829004ad2
1 /*
2 local-key-reg.cc -- implement Local_key_engraver
4 (c) 1997--1998 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"
17 #include "engraver-group.hh"
20 Local_key_engraver::Local_key_engraver()
22 key_C_ = 0;
23 key_item_p_ =0;
26 void
27 Local_key_engraver::do_creation_processing ()
29 Translator * result =
30 daddy_grav_l()->get_simple_translator (Key_engraver::static_name());
32 if (!result)
34 warning ("Out of tune! Can't find key engraver");
36 else
38 key_C_ = &((Key_engraver*)result->engraver_l ())->key_;
39 local_key_ = *key_C_;
43 void
44 Local_key_engraver::process_acknowledged ()
46 if (!key_item_p_ && mel_l_arr_.size())
48 for (int i=0; i < mel_l_arr_.size(); i++)
50 Item * support_l = support_l_arr_[i];
51 Note_req * note_l = mel_l_arr_[i];
53 if (tied_l_arr_.find_l (support_l) &&
54 !note_l->forceacc_b_)
55 continue;
57 if (!note_l->forceacc_b_
58 && local_key_.different_acc (note_l->pitch_))
59 continue;
60 if (!key_item_p_)
62 int c0_i=0;
64 Staff_info inf = get_staff_info();
65 if (inf.c0_position_i_l_)
66 c0_i = *get_staff_info().c0_position_i_l_;
68 key_item_p_ = new Local_key_item (c0_i);
69 announce_element (Score_elem_info (key_item_p_, 0));
71 key_item_p_->add (note_l->pitch_);
72 key_item_p_->add_support (support_l);
73 local_key_.set (note_l->pitch_);
79 void
80 Local_key_engraver::do_pre_move_processing()
82 if (key_item_p_)
84 for (int i=0; i < support_l_arr_.size(); i++)
85 key_item_p_->add_support (support_l_arr_[i]);
87 typeset_element (key_item_p_);
88 key_item_p_ =0;
91 mel_l_arr_.clear();
92 tied_l_arr_.clear();
93 support_l_arr_.clear();
94 forced_l_arr_.clear();
97 void
98 Local_key_engraver::acknowledge_element (Score_elem_info info)
100 Score_elem * elem_l = info.elem_l_;
101 if (info.req_l_->musical() && info.req_l_->musical ()->note ())
103 Note_req * note_l = info.req_l_->musical()->note ();
104 Item * item_l = info.elem_l_->item();
106 mel_l_arr_.push (note_l);
107 support_l_arr_.push (item_l);
109 else if (info.req_l_->command()
110 && info.req_l_->command()->keychange () && key_C_)
112 local_key_ = *key_C_;
114 else if (elem_l->is_type_b (Tie::static_name ()))
116 Tie * tie_l = (Tie*)elem_l->spanner();
117 if (tie_l->same_pitch_b_)
118 tied_l_arr_.push (tie_l-> head_l_drul_[RIGHT]);
122 void
123 Local_key_engraver::do_process_requests()
125 Time_description const * time_C_ = get_staff_info().time_C_;
126 if (time_C_ && !time_C_->whole_in_measure_)
128 if (key_C_)
129 local_key_= *key_C_;
134 IMPLEMENT_IS_TYPE_B1(Local_key_engraver,Engraver);
135 ADD_THIS_TRANSLATOR(Local_key_engraver);