summaryrefslogtreecommitdiff
path: root/lily/local-key-reg.cc
blob: 6af18c1c8b4c5e5f347aa08bd1a5fbe73da254d9 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
  local-key-reg.cc -- implement Local_key_register

  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
*/

#include "musical-request.hh"
#include "command-request.hh"
#include "local-key-reg.hh"
#include "local-key-item.hh"
#include "complex-walker.hh"
#include "key-reg.hh"
#include "debug.hh"
#include "key-item.hh"

Local_key_register::Local_key_register()
{
    key_item_p_ = 0;
    key_C_ = 0;
}

void
Local_key_register::pre_move_processing()
{
    if (key_item_p_) {
	typeset_element(key_item_p_);
	key_item_p_ = 0;
    }
}
void
Local_key_register::acknowledge_element(Staff_elem_info info)
{    
    if (info.req_l_->note()) {
	Note_req * note_l_ = info.req_l_->note();

	if( note_l_->forceacc_b_ ||
	    local_key_.oct(note_l_->octave_i_).acc(note_l_->notename_i_)
	    != note_l_->accidental_i_) {
	    Item * support_l_ = info.elem_l_->item();
	

	    if (!key_item_p_) {
		key_item_p_ = new Local_key_item(*get_staff_info().c0_position_i_l_);
	    }
	    
	    key_item_p_->add(note_l_);
	    key_item_p_->add(support_l_);
	    local_key_.oct(note_l_->octave_i_)
		.set(note_l_->notename_i_, note_l_->accidental_i_);
	}
    } else if (info.elem_l_->name()==Key_item::static_name()) { 
	Key_register * key_reg_l =
	    (Key_register*)info.origin_reg_l_arr_[0];
	key_C_ = &key_reg_l->key_;
	local_key_ = *key_C_;
    }	
}

void
Local_key_register::process_requests()
{
    Time_description const * time_C_ = get_staff_info().time_C_;
    if (! time_C_->whole_in_measure_){
	if (key_C_)  
	    local_key_= *key_C_;
	else if( time_C_->when_ >Moment(0))
	    warning ("Help me! can't figure  current key");
    }
}
IMPLEMENT_STATIC_NAME(Local_key_register);
ADD_THIS_REGISTER(Local_key_register);