lilypond-1.1.45
[lilypond.git] / src / inputcommands.cc
blob36e421c7b668687644e6e75c6493dbb18a45159d
1 #include "inputcommands.hh"
2 #include "inputcommand.hh"
3 #include "debug.hh"
4 #include "staffcommands.hh"
5 #include "getcommand.hh"
6 #include "command.hh"
7 #include "stcol.hh"
8 #include "staff.hh"
9 #include "assoc.hh"
10 #include "lexer.hh"
12 void
13 Commands_at::print() const
15 #ifndef NPRINT
16 mtor << "Commands_at {";
17 tdescription_.print();
18 for (iter_top(*this,cc); cc.ok(); cc++)
19 cc->print();
20 mtor << "}\n";
21 #endif
24 Moment
25 Commands_at::when()
27 return tdescription_.when;
30 Commands_at::Commands_at(Moment dt, Commands_at* prev)
31 : tdescription_(dt, (prev)? &prev->tdescription_ : 0)
33 if (prev && !tdescription_.whole_in_measure) {
34 bottom().add(get_newmeasure_command());
38 void
39 Commands_at::add(Input_command *i)
41 bottom().add(i);
43 // should check for other meterchanges here.
44 if (i->args[0] == "METER") {
45 int l = i->args[1];
46 int o = i->args[2];
47 tdescription_.set_meter(l,o);
48 bottom().add(get_grouping_command( get_default_grouping(l,o)));
52 Commands_at::Commands_at(Commands_at const&src) :
53 tdescription_(src.tdescription_)
55 IPointerList<Input_command*> &me(*this);
56 const IPointerList<Input_command*> &that(src);
58 PL_copy(me, that);
61 void
62 Commands_at::setpartial(Moment p)
64 tdescription_.setpartial(p);
67 Moment
68 Commands_at::barleft()
70 return tdescription_.barleft();
73 void
74 Commands_at::parse(Staff_commands_at*s)
76 s->tdescription_ = tdescription_;
77 for (iter_top(*this,cc); cc.ok(); cc++) {
78 if (cc->args.size() && cc->args[0] !="") {
79 Command c = **cc;
80 s->add(c);
85 /* *************** */
87 void
88 Input_cursor::find_moment(Moment w)
90 Moment last = when();
91 while (1) {
92 if (! ok() ) {
93 *this = list().bottom();
95 Moment dt = (w - when());
96 if ( !ptr()->tdescription_.cadenza_b_ )
97 dt = dt <? ptr()->barleft();
99 Commands_at * c = new Commands_at(dt, *this);
100 assert(c->when() <= w);
101 add(c);
102 } else if (when() == w ) {
103 return ;
104 } else if (when() > w )
105 break;
108 last = when();
109 next();
112 prev();
113 Moment dt = (w - when());
114 Commands_at * c = new Commands_at(dt, *this);
115 add(c);
116 next();
121 /* *************** */
122 void
123 Input_commands::find_moment(Moment m)
125 ptr.find_moment(m);
128 Input_commands::Input_commands(Input_commands const&src)
129 : ptr(src.ptr)
131 IPointerList<Commands_at*> &me(*this);
132 const IPointerList<Commands_at*> &that(src);
134 PL_copy(me, that);
137 Input_commands::Input_commands()
138 : ptr (bottom())
140 Commands_at * p = new Commands_at(0,0);
141 bottom().add(p);
142 ptr = bottom();
145 void
146 Input_commands::do_skip(int bars, Moment wholes)
148 while (bars > 0) {
149 Moment b = ptr->barleft();
150 ptr.find_moment(ptr->when() + b);
151 bars --;
153 if (wholes) {
154 ptr.find_moment(ptr->when() + wholes);
159 void
160 Input_commands::add(Input_command c, Assoc<String,Moment> &marks_assoc_r)
162 String s(c.args[0]);
163 if (s == "CADENZA") {
164 ptr->tdescription_.set_cadenza((int)c.args[1]);
165 } if (s == "PARTIAL") {
166 ptr->setpartial(c.args[1]);
167 } else if (s == "GROUPING") {
168 Input_command *ic = new Input_command(c);
169 ic->args.insert(ptr->tdescription_.one_beat, 1);
170 ptr->add(ic);
171 } else if (s == "METER") {
172 int beats_per_meas = c.args[1];
173 int one_beat = c.args[2];
174 Input_command *ch = get_meterchange_command(beats_per_meas, one_beat);
175 ptr->add(ch);
176 } else if (s == "SKIP") {
177 int bars = c.args[1] ;
178 Moment wholes= c.args[2];
179 do_skip(bars, wholes);
180 } else if (s == "RESET") {
181 ptr= top();
182 } else if (s=="GOTO") {
183 ptr = top();
184 String m(c.args[1]);
185 if (!marks_assoc_r.elt_query(m)) {
186 warning( "Unknown marker: `" +m + "\'", 0 );
187 return;
190 ptr.find_moment(marks_assoc_r[m]);
191 } else {
192 Input_command *ic = new Input_command(c);
193 ptr->add(ic);
198 void
199 Input_commands::parse(Staff * staff_l) const
201 print();
202 for (iter_top(*this,i); i.ok(); i++) {
204 Staff_column* col_l = staff_l->get_col(i->when(), false);
205 if (!col_l->staff_commands_p_)
206 col_l->staff_commands_p_ = new Staff_commands_at(i->tdescription_);
208 Staff_commands_at * com_l = col_l->staff_commands_p_;
210 if (!i->when()) { /* all pieces should start with a breakable. */
211 com_l->set_breakable();
214 i->parse(com_l);
219 void
220 Input_commands::print() const
222 #ifndef NPRINT
223 for (iter_top(*this,cc); cc.ok() ; cc++) {
224 cc->print();
226 #endif
228 /* *************** */
230 Moment
231 Input_cursor::when()const
233 return (*this)->when();
235 Input_cursor::Input_cursor(PCursor<Commands_at *>c)
236 : PCursor<Commands_at*>(c)