]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/score.cc
``slikken kreng''
[lilypond.git] / lily / score.cc
index 5463e829389d0fb828c1b9c88447a53ae3ac75d5..4f203c8033811ea92eb2a6ca87c9e3a2bed095a9 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
-#include "tex-stream.hh"
+
+#include <stdio.h>
+
+#include "ly-smobs.icc"
+
 #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-output.hh"
-#include "midi-def.hh"
-#include "p-col.hh"
-#include "score-reg.hh"
+#include "warn.hh"
+#include "music-output-def.hh"
+#include "music-output.hh"
 #include "music-iterator.hh"
 #include "music.hh"
-#include "music-list.hh"
-#include "input-register.hh"
+#include "global-translator.hh"
+#include "scm-hash.hh"
+#include "cpu-timer.hh"
+#include "main.hh"
+#include "paper-def.hh"
 
-extern String default_out_fn;
 
-Score::Score(Score const &s)
+/*
+  TODO: junkme.
+ */
+Score::Score ()
+  : Input ()
 {
-    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_ = 0;
+  music_ = SCM_EOL;
+  errorlevel_ = 0;
+
+  smobify_self ();
 }
 
-void
-Score::setup_music()
+/*
+  store point & click locations.
+  Global to save some time. (Sue us!)
+ */
+bool store_locations_global_b;
+
+Score::Score (Score const &s)
+  : Input (s)
 {
-    *mlog << "\nSetting up requests..." << flush;
-    
-    Score_register * score_reg =  
-       (Score_register*)lookup_reg("Score_register")->get_group_register_p();
-
-    score_reg->set_score (this);
-    Music_iterator * iter = Music_iterator::static_get_iterator_p(music_p_, 
-                                                                 score_reg);
-    iter->construct_children();
-
-    while ( iter->ok() || score_reg->extra_mom_pq_.size() ) {
-       Moment w = INFTY;
-       if (iter->ok() ) 
-           w = iter->next_moment();
-       
-       if (score_reg->extra_mom_pq_.size() && 
-           score_reg->extra_mom_pq_.front() <= w)
-           
-           w = score_reg->extra_mom_pq_.get();
-
-       mtor << "processing moment " << w << "\n";
-
-       Score_column* c1 = new Score_column(w);
-       Score_column* c2 = new Score_column(w);
-       
-       c1->musical_b_ = false;
-       c2->musical_b_ = true;
-       
-       cols_.bottom().add(c1);
-       cols_.bottom().add(c2);
-       score_reg->set_cols(c1,c2);
-       
-       score_reg->post_move_processing();
-       iter->next( w );
-       
-       score_reg->process_requests();
-       score_reg->do_announces();
-       score_reg->pre_move_processing();
+  music_ = SCM_EOL;
+  header_ = 0;
+  smobify_self ();
+
+  Music * m =unsmob_music (s.music_);
+  music_ =  m?m->clone ()->self_scm () : SCM_EOL;
+  scm_gc_unprotect_object (music_);
+  
+  for (int i=0; i < s.defs_.size (); i++)
+    defs_.push (s.defs_[i]->clone ());
+  errorlevel_ = s.errorlevel_;
+  if (s.header_)
+    {
+      header_ = (s.header_) ? new Scheme_hash_table (*s.header_): 0;
+
+      scm_gc_unprotect_object (header_->self_scm ());
     }
-    delete iter;
-    score_reg->do_removal_processing();
-    delete score_reg;
 }
 
-void
-Score::process()
+Score::~Score ()
 {
-    paper();
+  
 }
 
-void
-Score::paper()
-{
-    if (!paper_p_)
-       return;
 
-    if( errorlevel_i_){
-       // should we? hampers debugging. 
-       warning("Errors found, /*not processing score*/");
-//     return;
-    }
-    pscore_p_ = new PScore(paper_p_);
-    setup_music();
-    do_cols();
-    
-    clean_cols();    // can't move clean_cols() farther up.
-    print();
-    calc_idealspacing();
-
-    // debugging
-    OK();
-    *mlog << endl;
-    pscore_p_->process();
+/*
+  should enable  this to find weird mistakes? 
+*/
+#define PARANOIA
 
-    // output
-    paper_output();
-    
-}
+#ifdef PARANOIA
+#include <sys/resource.h>
+#endif
 
-/**
-  Remove empty cols, preprocess other columns.
-  */
 void
-Score::clean_cols()
+Score::run_translator (Music_output_def *odef)
 {
-#if 1
-    for (iter_top(cols_,c); c.ok(); ) {
-       if (!c->pcol_l_->used_b()) {
-           delete c.remove_p();
-       } else {
-           c->preprocess();
-           c++;
-       }
+
+
+#ifdef PARANOIA
+  if (verbose_global_b)
+    {
+      struct rlimit rls;
+
+      getrlimit (RLIMIT_STACK, &rls);
+      progress_indication (_f("stack size cur %d, max %d\n" ,rls.rlim_cur, rls.rlim_max));
     }
 #endif
-}
-
-PCursor<Score_column*>
-Score::find_col(Moment w, bool mus)
-{
-    iter_top( cols_,i);
-    
-    for (; i.ok(); i++) {
-       if (i->when() == w && i->musical_b_ == mus)
-           return i;
-       if (i->when() > w)
-           break;
+  
+  /*
+    We want to know if we want to store locations, since they take a
+    lot of overhead.
+  */
+  store_locations_global_b = (gh_eval_str ("point-and-click") !=  SCM_BOOL_F);
+  
+  Cpu_timer timer;
+  Global_translator * trans = odef->get_global_translator ();
+  if (!trans)
+    {
+      programming_error ("no toplevel translator");
+      return ;
+    }
+  progress_indication (_ ("Interpreting music..."));
+  Music * music = unsmob_music (music_);
+  
+  trans->final_mom_ = music->length_mom ();
+
+  Music_iterator * iter = Music_iterator::get_static_get_iterator (music);
+  iter->init_translator (music, trans);
+
+  iter->construct_children ();
+
+  if (! iter->ok ())
+    {
+      delete iter;
+      warning (_ ("Need music in a score"));
+      errorlevel_ =1;
+      return ;
     }
-    assert(false);
-    return i;
-}
 
-void
-Score::do_cols()    
-{
-    iter_top(cols_,i);
-    for (; i.ok(); i++) {
-       pscore_p_->add(i->pcol_l_);
+  trans->start ();
+  trans->run_iterator_on_me (iter);
+  delete iter;
+  trans->finish ();
+
+  if (errorlevel_)
+    {
+      // should we? hampers debugging.
+      warning (_ ("Errors found/*, not processing score*/"));
     }
-}
 
-Moment
-Score::last() const
-{    
-    Moment l = 0;
-    // TODO
-    return l;
-}
+  Music_output * output = trans->get_output ();
+  scm_gc_unprotect_object (trans->self_scm ());
+  
+  if (verbose_global_b)
+    progress_indication (_f ("elapsed time: %.2f seconds",  timer.read ()));
 
-void
-Score::set(Paper_def *pap_p)
-{
-    delete paper_p_;
-    paper_p_ = pap_p;
-}
+  if (!header_)
+    header_ = new Scheme_hash_table; // ugh
 
-void
-Score::set(Midi_def* midi_p)
-{    
-    delete midi_p_;
-    midi_p_ = midi_p;
+  output->header_ = header_;
+  output->origin_string_ =  location_string ();
+
+  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::OK() const
+Score::process ()
 {
-#ifndef NDEBUG
-    cols_.OK();
-    for (iter_top(cols_,cc); cc.ok() && (cc+1).ok(); cc++) {
-       assert(cc->when() <= (cc+1)->when());
-    }
-#endif    
-}
+  if (!unsmob_music (music_))
+    return;
 
 
-void
-Score::print() const
-{
-#ifndef NPRINT
-    mtor << "score {\n"; 
-    music_p_->print();
-    for (iter_top(cols_,i); i.ok(); i++) {
-       i->print();
+  for (int i=0; i < defs_.size (); i++)
+    {
+      if (no_paper_global_b 
+         && dynamic_cast<Paper_def*> (defs_[i]))
+       continue;
+      run_translator (defs_[i]);
     }
-    if (pscore_p_)
-       pscore_p_->print();
-    if (midi_p_)
-       midi_p_->print();
-    
-    mtor << "}\n";
-#endif
 }
 
-Score::Score()
-{
-    pscore_p_=0;
-    paper_p_ = 0;
-    midi_p_ = 0;
-    errorlevel_i_ = 0;
-}
 
-Score::~Score()
-{
-    delete music_p_;
-    delete pscore_p_;
-    delete paper_p_;
-    delete midi_p_;
-}
+
 
 void
-Score::paper_output()
+Score::add_output (Music_output_def *pap)
 {
-    if (paper_p_->outfile=="")
-       paper_p_->outfile = default_out_fn + ".out";
+  defs_.push (pap);
+}
 
-    if ( errorlevel_i_ ) { 
-       *mlog << "lilypond: warning: no output to: " << paper_p_->outfile 
-       << " (errorlevel=" << errorlevel_i_ << ")" << endl;
-        return;
-    }
+IMPLEMENT_SMOBS (Score);
+IMPLEMENT_DEFAULT_EQUAL_P (Score);
 
-    *mlog << "TeX output to " << paper_p_->outfile << " ...\n";
-    
-    Tex_stream the_output(paper_p_->outfile);
-    
-    the_output << "% outputting Score, defined at: " <<
-       location_str() << "\n";
-    pscore_p_->output(the_output);
-    
+
+SCM
+Score::mark_smob (SCM s)
+{
+  Score * sc = (Score*) SCM_CELL_WORD_1 (s);
+  if (sc->header_)
+    scm_gc_mark (sc->header_->self_scm ());
+  for (int i = sc->defs_.size (); i--;)
+    scm_gc_mark (sc->defs_[i]->self_scm ());
+  
+  return sc->music_;
 }
 
-void
-Score::midi()
+int
+Score::print_smob (SCM , SCM p, scm_print_state*)
 {
-#if 0
-    if (!midi_p_)
-       return;
+  scm_puts ("#<Score>", p);
 
-    if (midi_p_->outfile_str_ == "")
-       midi_p_->outfile_str_ = default_out_fn + ".midi";
-    
-    *mlog << "midi output to " << midi_p_->outfile_str_ << " ...\n";    
-    Midi_output(this, midi_p_);
-#endif
+  return 1;
 }
-