]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.3
authorfred <fred>
Fri, 11 Oct 1996 22:53:22 +0000 (22:53 +0000)
committerfred <fred>
Fri, 11 Oct 1996 22:53:22 +0000 (22:53 +0000)
cols.cc
linespace.cc
qlp.cc
score.cc
staff.cc

diff --git a/cols.cc b/cols.cc
index e2a13f35f32b39c0f1e5ca884fb3741a1ecb8f4d..0de683cc55ade3586268e4678257e842ef880c90 100644 (file)
--- a/cols.cc
+++ b/cols.cc
@@ -11,7 +11,9 @@ Idealspacing::Idealspacing(const PCol * l,const PCol * r)
 void
 Idealspacing::OK() const
 {
+#ifndef NDEBUG
     assert(hooke >= 0 && left  && right);
+#endif    
 }
 
 Interval
@@ -31,6 +33,7 @@ int
 PCol::compare(const PCol &c1, const PCol &c2)
 {
     assert(false);
+    return 0 ;
 }
 
 void
@@ -64,8 +67,10 @@ PCol::PCol(PCol *parent) {
 
 PCol::~PCol()
 {
-    delete prebreak;
-    delete postbreak;  
+    if (prebreak)
+       delete prebreak;        // no recursion!
+    if (postbreak)
+       delete postbreak;       
 }
 
 void
index 91b0e3009cca11a1f9f353cfb00e5daa4691d331..402bd4074ebe16afb1d75f6ee5945366b2fc4804 100644 (file)
@@ -27,6 +27,7 @@ Spacing_problem::col_id(const PCol *w)const
 void
 Spacing_problem::OK() const
 {
+#ifndef NDEBUG
     Union_find connected(cols.sz());
 
     for (int i=0; i < ideals.sz(); i++) {
@@ -39,6 +40,7 @@ Spacing_problem::OK() const
     for (int i = 0; i < cols.sz(); i++) {
        assert( connected.equiv(0,i));
     }
+#endif    
 }
 
 bool
@@ -164,9 +166,10 @@ Spacing_problem::make_constraints(Optimisation_problem& lp) const
 svec<Real>
 Spacing_problem::solve() const
 {
+    print();
     OK();
     assert(check_feasible());
-    print();
+
     
     /* optimalisatiefunctie */        
     Optimisation_problem lp(cols.sz());
@@ -212,16 +215,19 @@ Spacing_problem::add_ideal(const Idealspacing *i)
 void
 Spacing_problem::print_ideal(const Idealspacing*id)const
 {
+#ifndef NPRINT
     int l = col_id(id->left);
     int r = col_id(id->right);
 
     mtor << "idealspacing { between " << l <<","<<r<<'\n';
     mtor << "distance "<<id->space<< " strength " << id->hooke << "}\n";
+#endif
 }
 
 void
 Spacing_problem::print() const
 {
+    #ifndef NPRINT
     for (int i=0; i < cols.sz(); i++) {
        mtor << "col " << i<<' ';
        cols[i].print();
@@ -229,14 +235,20 @@ Spacing_problem::print() const
     for (int i=0; i < ideals.sz(); i++) {
        print_ideal(ideals[i]);
     }
+    #endif
+    
 }
 
 void
 Colinfo::print() const
 {
+#ifndef NPRINT
     mtor << "column { ";
     if (fixed)
        mtor << "fixed at " << fixpos<<", ";
     mtor << "[" << minleft() << ", " << minright() << "]";
     mtor <<"}\n";
+#endif
 }
+
+
diff --git a/qlp.cc b/qlp.cc
index 9ad72de4a030f986e8549f4a11a68f41d4819dab..c76946e8668b07a318a5f162c218b44d5e2d62ff 100644 (file)
--- a/qlp.cc
+++ b/qlp.cc
@@ -1,18 +1,22 @@
 #include "debug.hh"
+#include "const.hh"
 #include "qlp.hh"
 #include "choleski.hh"
+
 void
 Mixed_qp::add_equality_cons(Vector v, double r)
 {
     assert(false);
 }
+
 void
 Mixed_qp::add_fixed_var(int i, Real r)
 {
     eq_cons.add(i);
     eq_consrhs.add(r);
 }
-   void
+
+void
 Ineq_constrained_qp::add_inequality_cons(Vector c, double r)
 {
     cons.add(c);
@@ -26,11 +30,13 @@ Ineq_constrained_qp::Ineq_constrained_qp(int novars):
 }
 
 void
-Ineq_constrained_qp::OK()const
+Ineq_constrained_qp::OK() const
 {
+#ifndef NDEBUG    
     assert(cons.sz() == consrhs.sz());
     Matrix Qdif= quad - quad.transposed();
-    assert(Qdif.norm() < EPS);
+    assert(Qdif.norm()/quad.norm() < EPS);
+#endif    
 }
      
 
@@ -95,29 +101,34 @@ Mixed_qp::Mixed_qp(int n)
 }
 
 void
-Mixed_qp::OK()const
+Mixed_qp::OK() const
 {
+#ifndef NDEBUG
     Ineq_constrained_qp::OK();
     assert(eq_consrhs.sz() == eq_cons.sz());
+#endif    
 }
 void
 Ineq_constrained_qp::print() const
 {
-
+#ifndef NPRINT
     mtor << "Quad " << quad;
     mtor << "lin " << lin <<"\n";
     for (int i=0; i < cons.sz(); i++) {
        mtor << "constraint["<<i<<"]: " << cons[i] << " >= " << consrhs[i];
        mtor << "\n";
     }
+#endif
 }
 void
 Mixed_qp::print() const
 {
+#ifndef NPRINT
     Ineq_constrained_qp::print();
     for (int i=0; i < eq_cons.sz(); i++) {
        mtor << "eq cons "<<i<<": x["<<eq_cons[i]<<"] == " << eq_consrhs[i]<<"\n";
     }
+#endif
 }
 
 
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
 }
+
+    
index 61699dccb20d6506a6c337d79ddcc37c1cf1ca1c..12bf074d04bb837e762212dcc3b93cdd549ec572 100644 (file)
--- a/staff.cc
+++ b/staff.cc
@@ -6,9 +6,11 @@ void
 Staff::clean_cols()
 {
     PCursor<Staff_column *> stc(cols);
-    for(; stc.ok(); stc++){
+    for(; stc.ok(); ){
        if (!stc->score_column->used())
-           stc.remove();
+           stc.del();
+       else
+           stc++;
     }
 }
 
@@ -122,11 +124,12 @@ Staff::process()
 void
 Staff::OK() const
 {
+#ifndef NDEBUG
     cols.OK();
     commands.OK();
     voices.OK();
-    assert(score_);
-    
+    assert(score_);    
+#endif    
 }
 
 
@@ -164,6 +167,7 @@ Staff_column::when() const
 {
     return score_column->when;
 }
+
 void
 Staff_column::add(Voice_element*ve)
 {
@@ -174,6 +178,7 @@ Staff_column::add(Voice_element*ve)
        
     v_elts.add(ve);
 }
+
 Staff_column::Staff_column(Score_column*s) {
     score_column = s;
 }