]> git.donarmstrong.com Git - lilypond.git/blob - lily/voice-group-regs.cc
release: 0.0.57
[lilypond.git] / lily / voice-group-regs.cc
1 /*
2   voicegroup.cc -- implement Voice_group_registers
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "voice.hh"
9 #include "proto.hh"
10 #include "plist.hh"
11 #include "musical-request.hh"
12 #include "voice-regs.hh"
13 #include "voice-group-regs.hh"
14 #include "register.hh"
15 #include "complex-walker.hh"
16 #include "command-request.hh"
17 #include "debug.hh"
18 #include "input-register.hh"
19
20 static int temp_id_count;
21
22 Voice_group_registers::Voice_group_registers(String id,
23                                              Input_register const *ireg_C)
24 {
25     ireg_C_ =ireg_C;
26     Register_group_register::add(ireg_C->get_nongroup_p_arr());
27     if (id=="")                 // ugh
28         id = __FUNCTION__ + String(temp_id_count++);
29     group_id_str_ = id;
30     termination_mom_ = 0; 
31 }
32
33 bool
34 Voice_group_registers::try_request(Request*r_l)
35 {
36     for (int i=0; i < voice_reg_l_arr_.size(); i++) {   
37         if (voice_reg_l_arr_[i]->voice_l_ == r_l->voice_l())
38             goto gotcha;        // yeah, yeah, I know
39     }
40     return false;
41 gotcha:
42     Command_req* c_l = r_l->command();
43     if (c_l&& c_l->groupfeature()) {
44         Feature f;
45         f.type_ = c_l->groupfeature()->type_str_;
46         f.value_ = c_l->groupfeature()->value_str_;
47         set_feature(f);
48         return true;
49     }
50     return Register_group_register::try_request(r_l);
51 }
52
53
54 IMPLEMENT_STATIC_NAME(Voice_group_registers);
55
56 void
57 Voice_group_registers::do_print() const
58 {
59 #ifndef NPRINT
60     mtor << "ID: " << group_id_str_<<"\n";
61     mtor << "stopping at " << termination_mom_ << "\n";
62     Register_group_register::do_print();
63 #endif
64 }
65 void
66 Voice_group_registers::add(Request_register*r_l)
67 {
68     Register_group_register::add(r_l);
69     if (r_l->name() == Voice_registers::static_name()) {
70         Voice_registers * vregs_l = (Voice_registers*)r_l;
71         voice_reg_l_arr_.push( vregs_l );
72         Voice *v_l = vregs_l->voice_l_;
73         termination_mom_ = termination_mom_ >? v_l -> last();
74         mtor << "adding Voice_registers, now terminating at " << 
75             termination_mom_<< "\n";
76     }
77     OK();
78 }
79
80 void
81 Voice_group_registers::post_move_processing()
82 {
83     if ( get_staff_info().time_C_ ->when_ > termination_mom_ ){
84         mtor << "Terminating voice_group\n";
85         daddy_reg_l_->terminate_register(this);
86         return ;
87     }
88     Register_group_register::post_move_processing();
89 }
90
91 Request_register *
92 Voice_group_registers::get_register_p(Request_register *reg_l)
93 {
94      if (reg_l->name() == Voice_registers::static_name()) {
95         for (int i=0; i <voice_reg_l_arr_.size(); i++) {
96             if (reg_l == voice_reg_l_arr_[i])
97                 voice_reg_l_arr_.del(i);
98         }
99      }
100      Request_register*reg_p =Register_group_register::get_register_p(reg_l);
101      OK();
102
103      return reg_p;
104 }
105
106 void
107 Voice_group_registers::OK() const
108 {
109     for (int i=0; i < voice_reg_l_arr_.size(); i++) {
110         iter(reg_list_.find(voice_reg_l_arr_[i]), j);
111         assert(j.ok());
112     }
113 }
114              
115