]> git.donarmstrong.com Git - lilypond.git/blob - lily/voice-group-regs.cc
b9351bd8e8edb923abed6703947a64f4ad749ac0
[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 "text-reg.hh"
16 #include "stem-beam-reg.hh"
17 #include "script-reg.hh"
18 #include "complex-walker.hh"
19 #include "command-request.hh"
20 #include "debug.hh"
21 #include "dynamic-reg.hh"
22
23 static int temp_id_count;
24
25 Voice_group_registers::Voice_group_registers(String id)
26 {
27     add(new Dynamic_register);
28     add(new Text_register);
29     add(new Stem_beam_register);
30     add(new Script_register);
31     
32     if (id=="")                 // UGH
33         id = __FUNCTION__ + String(temp_id_count++);
34     group_id_str_ = id;
35     termination_mom_ = 0; 
36 }
37
38 bool
39 Voice_group_registers::try_request(Request*r_l)
40 {
41     for (int i=0; i < voice_regs_l_.size(); i++) {      
42         if (voice_regs_l_[i]->voice_l_ == r_l->voice_l())
43             goto gotcha;
44     }
45     return false;
46 gotcha:
47     if (r_l->groupfeature()) {
48         set_feature(Features::dir(r_l->groupfeature()->stemdir_i_));
49         return true;
50     }
51     return Register_group_register::try_request(r_l);
52 }
53
54
55 bool
56 Voice_group_registers::static_acceptable_request_b(Request*r)
57 {
58     return (r->stem() || r->beam() || r->text() || r->script() ||
59             r->groupfeature());
60 }
61
62 void
63 Voice_group_registers::terminate_register(Request_register*r_l)
64 {
65     if (r_l->name() == Voice_registers::static_name()) {
66         for (int i=0; i <voice_regs_l_.size(); i++) {
67             if (r_l == voice_regs_l_[i])
68                 voice_regs_l_.del(i);
69             mtor << "Terminating voice_reg " ;
70             Register_group_register::terminate_register(r_l);
71             return;
72         }
73     }
74     assert(false);
75 }
76 IMPLEMENT_STATIC_NAME(Voice_group_registers);
77
78 void
79 Voice_group_registers::do_print() const
80 {
81 #ifndef NPRINT
82     mtor << "ID: " << group_id_str_<<"\n";
83     mtor << "stopping at " << termination_mom_ << "\n";
84     Register_group_register::do_print();
85 #endif
86 }
87 void
88 Voice_group_registers::add(Request_register*r_l)
89 {
90     Register_group_register::add(r_l);
91     if (r_l->name() == Voice_registers::static_name()) {
92         Voice_registers * vregs_l = (Voice_registers*)r_l;
93         voice_regs_l_.push( vregs_l );
94         Voice *v_l = vregs_l->voice_l_;
95         termination_mom_ = termination_mom_ >? v_l -> last();
96         mtor << "adding Voice_registers, now terminating at " << 
97             termination_mom_<< "\n";
98     }
99 }
100
101 void
102 Voice_group_registers::post_move_processing()
103 {
104     if ( get_staff_info().time_C_ ->when_ > termination_mom_ ){
105         mtor << "Terminating voice_group\n";
106         daddy_reg_l_->terminate_register(this);
107     }
108     Register_group_register::post_move_processing();
109 }