-/*
- it still sucks.
- */
-
#include "inputcommands.hh"
#include "inputcommand.hh"
#include "debug.hh"
#include "staffcommands.hh"
#include "getcommand.hh"
#include "command.hh"
+#include "stcol.hh"
+#include "staff.hh"
-Input_commands::Input_commands(Input_commands const&src)
- : ptr(src.ptr)
+void
+Commands_at::print() const
+{
+#ifndef NPRINT
+ mtor << "Commands_at {";
+ tdescription_.print();
+ for (iter_top(*this,cc); cc.ok(); cc++)
+ cc->print();
+ mtor << "}\n";
+#endif
+}
+Moment
+Commands_at::when()
+{
+ return tdescription_.when;
+}
+Commands_at::Commands_at(Moment dt, Commands_at* prev)
+ : tdescription_(dt, (prev)? &prev->tdescription_ : 0)
+{
+ if (prev&& !tdescription_.whole_in_measure) {
+ bottom().add(get_newmeasure_command());
+ }
+}
+
+void
+Commands_at::add(Input_command *i)
+{
+ bottom().add(i);
+
+ // should check for other meterchanges here.
+ if (i->args[0] == "METER") {
+ int l = i->args[1];
+ int o = i->args[2];
+ tdescription_.set_meter(l,o);
+ bottom().add(get_grouping_command( get_default_grouping(l)));
+
+ }
+}
+
+Commands_at::Commands_at(Commands_at const&src) :
+ tdescription_(src.tdescription_)
{
IPointerList<Input_command*> &me(*this);
const IPointerList<Input_command*> &that(src);
- PL_copy(me, that);
+ PL_copy(me, that);
}
-Input_commands::Input_commands()
- : ptr (bottom())
+void
+Commands_at::setpartial(Moment p)
{
- Input_command c(0.0);
- bottom().add(new Input_command(c));
- ptr = bottom();
+ tdescription_.setpartial(p);
}
-void
-Input_commands::truncate(Real last)
+Moment
+Commands_at::barleft()
{
- bool reset_ = false;
-
- if (ptr.when() >= last)
- reset_=true;
- PCursor<Input_command*> i(*this);
-
- while (i.ok() && i ->when < last)
- i++;
-
- while (i.ok())
- i.del();
+ return tdescription_.barleft();
+}
- if (reset_) {
- reset();
-
- while(ptr.ok())
- ptr++;
+void
+Commands_at::parse(Staff_commands_at*s)
+{
+ s->tdescription_ = tdescription_;
+ for (iter_top(*this,cc); cc.ok(); cc++) {
+ if (cc->args.size() && cc->args[0] !="") {
+ Command c = **cc;
+ s->add(c);
+
+ }
}
}
+/****************/
-/*
- ugh. This sux.
- */
void
-Input_commands::find_moment(Real w)
+Input_cursor::find_moment(Moment w)
{
- assert(w >= ptr.when());
- while (ptr.ok() && ptr.when() < w) {
- ptr++;
+ Moment last = when();
+ while (1) {
+ if (! ok() ) {
+ *this = list().bottom();
+ Moment dt = (w - when()) <? ptr()->barleft();
+
+ Commands_at * c = new Commands_at(dt, *this);
+ assert(c->when() <= w);
+ add(c);
+ } else if (when() == w ) {
+ return ;
+ } else if (when() > w )
+ break;
+
+
+ last = when();
+ next();
}
+
+ prev();
+ Moment dt = (w - when());
+ Commands_at * c = new Commands_at(dt, *this);
+ add(c);
+ next();
+}
+
+
+
+/****************/
+Input_commands::Input_commands(Input_commands const&src)
+ : ptr(src.ptr)
+{
+ IPointerList<Commands_at*> &me(*this);
+ const IPointerList<Commands_at*> &that(src);
- if (!ptr.ok()) {
- int bars_left =int(floor( (w - ptr.last + ptr.whole_in_measure)
- /ptr.whole_per_measure));
- if (bars_left) {
- Real bar_when = ptr.last - ptr.whole_in_measure + ptr.whole_per_measure;
- ptr.addbot(get_bar_command(bar_when));
- find_moment(w); // tail-recursion. todo
- } else {
- ptr.addbot(new Input_command(w));
- }
+ PL_copy(me, that);
+}
- } else if (ptr.when() != w) {
- ptr.insert(new Input_command(w));
- ptr--;
- }
+Input_commands::Input_commands()
+ : ptr (bottom())
+{
+ Commands_at * p = new Commands_at(0,0);
+ bottom().add(p);
+ ptr = bottom();
}
void
-Input_commands::do_skip(int & bars, Real & wholes)
+Input_commands::do_skip(int bars, Moment wholes)
{
- if (wholes) {
- find_moment(ptr.when() +wholes);
- wholes = 0.0;
+ while (bars > 0) {
+ Moment b = ptr->barleft();
+ ptr.find_moment(ptr->when() + b);
+ bars --;
}
-
- if (bars) {
- ptr.last_command_here(); // find any METER change commands.
- if (ptr.whole_in_measure){
- Real barleft = ptr.whole_per_measure - ptr.whole_in_measure;
- do_skip(bars, barleft);
- }else {
- find_moment(ptr.when() + bars*ptr.whole_per_measure);
- bars = 0;
- }
+ if (wholes) {
+ ptr.find_moment(ptr->when() + wholes);
}
}
void
Input_commands::add(Input_command c)
{
- if (c.args[0] == "PARTIAL") {
- Real p = c.args[1].fvalue();
- ptr.setpartial(p);
-
+ if (c.args[0] == "PARTIAL") {
+ ptr->setpartial(c.args[1]);
+ } else if (c.args[0] == "GROUPING") {
+ Input_command *ic = new Input_command(c);
+ ic->args.insert(ptr->tdescription_.one_beat, 1);
+ ptr->add(ic);
} else if (c.args[0] == "METER") {
- int beats_per_meas, one_beat;
- Real r;
-
- interpret_meter(&c, beats_per_meas, one_beat, r);
+ int beats_per_meas = c.args[1];
+ int one_beat = c.args[2];
Input_command *ch = get_meterchange_command(beats_per_meas, one_beat);
- ch->when = ptr.when();
- ptr.add(ch);
-
- } else if (c.args[0] == "KEY" || c.args[0] == "CLEF") {
- Input_command *ic = new Input_command(c);
- ic->when = ptr.when();
- ptr.add(ic);
+ ptr->add(ch);
} else if (c.args[0] == "SKIP") {
- int bars = c.args[1].value() ;
- Real wholes= c.args[2].fvalue();
- while (bars > 0 || wholes > 0.0) {
- do_skip(bars, wholes);
- }
+ int bars = c.args[1] ;
+ Moment wholes= c.args[2];
+ do_skip(bars, wholes);
} else if (c.args[0] == "RESET") {
- reset();
- }
+ ptr= top();
+ } else {
+ Input_command *ic = new Input_command(c);
+ ptr->add(ic);
+ }
}
void
-Input_commands::reset()
+Input_commands::parse(Staff * staff_l) const
{
- ptr = top();
- ptr.reset();
-}
-
+ print();
+ for (iter_top(*this,i); i.ok(); i++) {
-Staff_commands*
-Input_commands::parse() const
-{
- Staff_commands*nc = new Staff_commands;
-
- { /* all pieces should start with a breakable. */
- Command c(0.0);
- c.code = INTERPRET;
- c.args.add("BAR");
- c.args.add("empty");
- nc->process_add(c);
- }
+ Staff_column* col_l = staff_l->get_col(i->when(), false);
+ if (!col_l->staff_commands_p_)
+ col_l->staff_commands_p_ = new Staff_commands_at(i->tdescription_);
+
+ Staff_commands_at * com_l = col_l->staff_commands_p_;
+
+ if (!i->when()) { /* all pieces should start with a breakable. */
+ com_l->set_breakable();
+ #if 0
+ Command c;//(0.0);
+ c.code = INTERPRET;
+ c.args.add("BAR");
+ c.args.add("empty");
+ com_l->add(c);
+ #endif
+ }
- for (PCursor<Input_command*> cc(*this); cc.ok(); cc++) {
- if (cc->args.sz() && cc->args[0] !="")
- nc->process_add(**cc);
+ i->parse(com_l);
}
-
- return nc;
}
Input_commands::print() const
{
#ifndef NPRINT
- for (PCursor<Command*> cc(*this); cc.ok() ; cc++) {
+ for (iter_top(*this,cc); cc.ok() ; cc++) {
cc->print();
}
- ptr.print();
#endif
}
+/****************/
+
+Moment
+Input_cursor::when()const
+{
+ return (*this)->when();
+}
+Input_cursor::Input_cursor(PCursor<Commands_at *>c)
+ : PCursor<Commands_at*>(c)
+{
+}