2 local-key-engraver.cc -- implement Local_key_engraver
4 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 #include "musical-request.hh"
8 #include "command-request.hh"
9 #include "local-key-engraver.hh"
10 #include "local-key-item.hh"
11 #include "key-engraver.hh"
13 #include "key-item.hh"
15 #include "note-head.hh"
16 #include "timing-translator.hh"
17 #include "engraver-group-engraver.hh"
18 #include "grace-align-item.hh"
20 Local_key_engraver::Local_key_engraver()
28 Local_key_engraver::do_creation_processing ()
33 Breaks if Key_engraver is removed from under us.
36 daddy_grav_l()->get_simple_translator ("Key_engraver");
38 key_grav_l_ = dynamic_cast<Key_engraver *> (result);
42 warning (_ ("out of tune:"));
43 warning (_f ("Can't find: `%s'", "Key_engraver"));
47 local_key_ = key_grav_l_->key_;
52 (if we are grace) get key info from parent Local_key_engraver
57 Local_key_engraver::process_acknowledged ()
59 if (!key_item_p_ && mel_l_arr_.size())
61 SCM f = get_property ("forgetAccidentals",0);
62 bool forget = gh_boolean_p (f) && gh_scm2bool(f);
63 for (int i=0; i < mel_l_arr_.size(); i++)
65 Item * support_l = support_l_arr_[i];
66 Note_req * note_l = mel_l_arr_[i];
68 /* see if there's a tie that "changes" the accidental */
69 /* works because if there's a tie, the note to the left
70 is of the same pitch as the actual note */
71 bool tie_changes = tied_l_arr_.find_l (support_l)
72 && !local_key_.different_acc (note_l->pitch_);
76 && ((note_l->forceacc_b_
77 || !local_key_.different_acc (note_l->pitch_)
78 || local_key_.internal_forceacc (note_l->pitch_)))
84 key_item_p_ = new Local_key_item;
85 announce_element (Score_element_info (key_item_p_, 0));
88 key_item_p_->add_pitch (note_l->pitch_,
89 note_l->cautionary_b_,
90 local_key_.double_to_single_acc(note_l->pitch_));
91 key_item_p_->add_support (support_l);
96 local_key_.set (note_l->pitch_);
97 if (!tied_l_arr_.find_l (support_l))
99 local_key_.clear_internal_forceacc (note_l->pitch_);
101 else if (tie_changes)
103 local_key_.set_internal_forceacc (note_l->pitch_);
108 if (key_item_p_ && grace_align_l_)
110 grace_align_l_->add_support (key_item_p_);
117 Local_key_engraver::do_removal_processing ()
119 // TODO: signal accidentals to Local_key_engraver the
123 Local_key_engraver::do_pre_move_processing()
127 for (int i=0; i < support_l_arr_.size(); i++)
128 key_item_p_->add_support (support_l_arr_[i]);
130 typeset_element (key_item_p_);
137 support_l_arr_.clear();
138 forced_l_arr_.clear();
142 Local_key_engraver::acknowledge_element (Score_element_info info)
144 SCM wg= get_property ("weAreGraceContext", 0);
146 bool selfgr = gh_boolean_p (wg) &&gh_scm2bool (wg);
147 bool he_gr = info.elem_l_->get_elt_property ("grace") != SCM_UNDEFINED;
149 Grace_align_item * gai = dynamic_cast<Grace_align_item*> (info.elem_l_);
150 if (he_gr && !selfgr && gai)
152 grace_align_l_ = gai;
154 Note_req * note_l = dynamic_cast <Note_req *> (info.req_l_);
155 Note_head * note_head = dynamic_cast<Note_head *> (info.elem_l_);
162 if (note_l && note_head)
164 mel_l_arr_.push (note_l);
165 support_l_arr_.push (note_head);
167 else if (Tie * tie_l = dynamic_cast<Tie *> (info.elem_l_))
169 tied_l_arr_.push (tie_l->head (RIGHT));
174 Local_key_engraver::do_process_requests()
176 Translator * tr = daddy_grav_l()->get_simple_translator ("Timing_engraver"); // ugh
177 Timing_translator * time_C_ = dynamic_cast<Timing_translator*> (tr);
179 if (time_C_ && !time_C_->measure_position ())
181 SCM n = get_property ("noResetKey",0);
182 bool no_res = gh_boolean_p (n) && gh_scm2bool (n);
183 if (!no_res && key_grav_l_)
184 local_key_= key_grav_l_->key_;
186 else if (key_grav_l_ && key_grav_l_->key_changed_b ())
188 local_key_ = key_grav_l_->key_;
194 ADD_THIS_TRANSLATOR(Local_key_engraver);