]> git.donarmstrong.com Git - lilypond.git/blob - src/inputcommands.cc
release: 0.0.29
[lilypond.git] / src / inputcommands.cc
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"
11
12 void
13 Commands_at::print() const
14 {
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
22 }
23
24 Moment
25 Commands_at::when()
26 {
27     return tdescription_.when;
28 }
29
30 Commands_at::Commands_at(Moment dt, Commands_at* prev)
31     : tdescription_(dt, (prev)? &prev->tdescription_ : 0)
32 {
33     if (prev && !tdescription_.whole_in_measure) {
34         bottom().add(get_newmeasure_command());
35     }
36 }
37
38 void
39 Commands_at::add(Input_command *i)
40 {
41     bottom().add(i);
42
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)));
49     }
50 }
51
52 Commands_at::Commands_at(Commands_at const&src) :
53     tdescription_(src.tdescription_)
54 {
55     IPointerList<Input_command*> &me(*this);
56     const IPointerList<Input_command*> &that(src);
57     
58     PL_copy(me, that);
59 }
60
61 void
62 Commands_at::setpartial(Moment p)
63 {
64     tdescription_.setpartial(p);
65 }
66
67 Moment
68 Commands_at::barleft()
69 {
70     return  tdescription_.barleft();
71 }
72
73 void
74 Commands_at::parse(Staff_commands_at*s)
75 {
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);
81             
82         }
83     }
84 }
85 /****************/
86
87 void
88 Input_cursor::find_moment(Moment w)
89 {
90     Moment last = when();
91     while  (1) {
92         if (! ok() ) {
93             *this = list().bottom();
94             
95             Moment dt = (w - when());
96             if ( !ptr()->tdescription_.cadenza_b_ )
97                 dt = dt <? ptr()->barleft();
98
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;
106         
107         
108         last = when();
109         next();
110     }
111
112     prev();
113     Moment dt = (w - when());
114     Commands_at * c = new Commands_at(dt, *this);
115     add(c);
116     next();
117 }
118
119
120
121 /****************/
122 void
123 Input_commands::find_moment(Moment m)
124 {
125     ptr.find_moment(m);
126 }
127
128 Input_commands::Input_commands(Input_commands const&src)
129     : ptr(src.ptr)
130 {
131     IPointerList<Commands_at*> &me(*this);
132     const IPointerList<Commands_at*> &that(src);
133     
134     PL_copy(me, that);    
135 }
136
137 Input_commands::Input_commands()
138     :    ptr (bottom())
139 {
140     Commands_at * p = new Commands_at(0,0);    
141     bottom().add(p);    
142     ptr = bottom();    
143 }
144
145 void
146 Input_commands::do_skip(int bars, Moment wholes)
147 {
148     while (bars > 0) {
149         Moment b = ptr->barleft();
150         ptr.find_moment(ptr->when() + b);
151         bars --;        
152     }
153     if (wholes) {
154         ptr.find_moment(ptr->when() + wholes);
155     }
156 }
157
158
159 void
160 Input_commands::add(Input_command c, Assoc<String,Moment> &marks_assoc_r)
161 {
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;
188         }
189         
190         ptr.find_moment(marks_assoc_r[m]);
191     } else {
192         Input_command *ic = new Input_command(c);
193         ptr->add(ic);
194     } 
195     
196 }
197
198 void
199 Input_commands::parse(Staff * staff_l) const
200 {
201     print();
202     for (iter_top(*this,i); i.ok(); i++) {
203
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_);
207         
208         Staff_commands_at * com_l = col_l->staff_commands_p_;
209         
210         if (!i->when()) {   /* all pieces should start with a breakable. */
211             com_l->set_breakable();
212         }
213
214         i->parse(com_l);
215     }
216 }
217
218
219 void
220 Input_commands::print() const
221 {
222 #ifndef NPRINT
223     for (iter_top(*this,cc); cc.ok() ; cc++) {
224         cc->print();
225     }
226 #endif
227 }
228 /****************/
229
230 Moment
231 Input_cursor::when()const
232 {
233     return (*this)->when(); 
234 }
235 Input_cursor::Input_cursor(PCursor<Commands_at *>c)
236     : PCursor<Commands_at*>(c)
237 {
238 }