]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-reg.cc
release: 0.0.50
[lilypond.git] / lily / key-reg.cc
1 /*
2   key-reg.cc -- implement Key_register
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7
8   todo: key undo
9   
10   */
11 #include "key-reg.hh"
12 #include "key-item.hh"
13 #include "command-request.hh"
14 #include "staff-column.hh"
15 #include "local-key-reg.hh"
16 #include "musical-request.hh"
17 #include "local-key-item.hh"
18 #include "bar.hh"
19
20 Key_register::Key_register()
21 {
22     post_move_processing();
23 }
24
25 bool
26 Key_register::try_request(Request * req_l)
27 {
28     Command_req* creq_l= req_l->command();
29     if (!creq_l|| !creq_l->keychange())
30         return false;
31      
32     assert(!keyreq_l_);         // todo
33     keyreq_l_ = creq_l->keychange();
34     change_key_b_ = true;
35     read_req(keyreq_l_);
36     return true;
37 }
38
39 void
40 Key_register::acknowledge_element(Staff_elem_info info)
41 {
42     Command_req * r_l = info.req_l_->command() ;
43     if (r_l && r_l->clefchange()) {
44         change_key_b_ = true;
45     }
46     
47     if (info.elem_l_->name() == Bar::static_name()) 
48         default_key_b_ = true;
49
50 }
51
52 void
53 Key_register::process_requests()
54 {
55     int c0_i= *get_staff_info().c0_position_i_l_;
56
57     if (key_.multi_octave_b_)
58         assert(false); // TODO . 
59     else 
60         kit_p_ = new Key_item(c0_i);
61     kit_p_->read(*this);
62     announce_element(Staff_elem_info(kit_p_, keyreq_l_));
63 }
64
65 void
66 Key_register::pre_move_processing()
67
68
69     if (! default_key_b_ && ! change_key_b_ ) {
70         delete kit_p_ ;
71         kit_p_ =0;
72     }
73     
74     if (kit_p_) {
75         if (change_key_b_) 
76             typeset_breakable_item(
77                 new Key_item(*kit_p_), kit_p_, new Key_item(*kit_p_));
78         else 
79             typeset_breakable_item(0,0,kit_p_);
80         kit_p_ = 0;
81     }
82 }
83
84
85     
86 void
87 Key_register::read_req(Key_change_req * r)
88 {
89     key_.multi_octave_b_ = r->multi_octave_b_;
90     accidental_idx_arr_.set_size(0);
91     for (int i = 0; i < r->melodic_p_arr_.size(); i ++) {
92         Melodic_req *  m_l =r->melodic_p_arr_[i];
93         int n_i=m_l->notename_i_;
94         int a_i = m_l->accidental_i_;
95         int o_i = m_l->octave_i_;
96         if (r->multi_octave_b_)
97             key_.set(o_i, n_i, a_i);
98         else
99             key_.set(n_i, a_i);
100         accidental_idx_arr_.push(n_i);
101     }
102 }
103
104 void
105 Key_register::post_move_processing()
106 {
107     keyreq_l_ = 0;
108     default_key_b_ = false;
109     kit_p_ = 0;
110     change_key_b_ = false;
111 }
112 IMPLEMENT_STATIC_NAME(Key_register);
113 ADD_THIS_REGISTER(Key_register);