]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-regs.cc
e22d32873c93a6c4688d158f2f015e516130cfff
[lilypond.git] / lily / staff-regs.cc
1 /*
2   staff-regs.cc -- implement Staff_registers
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "staff-sym.hh"
9 #include "voice-group-regs.hh"
10 #include "voice-regs.hh"
11 #include "staff-regs.hh"
12 #include "command-request.hh"
13 #include "bar.hh"
14 #include "debug.hh"
15 #include "input-register.hh"
16
17 Staff_info
18 Staff_registers::get_staff_info() return inf;
19 {
20     inf = Request_register::get_staff_info();
21     inf.c0_position_i_l_ = &c0_position_i_;
22 }
23
24 Staff_registers::Staff_registers(Input_register const*ireg_C)
25 {
26     c0_position_i_ = 0;
27     base_position_i_ =0;
28     add( ireg_C->get_nongroup_p_arr());
29     ireg_C_ =ireg_C;
30 }
31
32 /** Magic function which takes a Voice_registers out of one of its own
33   children, and puts it in another. This also handles the push and
34   popgroup feature.  */
35 void
36 Staff_registers::change_group(Group_change_req * greq_l,
37                                Voice_registers *voice_regs_l,
38                                Voice_group_registers * old_group)
39 {
40
41     Voice_registers *regs_p = (old_group)
42         ? (Voice_registers*) old_group->get_register_p(
43             voice_regs_l)
44         : new Voice_registers(
45             greq_l->voice_l(), ireg_C_->get_ireg_l("Voice_group_registers")
46             ->get_ireg_l("Voice_registers"));
47
48     String new_str = greq_l->newgroup_str_;
49     String old_str;
50     if (old_group)
51          old_str = old_group->group_id_str_;
52     if ( new_str[0] == '+') {
53         new_str = old_str + new_str;
54     } else if (new_str[0] == '-') {
55         int idx = old_str.index_last_i('+');
56         if (idx >=0)
57             new_str = old_str.left_str ( idx );
58     }
59     Voice_group_registers * new_group_l = get_group(new_str);
60     new_group_l->add(regs_p);
61     
62     mtor << "processed change_group " << get_staff_info().when()<<"\n";
63     print();
64 }
65
66 Voice_group_registers *
67 Staff_registers::get_group(String id)
68 {
69     for (int i=0; i < group_l_arr_.size(); i++) {
70         if (group_l_arr_[i]->group_id_str_ == id)
71             return group_l_arr_[i];
72     }
73     Voice_group_registers *group_p = 
74         new Voice_group_registers(id, ireg_C_->get_ireg_l("Voice_group_registers"));
75     group_l_arr_.push(group_p);
76     add(group_p);
77     return group_p;
78 }
79
80
81 void
82 Staff_registers::terminate_register(Request_register * reg)
83 {
84     for (int i=0; i < group_l_arr_.size(); i++) {
85         if (group_l_arr_[i] == reg) {
86             group_l_arr_.del(i);
87             Register_group_register::terminate_register(reg);
88             return;
89         }
90     }
91     assert(false);
92 }
93
94 bool
95 Staff_registers::try_request(Request * r)
96 {
97     bool b = Register_group_register::try_request(r);
98     if (!b) {
99         Command_req * cr_l = r->command() ;
100         
101         if (cr_l && cr_l->groupchange()) {
102             change_group(cr_l->groupchange(), 0, 0);
103             b = true;
104         } else 
105             b= false;
106     }
107     return b;
108 }
109
110 IMPLEMENT_STATIC_NAME(Staff_registers);
111
112 bool
113 Staff_registers::acceptable_request_b(Request*r)const
114 {
115     return Register_group_register::acceptable_request_b(r) ||
116         (r->command() && r->command()->groupchange());
117 }
118