]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-reg.cc
release: 0.0.53
[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 #include "time-description.hh"
20
21 Key_register::Key_register()
22 {
23     post_move_processing();
24 }
25
26 bool
27 Key_register::try_request(Request * req_l)
28 {
29     Command_req* creq_l= req_l->command();
30     if (!creq_l|| !creq_l->keychange())
31         return false;
32      
33     assert(!keyreq_l_);         // todo
34     keyreq_l_ = creq_l->keychange();
35     change_key_b_ = true;
36     read_req(keyreq_l_);
37     return true;
38 }
39
40 void
41 Key_register::acknowledge_element(Staff_elem_info info)
42 {
43     Command_req * r_l = info.req_l_->command() ;
44     if (r_l && r_l->clefchange()) {
45         change_key_b_ = true;
46     }
47     
48     if (info.elem_l_->name() == Bar::static_name()) 
49         default_key_b_ = true;
50
51 }
52
53 void
54 Key_register::process_requests()
55 {
56     int c0_i= *get_staff_info().c0_position_i_l_;
57
58     if (key_.multi_octave_b_)
59         assert(false); // TODO . 
60     else 
61         kit_p_ = new Key_item(c0_i);
62     kit_p_->read(*this);
63     announce_element(Staff_elem_info(kit_p_, keyreq_l_));
64 }
65
66 void
67 Key_register::pre_move_processing()
68
69     Time_description const * time_C_ = get_staff_info().time_C_;
70     if ( time_C_->whole_in_measure_&& default_key_b_ && ! change_key_b_ ) {
71         delete kit_p_ ;
72         kit_p_ =0;
73     }
74     
75     if (kit_p_) {
76         if (change_key_b_) 
77             typeset_breakable_item(
78                 new Key_item(*kit_p_), kit_p_, new Key_item(*kit_p_));
79         else 
80             typeset_breakable_item(0,0,kit_p_);
81         kit_p_ = 0;
82     }
83 }
84
85
86     
87 void
88 Key_register::read_req(Key_change_req * r)
89 {
90     key_.multi_octave_b_ = r->multi_octave_b_;
91     accidental_idx_arr_.set_size(0);
92     for (int i = 0; i < r->melodic_p_arr_.size(); i ++) {
93         Melodic_req *  m_l =r->melodic_p_arr_[i];
94         int n_i =m_l->notename_i_;
95         int a_i = m_l->accidental_i_;
96         int o_i = m_l->octave_i_;
97         if (r->multi_octave_b_)
98             key_.set(o_i, n_i, a_i);
99         else
100             key_.set(n_i, a_i);
101         accidental_idx_arr_.push(n_i);
102     }
103 }
104
105 void
106 Key_register::post_move_processing()
107 {
108     keyreq_l_ = 0;
109     default_key_b_ = false;
110     kit_p_ = 0;
111     change_key_b_ = false;
112 }
113 IMPLEMENT_STATIC_NAME(Key_register);
114 ADD_THIS_REGISTER(Key_register);