lilypond-1.0.8
[lilypond.git] / src / keyreg.cc
blob197a8f6b319a994aac915c7c606da90ae3a2dc01
1 /*
2 keyreg.cc -- implement Key_register
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
8 todo: key undo
12 #include "keyreg.hh"
13 #include "keyitem.hh"
14 #include "complexwalker.hh"
15 #include "commandrequest.hh"
16 #include "staffcolumn.hh"
17 #include "localkeyreg.hh"
18 #include "musicalrequest.hh"
20 Key_register::Key_register(Complex_walker*w)
21 : Request_register(w)
23 do_post_move_process();
27 bool
28 Key_register::try_request(Request * req_l)
30 if (!req_l->command()->keychange())
31 return false;
32 assert(!keyreq_l_); // todo
33 keyreq_l_ = req_l->command()->keychange();
34 read_req(keyreq_l_);
35 return true;
38 void
39 Key_register::acknowledge_element(Staff_elem_info info)
41 Command_req * r_l = info.req_l_->command() ;
42 if (r_l && r_l->clefchange() && !kit_p_) {
43 kit_p_ = new Key_item(walk_l_->c0_position_i());
44 kit_p_->read(*this);
45 announce_element(Staff_elem_info(kit_p_, keyreq_l_, this));
49 void
50 Key_register::process_request()
52 Time_description *time_l = &walk_l_->time_;
54 if (!keyreq_l_ &&
55 (!time_l->whole_in_measure_|| !time_l->when_)) {
56 default_key_b_ = true;
59 if ( default_key_b_ || keyreq_l_) {
60 kit_p_ = new Key_item(walk_l_->c0_position_i());
61 kit_p_->read(*this);
62 announce_element(Staff_elem_info(kit_p_, keyreq_l_, this));
66 void
67 Key_register::do_pre_move_process()
69 if (kit_p_) {
70 if (default_key_b_)
71 typeset_breakable_item(0,0,kit_p_);
72 else
73 typeset_breakable_item(
74 new Key_item(*kit_p_), kit_p_, new Key_item(*kit_p_));
75 kit_p_ = 0;
81 void
82 Key_register::read_req(Key_change_req * r)
84 accidental_idx_arr_.set_size(0);
85 for (int i = 0; i < r->melodic_p_arr_.size(); i ++) {
86 int n_i=r->melodic_p_arr_[i]->notename_i_;
87 key_.set(n_i, r->melodic_p_arr_[i]->accidental_i_);
88 accidental_idx_arr_.push(n_i);
92 void
93 Key_register::do_post_move_process()
95 keyreq_l_ = 0;
96 default_key_b_ = false;
97 kit_p_ = 0;