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