]> git.donarmstrong.com Git - lilypond.git/blob - lily/key-reg.cc
release: 0.0.68pre
[lilypond.git] / lily / key-reg.cc
1 /*
2   key-reg.cc -- implement Key_register
3
4   source file of the GNU 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 "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     do_post_move_processing();
24 }
25
26 bool
27 Key_register::do_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     if (keyreq_l_)
34         return false;           // 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     int c0_i= *get_staff_info().c0_position_i_l_;       
45          Command_req * r_l = info.req_l_->command() ;
46     if (r_l && r_l->clefchange()) {
47
48          if (!kit_p_) {
49             kit_p_ = new Key_item(c0_i);
50             announce_element(Score_elem_info(kit_p_,0));
51          }
52          change_key_b_ = true;
53     }
54     
55     if (info.elem_l_->name() == Bar::static_name()) {
56         default_key_b_ = true;
57          if (!kit_p_) {
58             kit_p_ = new Key_item(c0_i);
59             announce_element(Score_elem_info(kit_p_,0));
60          }
61     }
62
63 }
64
65 void
66 Key_register::do_process_requests()
67 {
68     int c0_i= *get_staff_info().c0_position_i_l_;
69
70     if (key_.multi_octave_b_)
71         assert(false); // TODO . 
72     else if (keyreq_l_) {
73         kit_p_ = new Key_item(c0_i);
74         kit_p_->read(*this);
75         announce_element(Score_elem_info(kit_p_, keyreq_l_));
76     }
77 }
78
79 void
80 Key_register::do_pre_move_processing()
81
82     if (kit_p_) {
83         typeset_breakable_item( kit_p_);
84         kit_p_ = 0;
85     }
86 }
87
88
89     
90 void
91 Key_register::read_req(Key_change_req * r)
92 {
93     key_.multi_octave_b_ = r->multi_octave_b_;
94     accidental_idx_arr_.set_size(0);
95     for (int i = 0; i < r->melodic_p_arr_.size(); i ++) {
96         Melodic_req *  m_l =r->melodic_p_arr_[i];
97         int n_i =m_l->notename_i_;
98         int a_i = m_l->accidental_i_;
99         int o_i = m_l->octave_i_;
100         if (r->multi_octave_b_)
101             key_.set(o_i, n_i, a_i);
102         else
103             key_.set(n_i, a_i);
104         accidental_idx_arr_.push(n_i);
105     }
106 }
107
108 void
109 Key_register::do_post_move_processing()
110 {
111     keyreq_l_ = 0;
112     default_key_b_ = false;
113     kit_p_ = 0;
114     change_key_b_ = false;
115 }
116 IMPLEMENT_STATIC_NAME(Key_register);
117 IMPLEMENT_IS_TYPE_B1(Key_register,Request_register);
118 ADD_THIS_REGISTER(Key_register);