]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/p-score.cc
release: 1.1.28
[lilypond.git] / lily / p-score.cc
index dbf5d84525803e33ad8b3fed93e88620eccb250d..f7b4238de813b3a9a109178e72d999c89b499e40 100644 (file)
@@ -3,67 +3,61 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996, 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c) 1996,  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "super-elem.hh"
+#include "main.hh"
 #include "debug.hh"
 #include "lookup.hh"
 #include "spanner.hh"
 #include "paper-def.hh"
-#include "scoreline.hh"
+#include "line-of-score.hh"
+#include "pcursor.hh"
+#include "plist.hh"
+#include "p-col.hh"
 #include "p-score.hh"
-#include "tex-stream.hh"
 #include "p-col.hh"
-
+#include "scope.hh"
 #include "word-wrap.hh"
 #include "gourlay-breaking.hh"
+#include "paper-stream.hh"
+#include "paper-outputter.hh"
+#include "file-results.hh"
+#include "misc.hh"
 
-Paper_score::Paper_score (Paper_def*p)
-{
-  paper_l_ = p;
-  super_elem_l_   = new Super_elem;
-  typeset_element (super_elem_l_);
-}
+#if 1                  // has w32 advanced?
+                       // nope (cygwin-b20)
+
+// sucking Cygnus egcs - w32
+#include "list.tcc"
+#include "cursor.tcc"
 
-Paper_score::~Paper_score()
+#endif
+
+Paper_score::Paper_score ()
 {
-  super_elem_l_->unlink_all();
+  outputter_l_ =0;
+  Line_of_score * line_p = new Line_of_score;
+  typeset_unbroken_spanner (line_p);
+
+  line_l_ = line_p;
 }
 
-void
-Paper_score::typeset_element (Score_elem * elem_p)
+Paper_score::~Paper_score ()
 {
-  elem_p_list_.bottom().add (elem_p);
-  elem_p->pscore_l_ = this;
-
-  elem_p->add_processing();
 }
 
 void
-Paper_score::typeset_item (Item *i, PCol *c)
+Paper_score::typeset_element (Score_element * elem_p)
 {
-  assert (c && i);
-  int breakstat = i->break_status_i_;
-
-  if (breakstat == -1) 
-    {
-       c = c->prebreak_p_;
-  }else if (breakstat == 1) 
-    {
-       c = c->postbreak_p_;
-    }
-
-  c->add (i);
-  typeset_element (i);
+  elem_p_list_.bottom ().add (elem_p);
+  elem_p->pscore_l_ = this;
+  elem_p->add_processing ();
 }
 
 void
 Paper_score::typeset_broken_spanner (Spanner*span_p)
 {
-  span_p->left_col_l_->starters.bottom().add (span_p);
-  assert (span_p->left_col_l_->line_l_ == span_p->right_col_l_->line_l_);
-
   typeset_element (span_p);
 }
 
@@ -71,251 +65,243 @@ Paper_score::typeset_broken_spanner (Spanner*span_p)
 void
 Paper_score::typeset_unbroken_spanner (Spanner*span_p)
 {
-  span_p_list_.bottom().add (span_p);
+  span_p_list_.bottom ().add (span_p);
   span_p->pscore_l_=this;
 
-  if (span_p->left_col_l_) 
-       span_p->left_col_l_->used_b_ = true;
-  if ( span_p->right_col_l_)
-       span_p->right_col_l_->used_b_ = true;
-  
   // do not init start/stop fields. These are for broken spans only.
-  span_p->add_processing();
+  span_p->add_processing ();
 }
 
 
 void
-Paper_score::clean_cols()
+Paper_score::clean_cols ()
 {
   int rank_i = 0;
-  for (iter_top (col_p_list_,c); c.ok();)
-       if (!c->used_b()) 
-         {
-           delete c.remove_p();
-         }
-       else 
-         {
-           c->set_rank (rank_i++);
-           c++;
-         }
-}
-
-void
-Paper_score::add (PCol *p)
-{
-  p->pscore_l_ = this;
-  if (p->breakable_b())
+  for (iter_top (col_p_list_,c); c.ok ();)
     {
-       p->prebreak_p_->pscore_l_ = this;
-       p->postbreak_p_->pscore_l_ = this;
+      c->set_rank (rank_i++);
+      c++;
     }
-  col_p_list_.bottom().add (p);
 }
 
 void
-Paper_score::output (Tex_stream &ts)
+Paper_score::add_column (Paper_column *p)
 {
-  ts << "\n "<<  paper_l_->lookup_l()->texsetting << "%(Tex id)\n";
-  ts<< super_elem_l_->TeX_string();
-  ts << "\n\\EndLilyPondOutput";
+  col_p_list_.bottom ().add (p);
+  typeset_element(p);
 }
 
 
-void
-Paper_score::OK()const
-{
-#ifndef NDEBUG
-  for (iter_top (col_p_list_,cc); cc.ok(); cc++)
-       cc->OK();
-  for (PCursor<Score_elem*> i (elem_p_list_.top()); i.ok (); i++) 
-       i->OK();
-#endif
-}
 
 void
-Paper_score::print() const
-{    
+Paper_score::print () const
+{
 #ifndef NPRINT
-  if ( !check_debug)
-       return ;
+  if (!check_debug)
+    return ;
   DOUT << "Paper_score { ";
-  paper_l_->print();
   DOUT << "\n elements: ";
-  for (iter_top (elem_p_list_,cc); cc.ok(); cc++)      
-       cc->print();
+  for (iter_top (elem_p_list_,cc); cc.ok (); cc++)
+    cc->print ();
   DOUT << "\n unbroken spanners: ";
-  for (iter (span_p_list_.top(), i); i.ok (); i++)
-       i->print();
-  DOUT << "\ncolumns: ";
-   for (iter_top (col_p_list_,cc); cc.ok(); cc++)
-       cc->print();
-  
+  for (iter (span_p_list_.top (), i); i.ok  (); i++)
+    i->print ();
+
   DOUT << "}\n";
-#endif 
+#endif
 }
 
-void
-Paper_score::preprocess()
+PCursor<Paper_column *>
+Paper_score::find_col (Paper_column const *c) const
 {
-  super_elem_l_->breakable_col_processing();
-  super_elem_l_->pre_processing();
-}
+  Paper_column const *what = c;
 
-void
-Paper_score::postprocess()
-{
-  super_elem_l_->post_processing();
-  super_elem_l_->molecule_processing();
+  return col_p_list_.find ((Paper_column*)what);
 }
 
-PCursor<PCol *>
-Paper_score::find_col (PCol const *c)const
+
+
+
+Array<Column_x_positions>
+Paper_score::calc_breaking ()
 {
-  PCol const *what = c;
-  if (what->daddy_l_)
-       what = what->daddy_l_;
-  
-  return col_p_list_.find ((PCol*)what);
+  Break_algorithm *algorithm_p=0;
+  Array<Column_x_positions> sol;
+  bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
+
+  if (!try_wrap)
+    {
+      algorithm_p = new Gourlay_breaking ;
+      algorithm_p->set_pscore (this);
+      sol = algorithm_p->solve ();
+      delete algorithm_p;
+      if (! sol.size ())
+       {
+         warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
+         try_wrap = true;
+       }
+    }
+  if  (try_wrap)
+    {
+      algorithm_p = new Word_wrap;
+      algorithm_p->set_pscore (this);
+      sol = algorithm_p->solve ();
+      delete algorithm_p;
+    }
+  return sol;
 }
 
 
+
 void
-Paper_score::set_breaking (Array<Col_hpositions> const &breaking)
+Paper_score::process ()
 {
-  super_elem_l_->line_of_score_l_->set_breaking (breaking);
-  super_elem_l_->break_processing();
+  clean_cols ();
+  print ();
+  *mlog << _ ("Preprocessing elements...") << " " << flush;
+      line_l_->breakable_col_processing ();
+      line_l_->pre_processing ();
+  
+      *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
+      line_l_->space_processing ();
 
+  Array<Column_x_positions> breaking = calc_breaking ();
 
-  for (iter (span_p_list_.top(),i); i.ok ();) 
+  Paper_stream* paper_stream_p = paper_l_->paper_stream_p ();
+  outputter_l_ = paper_l_->paper_outputter_p (paper_stream_p, header_l_, origin_str_);
+
+  Link_array<Line_of_score> lines;
+  for (int i=0; i < breaking.size (); i++)
     {
-       Spanner *span_p = i.remove_p();
-       if (span_p->broken_b()) 
-         {
-           span_p->unlink();
-           delete span_p;
-       }else
-         {
-           typeset_broken_spanner (span_p);
-         }
+      Line_of_score *line_l = line_l_->set_breaking (breaking, i);
+      lines.push (line_l);
+      if (line_l != line_l_)
+       typeset_broken_spanner (line_l);
+      
     }
-  for (iter (elem_p_list_.top(),i); i.ok () ;) 
+
+  *mlog << "\nLine ... ";
+  for (int i=0; i < lines.size (); i++)
     {
-       Item *i_l =i->item();
-       if ( i_l && !i_l->pcol_l_->line_l_) 
-         {
-           i_l->unlink();
-           delete i.remove_p();
-         }
-       else
-           i++;
+      *mlog << '[' << flush;
+      
+      Line_of_score *line_l = lines[i];
+      line_l->break_processing ();
+      line_l->post_processing ();
+       *mlog << i << flush;
+      line_l->output_all ();
+       *mlog << ']' << flush;
+      remove_line (line_l);
     }
+  
+  // huh?
+  delete outputter_l_;
+  delete paper_stream_p;
+  outputter_l_ = 0;
 
-  for (iter_top (col_p_list_, i); i.ok(); i++)
-       i->clean_breakable_items();
+  *mlog << '\n' << flush;
 }
 
 void
-Paper_score::calc_breaking()
+Paper_score::remove_line (Line_of_score *l)
 {
-  Break_algorithm *algorithm_p;
-  Array<Col_hpositions> sol;
-  bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
-
-  if (!try_wrap) 
+  Link_array<Score_element> to_remove;
+  for (PCursor<Score_element*> i(elem_p_list_.top ()); i.ok (); )
     {
-       algorithm_p = new Gourlay_breaking ;
-       algorithm_p->set_pscore (this);
-       sol = algorithm_p->solve();
-       delete algorithm_p;
-       if ( ! sol.size()) 
-         {
-            warning ("Can not solve this casting problem exactly; revert to Word_wrap");
-           try_wrap = true;
-         }
+      if (i->line_l () == l)
+       to_remove.push (i.remove_p ());
+      else
+       i++;
     }
-  if  (try_wrap) 
+
+  for (PCursor<Spanner*> i (span_p_list_.top ()); i.ok (); )
     {
-       algorithm_p = new Word_wrap;    
-       algorithm_p->set_pscore (this);
-       sol = algorithm_p->solve();
-       delete algorithm_p;
+      Score_element *e = i.ptr ();
+      if (e->line_l () == l)
+       to_remove.push (i.remove_p ());
+      else
+       i++;
     }
-  set_breaking (sol);
-}
 
-void
-Paper_score::process()
-{
-  clean_cols();
-  print();
-  *mlog << "Preprocessing elements... " <<flush;
-  preprocess();
-  *mlog << "\nCalculating column positions ... " <<flush;
-  calc_breaking();
-  *mlog << "\nPostprocessing elements..." << endl;
-  postprocess();
-  
-#ifndef NDEBUGA
-  for (PCursor<Score_elem*> i (elem_p_list_.top()); i.ok (); i++) 
-       assert (i->status() >= 9);
-#endif
+  //  l->unlink_all ();
+  for (int i=0; i < to_remove.size (); i++)
+    {
+      to_remove[i]->unlink ();
+      assert (!to_remove[i]->linked_b ());
+      delete to_remove [i];
+    }
 }
 
 /** Get all breakable columns between l and r, (not counting l and r).  */
-Link_array<PCol>
-Paper_score::breakable_col_range (PCol*l,PCol*r)const
+Link_array<Paper_column>
+Paper_score::breakable_col_range (Paper_column*l, Paper_column*r) const
 {
-  Link_array<PCol> ret;
+  Link_array<Paper_column> ret;
 
-  PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
-  PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
+  PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
+  PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
 
   /*
     ugh! windows-suck-suck-suck.
-   */
-  while ( PCursor<PCol*>::compare (start,stop) < 0) 
+    */
+  while (PCursor<Paper_column*>::compare (start,stop) < 0)
     {
-       if (start->breakable_b())
-           ret.push (start);
-       start++;
+      if (start->breakable_b_)
+       ret.push (start);
+      start++;
     }
 
   return ret;
 }
-Link_array<PCol>
-Paper_score::col_range (PCol*l,PCol*r)const
+
+
+Link_array<Paper_column>
+Paper_score::col_range (Paper_column*l, Paper_column*r) const
 {
-  Link_array<PCol> ret;
-  
-  PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
-  PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
+  Link_array<Paper_column> ret;
+
+  PCursor<Paper_column*> start (l ? find_col (l)+1 : col_p_list_.top ());
+  PCursor<Paper_column*> stop (r ? find_col (r) : col_p_list_.bottom ());
   ret.push (l);
-  
+
   /*
     ugh! windows-suck-suck-suck.
-   */
-  while ( PCursor<PCol*>::compare (start,stop) < 0)
-       ret.push (start++);
+    */
+  while (PCursor<Paper_column*>::compare (start,stop) < 0)
+    ret.push (start++);
   ret.push (r);
   return ret;
 }
 
-Link_array<PCol>
-Paper_score::broken_col_range (PCol*l,PCol*r)const
+Link_array<Item>
+Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
 {
-  Link_array<PCol> ret;
+  Link_array<Item> ret;
+  Item const*l=l_item_l;
+  Item const*r=r_item_l;
 
-  PCursor<PCol*> start (l ? find_col (l)+1 : col_p_list_.top());
-  PCursor<PCol*> stop (r ? find_col (r) : col_p_list_.bottom());
+  // huh? see Item::left_right_compare ()
+  /*
+  while (! (dynamic_cast<Paper_column const *> (l)))
+    l = dynamic_cast<Item*> (l->axis_group_l_a_[X_AXIS]);
+
+  while (! (dynamic_cast<Paper_column const *> (r)))
+    r = dynamic_cast<Item*>(r->axis_group_l_a_[X_AXIS]);
+  */
+  l = l->column_l ();
+  r = r->column_l ();
   
+  PCursor<Paper_column*> start (l ? find_col ((Paper_column*)l)+1 : col_p_list_.top ());
+  PCursor<Paper_column*> stop (r ? find_col ((Paper_column*)r) : col_p_list_.bottom ());
+
   /*
     ugh! windows-suck-suck-suck.
     */
-  while ( PCursor<PCol*>::compare (start,stop) < 0) 
+  while (PCursor<Paper_column*>::compare (start,stop) < 0)
     {
-       if (start->breakable_b() && !start->line_l_)
-           ret.push (start);
-       start++;
+      if (start->breakable_b_ && !start->line_l_)
+       ret.push (start);
+      start++;
     }
 
   return ret;