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