]> git.donarmstrong.com Git - lilypond.git/blobdiff - score.cc
release: 0.0.3
[lilypond.git] / score.cc
index b2b520c4433da53043a42a0853bbc299d2ca1e91..f5e357ecdbab7bfa3b13794d3154a6691d96870d 100644 (file)
--- a/score.cc
+++ b/score.cc
@@ -1,4 +1,4 @@
-#include <time.h>
+
 #include "tstream.hh"
 #include "score.hh"
 #include "pscore.hh"
@@ -6,33 +6,57 @@
 #include "misc.hh"
 #include "debug.hh"
 
+void
+Score::add_command_seq(svec<Command *> com)
+{
+    if (!com.sz())
+       return;
+    Real when = com[0]->when;
+
+    PCursor<Command*> pc(commands_);    
+    while (pc.ok()&&pc->when <= when)
+       pc++;
+    
+    for (int i = 0; i < com.sz(); i++) {
+       assert(com[i]->when == when);
+       if (!pc.ok())
+           pc.add(com[i]);
+       else
+           pc.insert(com[i]);
+    }
+    
+}
+
 void
 Score::add(Command *c)
 {
+    svec<Command*> seq;    
     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));
+       
+       seq.add(new Command(k));
+       seq.add(new Command(*c));
        k.code = BREAK_MIDDLE;
-       commands_.bottom().add(new Command(k));
-       commands_.bottom().add(new Command(*c));
+       seq.add(new Command(k));
+       seq.add(new Command(*c));
        k.code = BREAK_POST;
-       commands_.bottom().add(new Command(k));
+       seq.add(new Command(k));
        k.code = BREAK_END;
-       commands_.bottom().add(new Command(k));
+       seq.add(new Command(k));
     }
     else
-       commands_.bottom().add(new Command(*c));
-    
+       seq.add(new Command(*c));
     
+    add_command_seq(seq);
 }
 
 void
@@ -53,43 +77,41 @@ Score::do_pcols()
 }
 /*
     this sux. Really makeshift.
+
+    first and last column should be breakable.
+    Remove any command past the last musical column.
     */
 void
 Score::do_miscs()
 {
     Command c;
 
-    c.when = 0.0;
+    {
+       Command c;
+       c.when = 0.0;
+       c.code = TYPESET;
+       c.args.add("BAR");
+       c.args.add("empty");
+       add(&c);
+    }
     
-    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();
+    Real l = last();    
+    while (bot.ok() && bot->when > l) {
+
+       mtor <<"removing "<< bot->code <<" at " << bot->when<<'\n';
+       bot.del();
+       bot = commands_.bottom();
+    }
+
+    if (bot->when != l || bot->code != BREAK_END) {
+       Command c;
+       c.code = TYPESET;
+       c.when = l;
+       c.args.add("BAR");
+       c.args.add("||");
+       add(&c);
     }
-   
-    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));
-    
    commands_.OK();
 }
 
@@ -106,11 +128,12 @@ void
 Score::clean_commands() 
 {
     Mtime l= last();
-    for (PCursor<Command*> cc(commands_); cc.ok(); cc++) {
+    for (PCursor<Command*> cc(commands_); cc.ok(); ) {
        if (cc->when > l){
-          mtor << "remming \n";
-           cc.remove();
-       }
+           mtor << "remming \n";
+           cc.del();
+       } else
+           cc++;
     }
 }
 void
@@ -143,14 +166,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();
@@ -218,19 +244,18 @@ void
 Score::output(String s)
 {
     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";
+    if (outfile=="")
+       outfile = s;
+    
+    *mlog << "output to " << outfile << "...\n";
+    Tex_stream the_output(outfile);    
     pscore_->output(the_output);
 }
 
 void
 Score::OK() const
 {
+#ifndef NDEBUG
     for (PCursor<Staff*> sc(staffs_); sc.ok(); sc++) {
        sc->OK();
        assert(sc->score_ == this);
@@ -243,12 +268,13 @@ Score::OK() const
     for (PCursor<Command*> cc(commands_); cc.ok() && (cc+1).ok(); cc++) {
        assert(cc->when <= (cc+1)->when);
     }
-    
+#endif    
 }
 
 void
 Score::print() const
 {
+#ifndef NPRINT
     mtor << "score {\n"; 
     for (PCursor<Staff*> sc(staffs_); sc.ok(); sc++) {
        sc->print();
@@ -257,8 +283,12 @@ Score::print() const
        sc->print();
     }
     mtor << "}\n";
+#endif
+}
+Score::Score()
+{
+    pscore_=0;
 }
-
 /****************************************************************/
 
 Score_column::Score_column(Mtime w)
@@ -276,10 +306,14 @@ Score_column::used() {
 void
 Score_column::print() const
 {
+    #ifndef NPRINT
     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";
+    #endif
 }
+
+