]> git.donarmstrong.com Git - lilypond.git/blobdiff - src/inputcommands.cc
release: 0.0.20
[lilypond.git] / src / inputcommands.cc
index 3a27b3801f93c337e04d5e1bd47348e50d73c83d..e1d40465614488dba2792e45ef822bc04f2fc765 100644 (file)
@@ -1,7 +1,3 @@
-/*
-  it still sucks.
-  */
-
 #include "inputcommands.hh"
 #include "inputcommand.hh"
 #include "debug.hh"
@@ -13,57 +9,44 @@ void
 Commands_at::print() const
 {
 #ifndef NPRINT
-    mtor << "Commands_at { at "<<when<<'\n'; 
-    mtor << "meter " << whole_per_measure
-        << " pos "<< bars << ":" << whole_in_measure <<'\n';
+    mtor << "Commands_at {";
+    tdescription_.print();
     for (PCursor<Input_command *> cc(*this); cc.ok(); cc++) 
        cc->print();
     mtor << "}\n";
 #endif
 }
-
-Commands_at::Commands_at(Real dt, Commands_at* prev)
+Moment
+Commands_at::when()
 {
-    if (prev) {
-       assert(dt >0);
-       when = prev->when + dt;
-       whole_per_measure = prev->whole_per_measure;
-       whole_in_measure = prev->whole_in_measure + dt;
-       bars = prev->bars;
-
-       while ( whole_in_measure >= whole_per_measure ) {
-           whole_in_measure -= whole_per_measure;
-           bars ++;
-       }
-       if (!whole_in_measure) {
-           bottom().add(get_bar_command());
-       }
-    } else {
-       whole_per_measure = 1;
-       whole_in_measure =0;
-       when = 0.0;
-       bars = 0;
+    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_bar_command());
     }
 }
 
 void
 Commands_at::add(Input_command *i)
 {
-    bottom().add(i);           
-    if (i->args[0] == "METER") { // should check for other meterchanges here.
-       Real l = i->args[1];
-       Real o = i->args[2];
-       whole_per_measure = l/o;                
+    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)
+Commands_at::Commands_at(Commands_at const&src) :
+    tdescription_(src.tdescription_)
 {
-    when = src.when;
-    whole_in_measure = whole_in_measure;
-    whole_per_measure = whole_per_measure;
-    bars = src.bars;
-    
     IPointerList<Input_command*> &me(*this);
     const IPointerList<Input_command*> &that(src);
     
@@ -71,33 +54,43 @@ Commands_at::Commands_at(Commands_at const&src)
 }
 
 void
-Commands_at::setpartial(Real p)
+Commands_at::setpartial(Moment p)
 {
-    if (when)
-       error_t ("Partial measure only allowed at beginning.", when);
-    if (p<0||p > whole_per_measure)
-       error_t ("Partial measure has incorrect size", when);
-    whole_in_measure = whole_per_measure - p;
+    tdescription_.setpartial(p);
 }
-Real
+
+Moment
 Commands_at::barleft()
 {
-    return  whole_per_measure-whole_in_measure;
+    return  tdescription_.barleft();
 }
 
+void
+Commands_at::parse(Staff_commands_at*s)
+{
+    s->tdescription_ = tdescription_;
+    for (PCursor<Input_command *> cc(*this); cc.ok(); cc++) {
+       if (cc->args.sz() &&  cc->args[0] !="") {
+           Command c = **cc;
+           s->add(c);
+           
+       }
+    }
+}
 /****************/
 
 void
-Input_cursor::find_moment(Real w)
+Input_cursor::find_moment(Moment w)
 {
-    Real last = when();
+    Moment last = when();
     while  (1) {
        if (! ok() ) {
-           *this = PCursor<Commands_at*>(list().bottom());
-           Real dt = (w - when()) <? ptr()->barleft();
-           assert(dt >= 0);
+           *this = list().bottom();
+           Moment dt = (w - when()) <? ptr()->barleft();
+
            Commands_at * c = new Commands_at(dt, *this);
-           add(c);         
+           assert(c->when() <= w);
+           add(c);
        } else if (when() == w ) {
            return ;
        } else if (when() > w )
@@ -109,7 +102,7 @@ Input_cursor::find_moment(Real w)
     }
 
     prev();
-    Real dt = (w - when());
+    Moment dt = (w - when());
     Commands_at * c = new Commands_at(dt, *this);
     add(c);
     next();
@@ -136,15 +129,15 @@ Input_commands::Input_commands()
 }
 
 void
-Input_commands::do_skip(int bars, Real wholes)
+Input_commands::do_skip(int bars, Moment wholes)
 {
     while (bars > 0) {
-       Real b = ptr->barleft();
-       ptr.find_moment(ptr->when + b);
+       Moment b = ptr->barleft();
+       ptr.find_moment(ptr->when() + b);
        bars --;        
     }
     if (wholes) {
-       ptr.find_moment(ptr->when + wholes);
+       ptr.find_moment(ptr->when() + wholes);
     }
 }
 
@@ -154,21 +147,25 @@ Input_commands::add(Input_command c)
 {    
     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 = c.args[1];
        int one_beat = c.args[2];
        Input_command *ch = get_meterchange_command(beats_per_meas, one_beat);
        ptr->add(ch);           
-    } else if  (c.args[0] == "KEY" || c.args[0] == "CLEF") {
-       Input_command *ic = new Input_command(c);
-       ptr->add(ic);
     } else if (c.args[0] == "SKIP") {
        int bars = c.args[1] ;
-       Real wholes= c.args[2];
+       Moment wholes= c.args[2];
        do_skip(bars, wholes);
     } else if (c.args[0] == "RESET") {
        ptr= top();
-    }
+    } else {
+       Input_command *ic = new Input_command(c);
+       ptr->add(ic);
+    } 
     
 }
 
@@ -178,23 +175,23 @@ Input_commands::parse() const
     print();
     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->add(c,0.0);
-    }
+    for (PCursor<Commands_at*> i(*this); i.ok(); i++) {
 
-    for (PCursor<Commands_at*> i(*this); i.ok(); i++)
-       for (PCursor<Input_command *> cc(**i); cc.ok(); cc++) {
-           if (cc->args.sz() &&  cc->args[0] !="") {
-               Command c = **cc;
-//             c.when = i->when;
-               nc->add(c, i->when);
-           }
+       Staff_commands_at* s= nc->find(i->when());
+       if (!s){
+           s = new Staff_commands_at(i->tdescription_);
+           nc->add(s);
        }
-    
+       if (!i->when()) {   /* all pieces should start with a breakable. */
+           Command c;//(0.0);
+           c.code = INTERPRET;
+           c.args.add("BAR");
+           c.args.add("empty");
+           s->add(c);
+       }
+
+       i->parse(s);
+    }
     return nc;
 }
 
@@ -210,10 +207,10 @@ Input_commands::print() const
 }
 /****************/
 
-Real
+Moment
 Input_cursor::when()const
 {
-    return (*this)->when; 
+    return (*this)->when()
 }
 Input_cursor::Input_cursor(PCursor<Commands_at *>c)
     : PCursor<Commands_at*>(c)