]> git.donarmstrong.com Git - lilypond.git/blob - lily/local-key-grav.cc
release: 0.1.53
[lilypond.git] / lily / local-key-grav.cc
1 /*
2   local-key-reg.cc -- implement Local_key_engraver
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-grav.hh"
10 #include "local-key-item.hh"
11 #include "key-grav.hh"
12 #include "debug.hh"
13 #include "key-item.hh"
14 #include "tie.hh"
15 #include "note-head.hh"
16 #include "time-description.hh"
17 #include "engraver-group.hh"
18
19
20 Local_key_engraver::Local_key_engraver()
21 {
22   key_C_ = 0;
23 }
24
25 void
26 Local_key_engraver::do_creation_processing ()
27 {
28   Translator * result =
29     daddy_grav_l()->get_simple_translator (Key_engraver::static_name());
30
31   if (!result)
32     {
33       warning ("Out of tune! Can't find key engraver");
34     }
35   else
36     key_C_ = &((Key_engraver*)result->engraver_l ())->key_;
37 }
38
39 void
40 Local_key_engraver::do_pre_move_processing()
41 {
42   Local_key_item *key_item_p = 0;
43   if (mel_l_arr_.size()) 
44     {
45       for (int i=0; i  < mel_l_arr_.size(); i++) 
46         {
47           Item * support_l = support_l_arr_[i];
48           Note_req * note_l = mel_l_arr_[i];
49
50           if (tied_l_arr_.find_l (support_l) && 
51               !note_l->forceacc_b_)
52             continue;
53             
54           if (!note_l->forceacc_b_ &&
55               local_key_.oct (note_l->octave_i_).acc (note_l->notename_i_)
56               == note_l->accidental_i_) 
57             continue;
58           if (!key_item_p) 
59             {
60               int c0_i=0;
61
62               Staff_info inf = get_staff_info();
63               if (inf.c0_position_i_l_)
64                 c0_i = *get_staff_info().c0_position_i_l_;      
65                 
66               key_item_p = new Local_key_item (c0_i);
67
68             }
69           key_item_p->add (note_l);
70           key_item_p->add_support (support_l);
71           local_key_.oct (note_l->octave_i_)
72             .set (note_l->notename_i_, note_l->accidental_i_);
73         }
74         
75     }
76   if (key_item_p) 
77     {
78       for (int i=0; i < support_l_arr_.size(); i++)
79         key_item_p->add_support (support_l_arr_[i]);
80         
81       announce_element (Score_elem_info (key_item_p, 0)); // ugh ugh ugh
82       typeset_element (key_item_p);
83     }
84   
85   mel_l_arr_.clear();
86   tied_l_arr_.clear();
87   support_l_arr_.clear();
88   forced_l_arr_.clear();        
89 }
90
91 /*
92   whoah .. this looks hairy!
93  */
94 void
95 Local_key_engraver::acknowledge_element (Score_elem_info info)
96 {    
97   Score_elem * elem_l = info.elem_l_;
98   if (info.req_l_->musical() && info.req_l_->musical ()->note ()) 
99     {
100       Note_req * note_l = info.req_l_->musical()->note ();
101       Item * item_l = info.elem_l_->item();
102
103       mel_l_arr_.push (note_l);
104       support_l_arr_.push (item_l);
105     }
106   else if (info.req_l_->command()
107            && info.req_l_->command()->keychange ()) 
108     {
109       local_key_ = *key_C_;
110     }
111   else if (elem_l->is_type_b (Tie::static_name ())) 
112     {
113       Tie * tie_l = (Tie*)elem_l->spanner();
114       if (tie_l->same_pitch_b_)
115         tied_l_arr_.push (tie_l-> head_l_drul_[RIGHT]);
116     }
117 }
118
119 void
120 Local_key_engraver::do_process_requests()
121 {
122   Time_description const * time_C_ = get_staff_info().time_C_;
123   if (time_C_ && !time_C_->whole_in_measure_)
124     {
125       if (key_C_)
126         local_key_= *key_C_;
127     }
128 }
129
130
131 IMPLEMENT_IS_TYPE_B1(Local_key_engraver,Engraver);
132 ADD_THIS_TRANSLATOR(Local_key_engraver);