]> git.donarmstrong.com Git - lilypond.git/blob - lily/voice-group-regs.cc
release: 0.0.60
[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     dir_i_ =0;
26     ireg_C_ =ireg_C;
27     Register_group_register::add(ireg_C->get_nongroup_p_arr());
28     if (id=="")                 // ugh
29         id = __FUNCTION__ + String(temp_id_count++);
30     group_id_str_ = id;
31     termination_mom_ = 0; 
32 }
33
34 bool
35 Voice_group_registers::try_request(Request*r_l)
36 {
37     for (int i=0; i < voice_reg_l_arr_.size(); i++) {   
38         if (voice_reg_l_arr_[i]->voice_l_ == r_l->voice_l())
39             goto gotcha;        // yeah, yeah, I know
40     }
41     return false;
42 gotcha:
43     Command_req* c_l = r_l->command();
44     if (c_l&& c_l->groupfeature()) {
45         Feature f;
46         f.type_ = c_l->groupfeature()->type_str_;
47         f.value_ = c_l->groupfeature()->value_str_;
48         set_feature(f);
49         return true;
50     }
51     return Register_group_register::try_request(r_l);
52 }
53
54
55 IMPLEMENT_STATIC_NAME(Voice_group_registers);
56
57 void
58 Voice_group_registers::do_print() const
59 {
60 #ifndef NPRINT
61     mtor << "ID: " << group_id_str_<<"\n";
62     mtor << "stopping at " << termination_mom_ << "\n";
63     Register_group_register::do_print();
64 #endif
65 }
66 void
67 Voice_group_registers::add(Request_register*r_l)
68 {
69     Register_group_register::add(r_l);
70     if (r_l->name() == Voice_registers::static_name()) {
71         Voice_registers * vregs_l = (Voice_registers*)r_l;
72         voice_reg_l_arr_.push( vregs_l );
73         Voice *v_l = vregs_l->voice_l_;
74         termination_mom_ = termination_mom_ >? v_l -> last();
75         mtor << "adding Voice_registers, now terminating at " << 
76             termination_mom_<< "\n";
77     }
78     OK();
79 }
80
81 void
82 Voice_group_registers::post_move_processing()
83 {
84     if ( get_staff_info().time_C_ ->when_ > termination_mom_ ){
85         mtor << "Terminating voice_group\n";
86         daddy_reg_l_->terminate_register(this);
87         return ;
88     }
89     Register_group_register::post_move_processing();
90 }
91
92 Request_register *
93 Voice_group_registers::get_register_p(Request_register *reg_l)
94 {
95      if (reg_l->name() == Voice_registers::static_name()) {
96         for (int i=0; i <voice_reg_l_arr_.size(); i++) {
97             if (reg_l == voice_reg_l_arr_[i])
98                 voice_reg_l_arr_.del(i);
99         }
100      }
101      Request_register*reg_p =Register_group_register::get_register_p(reg_l);
102      OK();
103
104      return reg_p;
105 }
106
107 void
108 Voice_group_registers::OK() const
109 {
110     for (int i=0; i < voice_reg_l_arr_.size(); i++) {
111         iter(reg_list_.find(voice_reg_l_arr_[i]), j);
112         assert(j.ok());
113     }
114 }
115              
116              
117 void
118 Voice_group_registers::set_feature(Feature f)
119 {
120     if (f.type_ == "vdir")
121         dir_i_ = f.value_;
122     Register_group_register::set_feature(f);
123 }
124
125 Scalar
126 Voice_group_registers::get_feature(String f)
127 {
128     if (f == "vdir")
129         return dir_i_;
130     Register_group_register::get_feature(f);
131 }