]> git.donarmstrong.com Git - lilypond.git/blob - lily/voice-group-regs.cc
release: 0.0.52
[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_regs_l_.size(); i++) {      
37         if (voice_regs_l_[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_regs_l_.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 }
78
79 void
80 Voice_group_registers::post_move_processing()
81 {
82     if ( get_staff_info().time_C_ ->when_ > termination_mom_ ){
83         mtor << "Terminating voice_group\n";
84         daddy_reg_l_->terminate_register(this);
85     }
86     Register_group_register::post_move_processing();
87 }
88
89 Request_register *
90 Voice_group_registers::get_register_p(Request_register *reg_l)
91 {
92      if (reg_l->name() == Voice_registers::static_name()) {
93         for (int i=0; i <voice_regs_l_.size(); i++) {
94             if (reg_l == voice_regs_l_[i])
95                 voice_regs_l_.del(i);
96         }
97      }
98      return Register_group_register::get_register_p(reg_l);
99 }