]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.19
authorfred <fred>
Sun, 24 Mar 2002 19:26:54 +0000 (19:26 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:26:54 +0000 (19:26 +0000)
src/beam.cc
src/inputcommands.cc
src/moment.cc [new file with mode: 0644]

index a2d58254af6bc57b13811bef0def138f814e35d5..9cb43f57313e0d4f83a7896e2a164e2ba04f2f91 100644 (file)
@@ -9,8 +9,7 @@
 #include "stem.hh"
 #include "paper.hh"
 #include "lookup.hh"
-#include "scalar.hh"
-
+#include "grouping.hh"
 
 struct Stem_info {
     Real x;
@@ -38,6 +37,7 @@ Stem_info::Stem_info(const Stem*s)
 
 Beam::Beam()
 {
+    group = 0;
     slope = 0;
     left_pos = 0.0;
     dir =0;
@@ -120,25 +120,47 @@ Beam::calculate()
     solve_slope();
 }
 
-
 void
 Beam::process()
 {
     calculate();
 
-    /*
-      quick and dirty!
-      */
-    for (PCursor<Stem*> i(stems); i.ok(); i++)
-       i->beams_left = i->beams_right = intlog2(ABS(i->flag)) - 2;
-
-    stems.top()->beams_left = 0;
-    stems.bottom()->beams_right = 0;
-
     brew_molecule();
     set_stemlens();
 }
 
+void
+Beam::set_grouping(Rhythmic_grouping def, Rhythmic_grouping cur)
+{
+    def.OK();
+    cur.OK();
+    assert(cur.children.sz() == stems.size());
+    
+    cur.split(def);
+    group = new Rhythmic_grouping(cur);
+    svec<int> b;
+    {
+       PCursor<Stem*> s(stems);
+       svec<int> flags;
+       for (; s.ok(); s++) {
+           int f = intlog2(ABS(s->flag))-2;
+           assert(f>0);
+           flags.add(f);
+       }
+       int fi =0;
+       b= group->generate_beams(flags, fi);
+       b.insert(0,0);
+       b.add(0);
+       assert(stems.size() == b.sz()/2);
+    }
+
+    PCursor<Stem*> s(stems);
+    for (int i=0; i < b.sz() && s.ok(); i+=2, s++) {
+       s->beams_left = b[i];
+       s->beams_right = b[i+1];
+    }
+}
+
 
 // todo.
 Spanner *
@@ -258,3 +280,7 @@ Beam::print()const
 #endif
 }
 
+Beam::~Beam()
+{
+    delete group;
+}
index 3a27b3801f93c337e04d5e1bd47348e50d73c83d..59d8eeaae76ad21be738a51cca901a1efecdb77a 100644 (file)
@@ -1,7 +1,3 @@
-/*
-  it still sucks.
-  */
-
 #include "inputcommands.hh"
 #include "inputcommand.hh"
 #include "debug.hh"
@@ -13,57 +9,45 @@ 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 {";
+    moment_.print();
     for (PCursor<Input_command *> cc(*this); cc.ok(); cc++) 
        cc->print();
     mtor << "}\n";
 #endif
 }
-
+Real
+Commands_at::when()
+{
+    return moment_.when;
+}
 Commands_at::Commands_at(Real dt, Commands_at* prev)
+    : moment_(dt, (prev)? &prev->moment_ : 0)
 {
-    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;
+    if (prev&& !moment_.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];
+       moment_.set_meter(l,o);
+       bottom().add(get_grouping_command( moment_.one_beat,
+                                          get_default_grouping(l)));
+
     }
 }
 
-Commands_at::Commands_at(Commands_at const&src)
+Commands_at::Commands_at(Commands_at const&src) :
+    moment_(src.moment_)
 {
-    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);
     
@@ -73,18 +57,27 @@ Commands_at::Commands_at(Commands_at const&src)
 void
 Commands_at::setpartial(Real 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;
+    moment_.setpartial(p);
 }
+
 Real
 Commands_at::barleft()
 {
-    return  whole_per_measure-whole_in_measure;
+    return  moment_.barleft();
 }
 
+void
+Commands_at::parse(Staff_commands_at*s)
+{
+    s->moment_ = moment_;
+    for (PCursor<Input_command *> cc(*this); cc.ok(); cc++) {
+       if (cc->args.sz() &&  cc->args[0] !="") {
+           Command c = **cc;
+           s->add(c);
+           
+       }
+    }
+}
 /****************/
 
 void
@@ -93,11 +86,12 @@ Input_cursor::find_moment(Real w)
     Real last = when();
     while  (1) {
        if (! ok() ) {
-           *this = PCursor<Commands_at*>(list().bottom());
+           *this = list().bottom();
            Real dt = (w - when()) <? ptr()->barleft();
-           assert(dt >= 0);
+
            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 )
@@ -140,11 +134,11 @@ Input_commands::do_skip(int bars, Real wholes)
 {
     while (bars > 0) {
        Real b = ptr->barleft();
-       ptr.find_moment(ptr->when + b);
+       ptr.find_moment(ptr->when() + b);
        bars --;        
     }
     if (wholes) {
-       ptr.find_moment(ptr->when + wholes);
+       ptr.find_moment(ptr->when() + wholes);
     }
 }
 
@@ -154,21 +148,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->moment_.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];
        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 +176,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->moment_);
+           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;
 }
 
@@ -213,7 +211,7 @@ Input_commands::print() const
 Real
 Input_cursor::when()const
 {
-    return (*this)->when; 
+    return (*this)->when()
 }
 Input_cursor::Input_cursor(PCursor<Commands_at *>c)
     : PCursor<Commands_at*>(c)
diff --git a/src/moment.cc b/src/moment.cc
new file mode 100644 (file)
index 0000000..19f8571
--- /dev/null
@@ -0,0 +1,58 @@
+#include "moment.hh"
+#include "debug.hh"
+
+void
+Moment::print() const
+{    
+    mtor << " at "<<when<<'\n'; 
+    mtor << "meeter " << whole_per_measure << "/" << 1/one_beat 
+        << "\nposition "<< bars << ":" << whole_in_measure <<'\n';
+}
+void
+Moment::OK() const
+{
+    assert(whole_in_measure < whole_per_measure && 0 <= whole_in_measure);
+    assert(one_beat);
+}
+Moment::Moment(Real dt, Moment const *prev)
+{
+    if (prev) {
+       assert(dt >0);
+       *this = *prev;
+       when += + dt;
+       whole_in_measure += dt;
+       while ( whole_in_measure >= whole_per_measure ) {
+           whole_in_measure -= whole_per_measure;
+           bars ++;
+       }
+    } else {                           // default 4/4
+       whole_per_measure = 1;
+       whole_in_measure =0;
+       one_beat = 0.25;
+       when = 0.0;
+       bars = 0;
+    }  
+}
+
+void
+Moment::set_meter(int l, int o)
+{
+    assert(o);
+    one_beat = 1/Real(o);
+    whole_per_measure = Real(l) * one_beat;
+}
+
+void
+Moment::setpartial(Real 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;
+}
+Real
+Moment::barleft()
+{
+return    whole_per_measure-whole_in_measure;
+}