]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/p-score.cc
release: 1.1.28
[lilypond.git] / lily / p-score.cc
index 4ca78c5993b9cba8cc81d9c278e4c5537dd9758e..f7b4238de813b3a9a109178e72d999c89b499e40 100644 (file)
@@ -3,44 +3,55 @@
 
   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 "main.hh"
-#include "super-elem.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 "header.hh"
+#include "scope.hh"
 #include "word-wrap.hh"
 #include "gourlay-breaking.hh"
-#include "outputter.hh"
+#include "paper-stream.hh"
+#include "paper-outputter.hh"
+#include "file-results.hh"
+#include "misc.hh"
+
+#if 1                  // has w32 advanced?
+                       // nope (cygwin-b20)
+
+// sucking Cygnus egcs - w32
+#include "list.tcc"
+#include "cursor.tcc"
+
+#endif
 
 Paper_score::Paper_score ()
 {
   outputter_l_ =0;
-  super_elem_l_   = new Super_elem;
-  typeset_element (super_elem_l_);
+  Line_of_score * line_p = new Line_of_score;
+  typeset_unbroken_spanner (line_p);
+
+  line_l_ = line_p;
 }
 
 Paper_score::~Paper_score ()
 {
-  super_elem_l_->unlink_all ();
-  for (PCursor<Score_elem*> i(elem_p_list_.top()); i.ok(); i++)
-    assert(!i->linked_b());
 }
 
 void
-Paper_score::typeset_element (Score_elem * elem_p)
+Paper_score::typeset_element (Score_element * elem_p)
 {
   elem_p_list_.bottom ().add (elem_p);
   elem_p->pscore_l_ = this;
-
   elem_p->add_processing ();
 }
 
@@ -109,43 +120,13 @@ Paper_score::find_col (Paper_column const *c) const
 }
 
 
-void
-Paper_score::set_breaking (Array<Col_hpositions> const &breaking)
-{
-  super_elem_l_->line_of_score_l_->set_breaking (breaking);
-  super_elem_l_->break_processing ();
 
 
-  for (iter (span_p_list_.top (),i); i.ok  ();)
-    {
-      Spanner *span_p = i.remove_p ();
-      if (span_p->broken_b ())
-       {
-         span_p->unlink ();
-         delete span_p;
-       }else
-         {
-           typeset_broken_spanner (span_p);
-         }
-    }
-  for (iter (elem_p_list_.top (),i); i.ok  () ;)
-    {
-      Item *i_l =i->item ();
-      if (i_l && !i_l->line_l ())
-       {
-         i_l->unlink ();
-         delete i.remove_p ();
-       }
-      else
-       i++;
-    }
-}
-
-void
+Array<Column_x_positions>
 Paper_score::calc_breaking ()
 {
   Break_algorithm *algorithm_p=0;
-  Array<Col_hpositions> sol;
+  Array<Column_x_positions> sol;
   bool try_wrap = ! paper_l_->get_var ("castingalgorithm");
 
   if (!try_wrap)
@@ -156,7 +137,7 @@ Paper_score::calc_breaking ()
       delete algorithm_p;
       if (! sol.size ())
        {
-         warning (_("Can not solve this casting problem exactly; revert to Word_wrap"));
+         warning (_ ("Can't solve this casting problem exactly; revert to Word_wrap"));
          try_wrap = true;
        }
     }
@@ -167,60 +148,93 @@ Paper_score::calc_breaking ()
       sol = algorithm_p->solve ();
       delete algorithm_p;
     }
-  set_breaking (sol);
+  return sol;
 }
 
+
+
 void
 Paper_score::process ()
 {
   clean_cols ();
   print ();
-  *mlog << _("Preprocessing elements... ") <<flush;
-  super_elem_l_->breakable_col_processing ();
-  super_elem_l_->pre_processing ();
-  *mlog << _("\nCalculating column positions ... ") <<flush;
-  calc_breaking ();
-  *mlog << _("\nPostprocessing elements...") << endl;
-  super_elem_l_->post_processing ();
-  tex_output ();
-}
+  *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 ();
 
-void
-Paper_score::tex_output ()
-{
-  // output
-  String outname = paper_l_->outfile_str_ ;
-  if (outname.empty_b ())
-    outname = default_out_str_+ ".tex";
+  Paper_stream* paper_stream_p = paper_l_->paper_stream_p ();
+  outputter_l_ = paper_l_->paper_outputter_p (paper_stream_p, header_l_, origin_str_);
 
-  *mlog << _("TeX output to ") <<  outname << " ...\n";
+  Link_array<Line_of_score> lines;
+  for (int i=0; i < breaking.size (); i++)
+    {
+      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);
+      
+    }
 
-  Tex_stream tex_out (outname);
-  Tex_outputter interfees (&tex_out);
+  *mlog << "\nLine ... ";
+  for (int i=0; i < lines.size (); 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;
 
-  outputter_l_ = &interfees;
+  *mlog << '\n' << flush;
+}
 
-  tex_out << _("% outputting Score, defined at: ") << origin_str_ << "\n";
-  if (header_l_)
+void
+Paper_score::remove_line (Line_of_score *l)
+{
+  Link_array<Score_element> to_remove;
+  for (PCursor<Score_element*> i(elem_p_list_.top ()); i.ok (); )
     {
-      tex_out << header_l_->TeX_string();
+      if (i->line_l () == l)
+       to_remove.push (i.remove_p ());
+      else
+       i++;
     }
-  tex_out << paper_l_->TeX_output_settings_str ();
-  
 
-  if (experimental_features_global_b)
-    tex_out << "\\turnOnExperimentalFeatures%\n";
-  if (postscript_global_b)
-    tex_out << "\\turnOnPostScript%\n";
-  super_elem_l_->output_all ();
-  tex_out << "\n\\EndLilyPondOutput";
-  outputter_l_ = 0;
+  for (PCursor<Spanner*> i (span_p_list_.top ()); i.ok (); )
+    {
+      Score_element *e = i.ptr ();
+      if (e->line_l () == l)
+       to_remove.push (i.remove_p ());
+      else
+       i++;
+    }
+
+  //  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<Paper_column>
-Paper_score::breakable_col_range (Paper_column*l,Paper_column*r) const
+Paper_score::breakable_col_range (Paper_column*l, Paper_column*r) const
 {
   Link_array<Paper_column> ret;
 
@@ -239,6 +253,8 @@ Paper_score::breakable_col_range (Paper_column*l,Paper_column*r) const
 
   return ret;
 }
+
+
 Link_array<Paper_column>
 Paper_score::col_range (Paper_column*l, Paper_column*r) const
 {
@@ -264,12 +280,17 @@ Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
   Item const*l=l_item_l;
   Item const*r=r_item_l;
 
-  while (! l->is_type_b(Paper_column::static_name ()))
-    l = l->axis_group_l_a_[X_AXIS]->item ();
-
-  while (! r->is_type_b(Paper_column::static_name ()))
-    r = r->axis_group_l_a_[X_AXIS]->item ();
-
+  // 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 ());