source file of the GNU LilyPond music typesetter
- (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+ (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
-#include "tex-stream.hh"
+#include "ly-smobs.icc"
+
+#include "scm-hash.hh"
#include "score.hh"
-#include "score-column.hh"
-#include "p-score.hh"
#include "debug.hh"
-#include "paper-def.hh"
-#include "main.hh"
-#include "source.hh"
-#include "source-file.hh"
-#include "midi-def.hh"
-#include "midi-stream.hh"
-#include "audio-score.hh"
-#include "p-col.hh"
+#include "music-output-def.hh"
+#include "music-output.hh"
#include "music-iterator.hh"
#include "music.hh"
#include "global-translator.hh"
-#include "header.hh"
+#include "scope.hh"
+#include "cpu-timer.hh"
+#include "main.hh"
+#include "paper-def.hh"
+
-extern String default_out_fn;
+/*
+ TODO: junkme.
+ */
Score::Score()
+ : Input()
{
header_p_ = 0;
- music_p_ = 0;
- pscore_p_ = 0;
- audio_score_p_ = 0;
- paper_p_ = 0;
- midi_p_ = 0;
+ music_ = SCM_EOL;
errorlevel_i_ = 0;
+ smobify_self ();
}
Score::Score (Score const &s)
+ : Input (s)
{
- assert (!pscore_p_);
- music_p_ = s.music_p_->clone();
- midi_p_ = new Midi_def (*s.midi_p_);
- paper_p_ = new Paper_def (*s.paper_p_);
- header_p_ = new Header (*s.header_p_);
+ music_ = SCM_EOL;
+
+ smobify_self ();
+
+ Music * m =unsmob_music (s.music_);
+ music_ = m?m->clone()->self_scm () : SCM_EOL;
+
+ for (int i=0; i < s.def_p_arr_.size (); i++)
+ def_p_arr_.push(s.def_p_arr_[i]->clone());
+ errorlevel_i_ = s.errorlevel_i_;
+ header_p_ = (s.header_p_) ? new Scheme_hash_table (*s.header_p_): 0;
}
Score::~Score()
{
- delete header_p_;
- delete music_p_;
- delete pscore_p_;
- delete audio_score_p_;
- delete paper_p_;
- delete midi_p_;
+
}
void
-Score::run_translator (Global_translator * trans_l)
+Score::run_translator (Music_output_def *odef_l)
{
- trans_l->set_score (this);
- Music_iterator * iter = Music_iterator::static_get_iterator_p (music_p_,
- trans_l);
- iter->construct_children();
+ Cpu_timer timer;
- if ( ! iter->ok())
+
+ Global_translator * trans_p = odef_l->get_global_translator_p();
+ if (!trans_p)
{
- delete iter;
- warning ("Need music in a score");
- errorlevel_i_ =1;
- return ;
+ programming_error ("no toplevel translator");
+ return ;
}
+ progress_indication ("\n" + _("Interpreting music..."));
+ Music * music = unsmob_music (music_);
- trans_l->start();
-
- while ( iter->ok() || trans_l->moments_left_i ())
+ trans_p->final_mom_ = music->length_mom ();
+
+
+ Music_iterator * iter = Music_iterator::static_get_iterator_p (music);
+ iter->init_translator(music, trans_p);
+
+ iter->construct_children();
+
+ if (! iter->ok())
{
- Moment w = infinity_mom;
- if (iter->ok())
- {
- w = iter->next_moment();
- DOUT << w;
- iter->print();
- }
- trans_l->modify_next (w);
- trans_l->prepare (w);
- trans_l->print();
-
- iter->process_and_next (w);
- trans_l->process();
+ delete iter;
+ warning (_("Need music in a score"));
+ errorlevel_i_ =1;
+ return ;
}
- delete iter;
- trans_l->finish();
-}
-void
-Score::process()
-{
- print();
- paper();
- midi();
-}
+ trans_p->start ();
+ trans_p->run_iterator_on_me (iter);
+ delete iter;
+ trans_p->finish ();
-void
-Score::midi()
-{
- if ( !midi_p_)
- return;
-
- *mlog << "\nCreating MIDI elements ..." << flush;
- audio_score_p_ = new Audio_score (this);
-
- Global_translator* score_trans= midi_p_->get_global_translator_p();
- run_translator (score_trans);
- delete score_trans;
-
if (errorlevel_i_)
{
- // should we? hampers debugging.
- warning ("Errors found, /*not processing score*/");
-// return;
+ // should we? hampers debugging.
+ warning (_ ("Errors found/*, not processing score*/"));
}
- *mlog << endl;
- midi_output();
-}
+ Music_output * output = trans_p->get_output_p();
+ scm_unprotect_object (trans_p->self_scm ());
+ if(verbose_global_b)
+ progress_indication (_f ("elapsed time: %.2f seconds", timer.read ()));
+
+ if (!header_p_)
+ header_p_ = new Scheme_hash_table; // ugh
+ Scope bla (header_p_);
+ output->header_l_ = &bla;
+ output->origin_str_ = location_str();
+
+ progress_indication ("\n");
+ output->process();
+ delete output ;
+
+ /*
+ force GC. At this point, GUILE may give back mallocated area to
+ the system.
+ */
+
+ scm_gc();
+}
+
void
-Score::paper()
+Score::process()
{
- if (!paper_p_)
- return;
-
- *mlog << "\nCreating elements ..." << flush;
- pscore_p_ = new Paper_score (paper_p_);
-
- Global_translator * score_trans= paper_p_->get_global_translator_p();
- run_translator (score_trans);
- delete score_trans;
-
- if (errorlevel_i_)
+ if (!unsmob_music (music_))
+ return;
+
+
+ for (int i=0; i < def_p_arr_.size (); i++)
{
- // should we? hampers debugging.
- warning ("Errors found, /*not processing score*/");
-// return;
+ if (no_paper_global_b
+ && dynamic_cast<Paper_def*>(def_p_arr_[i]))
+ continue;
+ run_translator (def_p_arr_[i]);
}
-
- *mlog << endl;
- pscore_p_->process();
-
- // output
- paper_output();
}
-void
-Score::midi_output()
-{
- if ( midi_p_->outfile_str_ == "")
- midi_p_->outfile_str_ = default_out_fn + ".midi";
- Midi_stream midi_stream (midi_p_->outfile_str_);
- *mlog << "MIDI output to " << midi_p_->outfile_str_ << " ..." << endl;
- audio_score_p_->output (midi_stream);
- *mlog << endl;
-}
void
-Score::paper_output()
+Score::add_output (Music_output_def *pap_p)
{
- if (paper_p_->outfile_str_=="")
- paper_p_->outfile_str_ = default_out_fn + ".tex";
-
- if ( errorlevel_i_)
- {
- *mlog << "lilypond: warning: no output to: " << paper_p_->outfile_str_
- << " (errorlevel=" << errorlevel_i_ << ")" << endl;
- return;
- }
-
- *mlog << "TeX output to " << paper_p_->outfile_str_ << " ...\n";
-
- Tex_stream the_output (paper_p_->outfile_str_);
-
- the_output << "% outputting Score, defined at: " <<
- location_str() << "\n";
- pscore_p_->output (the_output);
+ def_p_arr_.push(pap_p);
}
-void
-Score::print() const
+IMPLEMENT_SMOBS(Score);
+IMPLEMENT_DEFAULT_EQUAL_P(Score);
+IMPLEMENT_UNSMOB(Score, score);
+
+SCM
+Score::mark_smob (SCM s)
{
-#ifndef NPRINT
- DOUT << "score {\n";
- music_p_->print();
- if (midi_p_)
- midi_p_->print();
+ Score * sc = (Score*) SCM_CELL_WORD_1(s);
+ if (sc->header_p_)
+ scm_gc_mark (sc->header_p_->self_scm ());
+ for (int i = sc->def_p_arr_.size (); i--;)
+ scm_gc_mark (sc->def_p_arr_[i]->self_scm ());
- DOUT << "}\n";
-#endif
+ return sc->music_;
}
-void
-Score::set (Paper_def *pap_p)
+int
+Score::print_smob (SCM s, SCM p, scm_print_state*)
{
- delete paper_p_;
- paper_p_ = pap_p;
-}
+ scm_puts ("#<Score>", p);
-void
-Score::set (Midi_def* midi_p)
-{
- delete midi_p_;
- midi_p_ = midi_p;
+ return 1;
}
-