]> git.donarmstrong.com Git - lilypond.git/blob - lily/voice-group-regs.cc
release: 0.0.46.jcn1
[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;
39     }
40     return false;
41 gotcha:
42     Command_req* c_l = r_l->command();
43     if (c_l&& c_l->groupfeature()) {
44         set_feature(Features::dir(c_l->groupfeature()->stemdir_i_));
45         return true;
46     }
47     return Register_group_register::try_request(r_l);
48 }
49
50
51 IMPLEMENT_STATIC_NAME(Voice_group_registers);
52
53 void
54 Voice_group_registers::do_print() const
55 {
56 #ifndef NPRINT
57     mtor << "ID: " << group_id_str_<<"\n";
58     mtor << "stopping at " << termination_mom_ << "\n";
59     Register_group_register::do_print();
60 #endif
61 }
62 void
63 Voice_group_registers::add(Request_register*r_l)
64 {
65     Register_group_register::add(r_l);
66     if (r_l->name() == Voice_registers::static_name()) {
67         Voice_registers * vregs_l = (Voice_registers*)r_l;
68         voice_regs_l_.push( vregs_l );
69         Voice *v_l = vregs_l->voice_l_;
70         termination_mom_ = termination_mom_ >? v_l -> last();
71         mtor << "adding Voice_registers, now terminating at " << 
72             termination_mom_<< "\n";
73     }
74 }
75
76 void
77 Voice_group_registers::post_move_processing()
78 {
79     if ( get_staff_info().time_C_ ->when_ > termination_mom_ ){
80         mtor << "Terminating voice_group\n";
81         daddy_reg_l_->terminate_register(this);
82     }
83     Register_group_register::post_move_processing();
84 }
85
86 Request_register *
87 Voice_group_registers::get_register_p(Request_register *reg_l)
88 {
89      if (reg_l->name() == Voice_registers::static_name()) {
90         for (int i=0; i <voice_regs_l_.size(); i++) {
91             if (reg_l == voice_regs_l_[i])
92                 voice_regs_l_.del(i);
93         }
94      }
95      return Register_group_register::get_register_p(reg_l);
96 }