]> git.donarmstrong.com Git - lilypond.git/blobdiff - score.cc
release: 0.0.6
[lilypond.git] / score.cc
index b2b520c4433da53043a42a0853bbc299d2ca1e91..097e2aa50d12f1d936f4f25045437999d2fd8793 100644 (file)
--- a/score.cc
+++ b/score.cc
-#include <time.h>
+#include "scommands.hh"
 #include "tstream.hh"
 #include "score.hh"
+#include "sccol.hh"
 #include "pscore.hh"
 #include "staff.hh"
-#include "misc.hh"
 #include "debug.hh"
+#include "paper.hh"
 
 void
-Score::add(Command *c)
+Score::set(Paperdef*p)
 {
-    if (c->code == TYPESET && c->args[0] == "BAR") {
-       /* should be encapsulated in BREAKs
-
-          THIS SUX.
-
-        */
-       Command k;
-       
-       k.when = c->when;
-       k.code = BREAK_PRE;
-       commands_.bottom().add(new Command(k));
-       commands_.bottom().add(new Command(*c));
-       k.code = BREAK_MIDDLE;
-       commands_.bottom().add(new Command(k));
-       commands_.bottom().add(new Command(*c));
-       k.code = BREAK_POST;
-       commands_.bottom().add(new Command(k));
-       k.code = BREAK_END;
-       commands_.bottom().add(new Command(k));
-    }
-    else
-       commands_.bottom().add(new Command(*c));
-    
-    
+    delete paper_;
+    paper_ = p;
 }
-
 void
-Score::add(Staff*s)
+Score::output(String s)
 {
-    s->score_ = this;
-    staffs_.bottom().add(s);    
+    OK();
+    if (paper_->outfile=="")
+       paper_->outfile = s;
+    
+    *mlog << "output to " << paper_->outfile << "...\n";
+    Tex_stream the_output(paper_->outfile);    
+    pscore_->output(the_output);
 }
 
 
 void
-Score::do_pcols()
-{
-    PCursor<Score_column*> sc(cols_);
-    for (;sc.ok(); sc++) {
-       pscore_->add(sc->pcol);
-    }
-}
-/*
-    this sux. Really makeshift.
-    */
-void
-Score::do_miscs()
+Score::process()
 {
-    Command c;
-
-    c.when = 0.0;
+    *mlog << "Processing ...";
+    set(commands_->parse(last()));
+    commands_->print();
     
-    c.code = BREAK_END;
-    commands_.top().insert(new Command(c));    
-    c.code = BREAK_POST;
-    commands_.top().insert(new Command(c));
-    c.code = BREAK_MIDDLE;
-    commands_.top().insert(new Command(c));
-    c.code = BREAK_PRE;
-    commands_.top().insert(new Command(c));
-
-    PCursor<Command*> bot(commands_.bottom());
-    c.when = last();    
-    while (bot.ok() && bot->when > c.when) {
-//       mtor <<"removing "<< bot->code <<" at " << bot->when<<'\n';
-       bot.remove();
-       bot = commands_.bottom();
-    }
-   
-    c.code = BREAK_PRE;
-    bot.add(new Command(c));
-    bot++;
-    c.code = BREAK_MIDDLE;
-    bot.add(new Command(c));
-   bot++;
-    c.code = BREAK_POST;
-    bot.add(new Command(c));
-   bot++;
-   c.code = BREAK_END;
-    bot.add(new Command(c));
+    if (!paper_)
+       paper_ = new Paperdef;
     
-   commands_.OK();
-}
-
-Mtime
-Score::last() const
-{    
-    Mtime l = 0;
-    for (PCursor<Staff*> stc(staffs_); stc.ok(); stc++) {
-       l = MAX(l, stc->last());
-    }
-    return l;
-}
-void
-Score::clean_commands() 
-{
-    Mtime l= last();
-    for (PCursor<Command*> cc(commands_); cc.ok(); cc++) {
-       if (cc->when > l){
-          mtor << "remming \n";
-           cc.remove();
-       }
-    }
-}
-void
-Score::process()
-{
-     do_miscs();
+    commands_->clean(last());
     
     /// distribute commands to disciples
     distribute_commands();
     
-    pscore_ = new PScore;
+    pscore_ = new PScore(paper_);
     for (PCursor<Staff*> sc(staffs_); sc.ok(); sc++) {
        sc->set_output(pscore_);
        sc->process();
@@ -133,9 +53,11 @@ Score::process()
     clean_cols();
     OK();
     //    print();
+    *mlog << "Calculating ... ";
     pscore_->calc_breaking();
     // TODO: calculate vertical structs
     // TODO: calculate mixed structs.
+    *mlog << "\n";
 }
 
 // remove empty cols with no spacing attached.
@@ -143,14 +65,17 @@ Score::process()
     */
 void
 Score::clean_cols()
-{
+{    
     for (PCursor<Staff * > sc(staffs_); sc.ok(); sc++)
        sc->clean_cols();
-    for (PCursor<Score_column*> c(cols_); c.ok(); c++) {
+    
+    for (PCursor<Score_column*> c(cols_); c.ok(); ) {
        if (!c->pcol->used) {
-//         mtor << "removing : "; c->print();
-           c.remove();
-       }
+           mtor << "removing : ";
+           c->print();
+           c.del();
+       } else
+           c++;
     }
     
     pscore_->clean_cols();
@@ -160,7 +85,7 @@ Score::clean_cols()
     */
 // todo
 PCursor<Score_column*>
-Score::create_cols(Mtime w)
+Score::create_cols(Real w)
 {
     Score_column* c1 = new Score_column(w);
     Score_column* c2 = new Score_column(w);
@@ -190,7 +115,7 @@ Score::create_cols(Mtime w)
 }
 
 Score_column*
-Score::find_col(Mtime w,bool mus)
+Score::find_col(Real w,bool mus)
 {
     PCursor<Score_column*> scc(cols_);
     for (; scc.ok(); scc++) {
@@ -209,28 +134,39 @@ void
 Score::distribute_commands(void)
 {
     for (PCursor<Staff*> sc(staffs_); sc.ok(); sc++) {
-       sc->add_commands(commands_);
+       sc->add_commands(*commands_);
     }
 }
+void
+Score::add(Staff*s)
+{
+    s->score_ = this;
+    staffs_.bottom().add(s);    
+}
 
 
 void
-Score::output(String s)
+Score::do_pcols()
 {
-    OK();
-    mtor << "output to " << s << "...\n";
-
-    Tex_stream the_output(s);
-    the_output << "% Automatically generated by LilyPond 0.0 at";
-    time_t t(time(0));
-    the_output << ctime(&t)<<"\n";
-    the_output << "% from input file ..\n";
-    pscore_->output(the_output);
+    PCursor<Score_column*> sc(cols_);
+    for (; sc.ok(); sc++) {
+       pscore_->add(sc->pcol);
+    }
+}
+Real
+Score::last() const
+{    
+    Real l = 0;
+    for (PCursor<Staff*> stc(staffs_); stc.ok(); stc++) {
+       l = MAX(l, stc->last());
+    }
+    return l;
 }
 
 void
 Score::OK() const
 {
+#ifndef NDEBUG
     for (PCursor<Staff*> sc(staffs_); sc.ok(); sc++) {
        sc->OK();
        assert(sc->score_ == this);
@@ -240,15 +176,15 @@ Score::OK() const
     for (PCursor<Score_column*> cc(cols_); cc.ok() && (cc+1).ok(); cc++) {
        assert(cc->when <= (cc+1)->when);
     }
-    for (PCursor<Command*> cc(commands_); cc.ok() && (cc+1).ok(); cc++) {
-       assert(cc->when <= (cc+1)->when);
-    }
-    
+    commands_->OK();
+#endif    
 }
 
+
 void
 Score::print() const
 {
+#ifndef NPRINT
     mtor << "score {\n"; 
     for (PCursor<Staff*> sc(staffs_); sc.ok(); sc++) {
        sc->print();
@@ -256,30 +192,28 @@ Score::print() const
     for (PCursor<Score_column*> sc(cols_); sc.ok(); sc++) {
        sc->print();
     }
+    commands_->print();
     mtor << "}\n";
+#endif
 }
 
-/****************************************************************/
-
-Score_column::Score_column(Mtime w)
+Score::Score()
 {
-    when = w;
-    pcol = new PCol(0);
-    musical = false;
+    pscore_=0;
+    paper_ = 0;
+    commands_ = new Score_commands;
 }
 
-bool
-Score_column::used() {
-    return pcol->used;
+Score::~Score()
+{
+    delete pscore_;
+    delete commands_;
+    delete paper_;
 }
 
 void
-Score_column::print() const
+Score::set(Score_commands*c)
 {
-    mtor << "Score_column { mus "<< musical <<" at " <<  when<<'\n';
-    mtor << " # symbols: " << pcol->its.size() << "\n";
-    mtor << "durations: [" ;
-    for (int i=0; i < durations.sz(); i++)
-       mtor << durations[i] << " ";
-    mtor << "]\n}\n";
+    delete commands_;
+    commands_ = c;
 }