]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-reg.cc
release: 0.0.53
[lilypond.git] / lily / local-key-reg.cc
1 /*
2   local-key-reg.cc -- implement Local_key_register
3
4   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
5 */
6
7 #include "musical-request.hh"
8 #include "command-request.hh"
9 #include "local-key-reg.hh"
10 #include "local-key-item.hh"
11 #include "complex-walker.hh"
12 #include "key-reg.hh"
13 #include "debug.hh"
14 #include "key-item.hh"
15
16 Local_key_register::Local_key_register()
17 {
18     key_item_p_ = 0;
19     key_C_ = 0;
20 }
21
22 void
23 Local_key_register::pre_move_processing()
24 {
25     if (key_item_p_) {
26         typeset_element(key_item_p_);
27         key_item_p_ = 0;
28     }
29 }
30
31 void
32 Local_key_register::acknowledge_element(Staff_elem_info info)
33 {    
34     if (info.req_l_->note()) {
35         Note_req * note_l_ = info.req_l_->note();
36
37         if( note_l_->forceacc_b_ ||
38             local_key_.oct(note_l_->octave_i_).acc(note_l_->notename_i_)
39             != note_l_->accidental_i_) {
40             Item * support_l_ = info.elem_l_->item();
41         
42
43             if (!key_item_p_) {
44                 key_item_p_ = new Local_key_item(*get_staff_info().c0_position_i_l_);
45             }
46             
47             key_item_p_->add(note_l_);
48             key_item_p_->add(support_l_);
49             local_key_.oct(note_l_->octave_i_)
50                 .set(note_l_->notename_i_, note_l_->accidental_i_);
51         }
52     } else if (info.req_l_->command()  && info.req_l_->command()->keychange()) { 
53         Key_register * key_reg_l =
54             (Key_register*)info.origin_reg_l_arr_[0];
55         key_C_ = &key_reg_l->key_;
56         local_key_ = *key_C_;
57     } else if (info.elem_l_->name() == Key_item::static_name()) {
58         Key_register * key_reg_l =
59             (Key_register*)info.origin_reg_l_arr_[0];
60         key_C_ = &key_reg_l->key_;
61     }
62 }
63
64 void
65 Local_key_register::process_requests()
66 {
67     Time_description const * time_C_ = get_staff_info().time_C_;
68     if (! time_C_->whole_in_measure_){
69         if (key_C_)
70             local_key_= *key_C_;
71         else if( time_C_->when_ >Moment(0))
72             warning ("Help me! can't figure  current key");
73     }
74 }
75
76 IMPLEMENT_STATIC_NAME(Local_key_register);
77 ADD_THIS_REGISTER(Local_key_register);