]> git.donarmstrong.com Git - lilypond.git/blob - lily/staff-regs.cc
release: 0.0.64
[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() 
19 {
20     Staff_info inf;
21     inf = Request_register::get_staff_info();
22     inf.staff_sym_l_=staff_sym_l_;
23     inf.c0_position_i_l_ = &c0_position_i_;
24     return inf;
25 }
26
27 Staff_registers::Staff_registers(Input_register const*ireg_C)
28 {
29     staff_sym_l_ =0;
30     c0_position_i_ = 0;
31     base_position_i_ =0;
32     add( ireg_C->get_nongroup_p_arr());
33     ireg_C_ =ireg_C;
34 }
35
36 /** Magic function which takes a Voice_registers out of one of its own
37   children, and puts it in another. This also handles the push and
38   popgroup feature.  */
39 void
40 Staff_registers::change_group(Group_change_req * greq_l,
41                                Voice_registers *voice_regs_l,
42                                Voice_group_registers * old_group)
43 {
44
45     Voice_registers *regs_p = (old_group)
46         ? (Voice_registers*) old_group->get_register_p(
47             voice_regs_l)
48         : new Voice_registers(
49             greq_l->voice_l(), ireg_C_->get_ireg_l("Voice_group_registers")
50             ->get_ireg_l("Voice_registers"));
51
52     String new_str = greq_l->newgroup_str_;
53     String old_str;
54     if (old_group)
55          old_str = old_group->group_id_str_;
56     if ( new_str[0] == '+') {
57         new_str = old_str + new_str;
58     } else if (new_str[0] == '-') {
59         int idx = old_str.index_last_i('+');
60         if (idx >=0)
61             new_str = old_str.left_str ( idx );
62     }
63     Voice_group_registers * new_group_l = get_group(new_str);
64     new_group_l->add(regs_p);
65     regs_p->sync_features(); 
66     mtor << "processed change_group " << get_staff_info().when()<<"\n";
67     print();
68 }
69
70 Voice_group_registers *
71 Staff_registers::get_group(String id)
72 {
73     for (int i=0; i < group_l_arr_.size(); i++) {
74         if (group_l_arr_[i]->group_id_str_ == id)
75             return group_l_arr_[i];
76     }
77     Voice_group_registers *group_p = 
78         new Voice_group_registers(id, ireg_C_->get_ireg_l("Voice_group_registers"));
79     group_l_arr_.push(group_p);
80     add(group_p);
81     return group_p;
82 }
83
84
85 void
86 Staff_registers::terminate_register(Request_register * reg)
87 {
88     for (int i=0; i < group_l_arr_.size(); i++) {
89         if (group_l_arr_[i] == reg) {
90             group_l_arr_.del(i);
91             Register_group_register::terminate_register(reg);
92             return;
93         }
94     }
95     assert(false);
96 }
97
98 bool
99 Staff_registers::try_request(Request * r)
100 {
101     bool b = Register_group_register::try_request(r);
102     if (!b) {
103         Command_req * cr_l = r->command() ;
104         
105         if (cr_l && cr_l->groupchange()) {
106             change_group(cr_l->groupchange(), 0, 0);
107             b = true;
108         } else 
109             b= false;
110     }
111     return b;
112 }
113
114 IMPLEMENT_STATIC_NAME(Staff_registers);
115
116 bool
117 Staff_registers::acceptable_request_b(Request*r)const
118 {
119     return Register_group_register::acceptable_request_b(r) ||
120         (r->command() && r->command()->groupchange());
121 }
122
123 void
124 Staff_registers::acknowledge_element(Score_elem_info i)
125 {
126     Register_group_register::acknowledge_element(i);
127     if ( i.elem_l_->name() == Staff_symbol::static_name())
128         staff_sym_l_ = (Staff_symbol*)i.elem_l_->item();
129 }