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