void
Spacing_problem::OK() const
{
+#ifndef NDEBUG
Union_find connected(cols.sz());
for (int i=0; i < ideals.sz(); i++) {
for (int i = 0; i < cols.sz(); i++) {
assert( connected.equiv(0,i));
}
+#endif
}
bool
svec<Real>
Spacing_problem::solve() const
{
+ print();
OK();
assert(check_feasible());
- print();
+
/* optimalisatiefunctie */
Optimisation_problem lp(cols.sz());
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();
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
}
+
+
#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);
}
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
}
}
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
}
-#include <time.h>
+
#include "tstream.hh"
#include "score.hh"
#include "pscore.hh"
#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
}
/*
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();
}
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
*/
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();
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);
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();
sc->print();
}
mtor << "}\n";
+#endif
+}
+Score::Score()
+{
+ pscore_=0;
}
-
/****************************************************************/
Score_column::Score_column(Mtime w)
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
}
+
+