lilypond-1.3.145
[lilypond.git] / lily / key-reg.cc
blob70dea983e99e528f5e61c6a786c12dfd1fd8a5bd
1 /*
2 key-reg.cc -- implement Key_register
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 Todo: key undo, special keys.
12 #include "key-reg.hh"
13 #include "key-item.hh"
14 #include "command-request.hh"
15 #include "local-key-reg.hh"
16 #include "musical-request.hh"
17 #include "local-key-item.hh"
18 #include "bar.hh"
19 #include "time-description.hh"
21 Key_register::Key_register()
23 kit_p_ = 0;
24 do_post_move_processing();
27 void
28 Key_register::create_key()
30 if (!kit_p_) {
31 int c0_i= *get_staff_info().c0_position_i_l_;
33 kit_p_ = new Key_item(c0_i);
34 announce_element(Score_elem_info(kit_p_,keyreq_l_));
35 kit_p_->read(*this);
39 bool
40 Key_register::do_try_request(Request * req_l)
42 Command_req* creq_l= req_l->command();
43 if (!creq_l|| !creq_l->keychange())
44 return false;
46 if (keyreq_l_)
47 return false; // TODO
48 keyreq_l_ = creq_l->keychange();
49 read_req(keyreq_l_);
50 return true;
53 void
54 Key_register::acknowledge_element(Score_elem_info info)
56 Command_req * r_l = info.req_l_->command() ;
57 if (r_l && r_l->clefchange()) {
58 create_key();
59 } else if (info.elem_l_->name() == Bar::static_name()) {
60 if ( !keyreq_l_)
61 default_key_b_ = true;
62 create_key();
67 void
68 Key_register::do_process_requests()
70 if (key_.multi_octave_b_)
71 assert(false); // TODO .
72 else if (keyreq_l_) {
73 create_key();
77 void
78 Key_register::do_pre_move_processing()
80 if (kit_p_) {
81 kit_p_->default_b_ = default_key_b_;
82 typeset_breakable_item( kit_p_);
83 kit_p_ = 0;
89 void
90 Key_register::read_req(Key_change_req * r)
92 key_.multi_octave_b_ = r->multi_octave_b_;
93 accidental_idx_arr_.set_size(0);
94 for (int i = 0; i < r->melodic_p_arr_.size(); i ++) {
95 Melodic_req * m_l =r->melodic_p_arr_[i];
96 int n_i =m_l->notename_i_;
97 int a_i = m_l->accidental_i_;
98 int o_i = m_l->octave_i_;
99 if (r->multi_octave_b_)
100 key_.set(o_i, n_i, a_i);
101 else
102 key_.set(n_i, a_i);
103 accidental_idx_arr_.push(n_i);
107 void
108 Key_register::do_post_move_processing()
110 keyreq_l_ = 0;
111 default_key_b_ = false;
114 IMPLEMENT_STATIC_NAME(Key_register);
115 IMPLEMENT_IS_TYPE_B1(Key_register,Request_register);
116 ADD_THIS_REGISTER(Key_register);