]> git.donarmstrong.com Git - lilypond.git/blobdiff - src/staff.cc
partial: 0.0.39-1.jcn
[lilypond.git] / src / staff.cc
index 825e878d8a8d8b11c39ea1270651a3b64e36b797..4f72617f5e2bd8badb53ee49793e27e6548d126f 100644 (file)
 #include "staff.hh"
 #include "score.hh"
 #include "voice.hh"
-#include "swalker.hh"
-#include "stcol.hh"
-#include "sccol.hh"
-#include "staffcommands.hh"
+#include "staff-walker.hh"
+#include "staff-column.hh"
+#include "score-column.hh"
+#include "voice-element.hh"
 #include "debug.hh"
+#include "musicalrequest.hh"
+#include "commandrequest.hh" // todo
+#include "midi-stream.hh"
 
 void
-Staff::add(PointerList<Voice*> &l)
+Staff::add(PointerList<Voice*> const &l)
 {
     for (iter_top(l,i); i.ok(); i++)
-       voices.bottom().add(i);
+       voice_list_.bottom().add(i);
 }
 
-void
-Staff::process_commands(Moment l)
-{
-    if (staff_commands_)
-       staff_commands_->clean(l);
-}
-
-Paperdef*
+Paper_def *
 Staff::paper() const
 {
-    return score_->paper_;
+    return score_l_->paper_p_;
 }
 
 void
 Staff::clean_cols()
 {
-    iter_top(cols,i);
+    iter_top(cols_,i);
     for(; i.ok(); ){
-       if (!i->score_column->used())
-           i.del();
+       if (!i->musical_column_l_->used_b())
+           i->musical_column_l_ = 0;
+       if (!i->command_column_l_->used_b())
+           i->command_column_l_ =0;
+       
+       if (!i->command_column_l_&& !i->musical_column_l_)
+           delete i.get_p();
        else
            i++;
     }
 }
 
 Staff_column *
-Staff::get_col(Moment w, bool mus)
-{
-    Score_column* sc = score_->find_col(w,mus);
-    assert(sc->when == w);
+Staff::get_col(Moment w, PCursor<Staff_column*> *last)
+{    
+    iter_top(cols_,i);
+    if (last && last->ok() && (*last)->when() <= w)
+       i = *last;
     
-    iter_top(cols,i);
     for (; i.ok(); i++) {
-       if (*i->score_column > *sc) // too far
-           break;
-       if (sc == i->score_column)
+       if (i->when() == w) {
+           if (last)
+               *last = i;
            return i;
+       } else if (i->when() > w)
+           break;
     }
 
-    /* post: *sc > *->score_column || !i.ok() */
-    Staff_column* newst = create_col(sc);
 
-    if (!i.ok()) {
-       cols.bottom().add(newst);
-       return cols.bottom();
-    }
-    
-    if (mus) {
-       i.insert(newst);
-       return newst;
-    }
-
-//  ;  assert((i-1).ok())
-    // todo!
+    PCursor<Score_column*> scorecolumns(score_l_->find_col(w, false));
+    Staff_column* staffcolumn_p = new Staff_column;
+    staffcolumn_p->staff_l_ = this;
+    Score_column* comcol_l  = scorecolumns++;
+    staffcolumn_p->set_cols(comcol_l, scorecolumns);
     
-    // making a fix at 2:30 am, with several beers drunk.
-    // but it works :-)
-    if ((i-1).ok()&& (i-1)->when() == newst->when()) {
+    if (!i.ok()) {
+       cols_.bottom().add(    staffcolumn_p);
+       i = cols_.bottom();
+    } else {
+       i.insert(staffcolumn_p);
        i--;
     }
-
-    i.insert(newst);
-    
-    return newst;
+    if (last)
+       *last = i;
+    return i;
 }
 
-
-
-/*
-    put all stuff grouped vertically in the Staff_cols
+/**
+  put all stuff grouped vertically in the Staff_cols.
+  Do the preprarations for walking the cols. not virtual
     */
 void
 Staff::setup_staffcols()
 {    
-    for (iter_top(voices,i); i.ok(); i++) {
+    for (iter_top(voice_list_,i); i.ok(); i++) {
+       PCursor<Staff_column*> last(cols_);
        Moment now = i->start;
-       for (iter_top(i->elts,ve); ve.ok(); ve++) {
-
-           Staff_column *sc=get_col(now,true);
-           sc->add(ve);
-           now += ve->duration;            
-       }       
-    }
-
-    for (iter_top(*staff_commands_,cc); cc.ok(); cc++) {
-       Staff_column *sc=get_col(cc->tdescription_.when,false);
-       sc->s_commands = cc;
-       sc->tdescription_ = new Time_description(cc->tdescription_);
-    }
-
-    iter_top(*staff_commands_,cc);
-    for (iter_top(cols,i); i.ok(); i++) {
-       while  ((cc+1).ok() && (cc+1)->when() < i->when())
-           cc++;
-
-       if(!i->tdescription_) {
-           if (cc->tdescription_.when == i->when())
-               i->tdescription_ = new Time_description(cc->tdescription_);
-           else
-               i->tdescription_ = new Time_description(
-                   i->when() - cc->when() ,&cc->tdescription_);
+       for (iter_top(i->elts,j); j.ok(); j++) {
+           
+           Staff_column *s_l= get_col(now, &last);
+           assert(now == s_l->when());
+           s_l->add(j);
+           now += j->duration;     
        }
-    }
-}
 
-void
-Staff::process()
-{
-    setup_staffcols();
+    }
     OK();
-    walk();
 }
 
 void
 Staff::OK() const
 {
 #ifndef NDEBUG
-    cols.OK();
-    voices.OK();
-    assert(score_);    
+    cols_.OK();
+    voice_list_.OK();
+    iter_top(cols_, i);
+    iter_top(cols_, j);
+    i++;
+    for (; i.ok(); j++,i++) {
+       assert(j->when () < i->when() );
+    }
+    assert(score_l_);
 #endif    
 }
 
@@ -141,31 +117,28 @@ Staff::OK() const
 Moment
 Staff::last() const
 {
-    Moment l = 0.0;
-    for (iter_top(voices,i); i.ok(); i++) {
+    Moment l = 0;
+    for (iter_top(voice_list_,i); i.ok(); i++) {
        l = l >? i->last();
     }
     return l;
 }
 
-
 void
 Staff::print() const
 {
 #ifndef NPRINT
     mtor << "Staff {\n";
-    for (iter_top(voices,i); i.ok(); i++) {
+    for (iter_top(voice_list_,i); i.ok(); i++) {
        i->print();     
     }
-    if (staff_commands_)
-       staff_commands_->print();
     mtor <<"}\n";
 #endif
 }
 
 Staff::Staff()
 {    
-    staff_commands_ = 0;
-    score_ =0;
-    pscore_=0;    
+    score_l_ =0;
+    pscore_l_ =0;
+    pstaff_l_ =0;
 }