]> git.donarmstrong.com Git - lilypond.git/blob - src/inputcommands.cc
release: 0.0.20
[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
8 void
9 Commands_at::print() const
10 {
11 #ifndef NPRINT
12     mtor << "Commands_at {";
13     tdescription_.print();
14     for (PCursor<Input_command *> cc(*this); cc.ok(); cc++) 
15         cc->print();
16     mtor << "}\n";
17 #endif
18 }
19 Moment
20 Commands_at::when()
21 {
22     return tdescription_.when;
23 }
24 Commands_at::Commands_at(Moment dt, Commands_at* prev)
25     : tdescription_(dt, (prev)? &prev->tdescription_ : 0)
26 {
27     if (prev&& !tdescription_.whole_in_measure) {
28         bottom().add(get_bar_command());
29     }
30 }
31
32 void
33 Commands_at::add(Input_command *i)
34 {
35     bottom().add(i);
36
37     // should check for other meterchanges here.
38     if (i->args[0] == "METER") { 
39         int l = i->args[1];
40         int o = i->args[2];
41         tdescription_.set_meter(l,o);
42         bottom().add(get_grouping_command( get_default_grouping(l)));
43
44     }
45 }
46
47 Commands_at::Commands_at(Commands_at const&src) :
48     tdescription_(src.tdescription_)
49 {
50     IPointerList<Input_command*> &me(*this);
51     const IPointerList<Input_command*> &that(src);
52     
53     PL_copy(me, that);
54 }
55
56 void
57 Commands_at::setpartial(Moment p)
58 {
59     tdescription_.setpartial(p);
60 }
61
62 Moment
63 Commands_at::barleft()
64 {
65     return  tdescription_.barleft();
66 }
67
68 void
69 Commands_at::parse(Staff_commands_at*s)
70 {
71     s->tdescription_ = tdescription_;
72     for (PCursor<Input_command *> cc(*this); cc.ok(); cc++) {
73         if (cc->args.sz() &&  cc->args[0] !="") {
74             Command c = **cc;
75             s->add(c);
76             
77         }
78     }
79 }
80 /****************/
81
82 void
83 Input_cursor::find_moment(Moment w)
84 {
85     Moment last = when();
86     while  (1) {
87         if (! ok() ) {
88             *this = list().bottom();
89             Moment dt = (w - when()) <? ptr()->barleft();
90
91             Commands_at * c = new Commands_at(dt, *this);
92             assert(c->when() <= w);
93             add(c);
94         } else if (when() == w ) {
95             return ;
96         } else if (when() > w )
97             break;
98         
99         
100         last = when();
101         next();
102     }
103
104     prev();
105     Moment dt = (w - when());
106     Commands_at * c = new Commands_at(dt, *this);
107     add(c);
108     next();
109 }
110
111
112
113 /****************/
114 Input_commands::Input_commands(Input_commands const&src)
115     : ptr(src.ptr)
116 {
117     IPointerList<Commands_at*> &me(*this);
118     const IPointerList<Commands_at*> &that(src);
119     
120     PL_copy(me, that);    
121 }
122
123 Input_commands::Input_commands()
124     :    ptr (bottom())
125 {
126     Commands_at * p = new Commands_at(0,0);    
127     bottom().add(p);    
128     ptr = bottom();    
129 }
130
131 void
132 Input_commands::do_skip(int bars, Moment wholes)
133 {
134     while (bars > 0) {
135         Moment b = ptr->barleft();
136         ptr.find_moment(ptr->when() + b);
137         bars --;        
138     }
139     if (wholes) {
140         ptr.find_moment(ptr->when() + wholes);
141     }
142 }
143
144
145 void
146 Input_commands::add(Input_command c)
147 {    
148     if (c.args[0] == "PARTIAL") {       
149         ptr->setpartial(c.args[1]);
150     } else if (c.args[0] == "GROUPING") {
151         Input_command *ic = new Input_command(c);
152         ic->args.insert(ptr->tdescription_.one_beat, 1);
153         ptr->add(ic);
154     } else if (c.args[0] == "METER") {
155         int beats_per_meas = c.args[1];
156         int one_beat = c.args[2];
157         Input_command *ch = get_meterchange_command(beats_per_meas, one_beat);
158         ptr->add(ch);           
159     } else if (c.args[0] == "SKIP") {
160         int bars = c.args[1] ;
161         Moment wholes= c.args[2];
162         do_skip(bars, wholes);
163     } else if (c.args[0] == "RESET") {
164         ptr= top();
165     } else {
166         Input_command *ic = new Input_command(c);
167         ptr->add(ic);
168     } 
169     
170 }
171
172 Staff_commands*
173 Input_commands::parse() const
174 {
175     print();
176     Staff_commands*nc = new Staff_commands;
177
178     for (PCursor<Commands_at*> i(*this); i.ok(); i++) {
179
180         Staff_commands_at* s= nc->find(i->when());
181         if (!s){
182             s = new Staff_commands_at(i->tdescription_);
183             nc->add(s);
184         }
185         if (!i->when()) {   /* all pieces should start with a breakable. */
186             Command c;//(0.0);
187             c.code = INTERPRET;
188             c.args.add("BAR");
189             c.args.add("empty");
190             s->add(c);
191         }
192
193         i->parse(s);
194     }
195     return nc;
196 }
197
198
199 void
200 Input_commands::print() const
201 {
202 #ifndef NPRINT
203     for (PCursor<Commands_at*> cc(*this); cc.ok() ; cc++) {
204         cc->print();
205     }
206 #endif
207 }
208 /****************/
209
210 Moment
211 Input_cursor::when()const
212 {
213     return (*this)->when(); 
214 }
215 Input_cursor::Input_cursor(PCursor<Commands_at *>c)
216     : PCursor<Commands_at*>(c)
217 {
218 }