-#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();
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.
*/
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();
*/
// 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);
}
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++) {
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);
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();
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;
}