]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-1.0.1
authorfred <fred>
Sun, 24 Mar 2002 20:12:55 +0000 (20:12 +0000)
committerfred <fred>
Sun, 24 Mar 2002 20:12:55 +0000 (20:12 +0000)
lily/break.cc
lily/line-of-score.cc [new file with mode: 0644]
lily/p-score.cc
lily/score-element.cc [new file with mode: 0644]
lily/score-engraver.cc [new file with mode: 0644]
lily/super-elem.cc

index cc5c6f92a420487135a4c47b9c07496b01f34129..f6c374dce5c88f3cdb745131398adb0190422ba3 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996,  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c) 1996,  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "score-column.hh"
@@ -11,7 +11,7 @@
 #include "paper-def.hh"
 #include "spring-spacer.hh"
 #include "debug.hh"
-#include "scoreline.hh"
+#include "line-of-score.hh"
 #include "p-score.hh"
 #include "p-col.hh"
 #include "cpu-timer.hh"
 String
 Col_stats::str () const
 {
-  String s (count_i_);
-  s += _ (" lines");
-  if  (count_i_)
-    s += String (Real (cols_i_)/count_i_, _(", (with an average of %.1f columns)"));
-
+  String s;
+  if (!count_i_)
+    s = _ ("0 lines");
+  else if (count_i_ == 1)
+    s = _f ("1 line (of %.0f columns)", (Real)cols_i_/count_i_);
+  else
+    s = _f ("%d lines (with an average of %.1f columns)", 
+      count_i_, (Real)cols_i_/count_i_);
   return s;
 }
 
@@ -103,7 +106,7 @@ Break_algorithm::generate_spacing_problem (Line_of_cols curline, Interval line)
   Spring_spacer * sp= (Spring_spacer*) (*get_line_spacer) (); // ugh
 
   sp->paper_l_ = pscore_l_->paper_l_;
-  sp->add_column (curline[0], true, line.min ());
+  sp->add_column (curline[0], true, line[LEFT]);
   for (int i=1; i< curline.size ()-1; i++)
     sp->add_column (curline[i]);
 
@@ -153,7 +156,7 @@ void
 Break_algorithm::problem_OK () const
 {
   if (!pscore_l_->col_p_list_.size ())
-    error (_("Score does not have any columns"));
+    error (_("score does not have any columns"));
   OK ();
 }
 
@@ -169,18 +172,18 @@ Break_algorithm::OK () const
 #endif
 }
 
-Array<Col_hpositions>
+Array<Column_x_positions>
 Break_algorithm::solve () const
 {
   Cpu_timer timer;
 
-  Array<Col_hpositions> h= do_solve ();
+  Array<Column_x_positions> h= do_solve ();
 
   if (approx_stats_.count_i_)
-    *mlog << _ ("\n(Approximated: ") << approx_stats_.str () << ")\n";
+    *mlog << '\n' << _f ("approximated: %s", approx_stats_.str ()) << endl;
   if (exact_stats_.count_i_)
-    *mlog << _ ("(Calculated exactly: ") << exact_stats_.str () << ")\n";
-  *mlog << _ ("Time: ") << String (timer.read (), "%.2f") << _ (" seconds\n");
+    *mlog << _f ("calculated exactly: %s", exact_stats_.str ()) << endl;
+  *mlog << _f ("time: %.2f seconds",  timer.read ()) << endl;
 
   return h;
 }
diff --git a/lily/line-of-score.cc b/lily/line-of-score.cc
new file mode 100644 (file)
index 0000000..164d079
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+  scoreline.cc -- implement Line_of_score
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1996,  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#include "line-of-score.hh"
+#include "dimension.hh"
+#include "spanner.hh"
+#include "atom.hh"
+#include "paper-def.hh"
+#include "p-col.hh"
+#include "p-score.hh"
+
+
+Line_of_score::Line_of_score()
+{
+  error_mark_b_ = 0;
+}
+
+
+IMPLEMENT_IS_TYPE_B1(Line_of_score,Spanner);
+
+void
+Line_of_score::add_element (Score_element*e)
+{
+  // avoid excess dependencies.
+  if (!(e->axis_group_l_a_[0] || e->axis_group_l_a_[1]))
+    add_dependency (e);
+}
+
+bool
+Line_of_score::contains_b (Paper_column const* c) const
+{
+  return cols.find_l ((Paper_column*)c);
+}
+
+void
+Line_of_score::set_breaking (Array<Column_x_positions> const &breaking)
+{
+  for (int j=0; j < breaking.size(); j++) 
+    {
+      const Array<Paper_column*> &curline (breaking[j].cols);
+      const Array<Paper_column*> &errors (breaking[j].error_col_l_arr_);
+      const Array<Real> &config (breaking[j].config);
+       
+      for (int i=0; i < errors.size(); i++)
+       errors[i]->error_mark_b_ = true;
+
+      Line_of_score *line_l=0;
+      Line_of_score *line_p =0;
+       
+      if (breaking.size() >1) 
+       {
+         line_p = (Line_of_score*)clone()->access_Spanner ();
+         line_l = line_p;
+       }
+      else 
+       line_l =  this;
+       
+      ((Array<Paper_column*> &)line_l->cols) = curline;
+      line_l->set_bounds(LEFT,curline[0]);
+      
+      line_l->set_bounds(RIGHT,curline.top());
+       
+      if (line_p) 
+       {
+         pscore_l_->typeset_broken_spanner (line_p);
+         broken_into_l_arr_.push (line_p);
+       }
+
+      for (int i=0; i < curline.size(); i++)
+       {
+         curline[i]->translate_axis (config[i],X_AXIS);
+         curline[i]->line_l_ = (Line_of_score*)line_l;
+       }
+    }
+}
+
+
+void
+Line_of_score::break_into_pieces (bool)
+{
+  
+}
+
+Link_array<Line_of_score>
+Line_of_score::get_lines() const
+{
+  Link_array<Line_of_score> ret;
+
+  if (broken_into_l_arr_.size())
+    for (int i=0; i < broken_into_l_arr_.size(); i++) 
+      {
+       ret.push ((Line_of_score*)broken_into_l_arr_[i]);
+      }
+  else 
+    ret.push ((Line_of_score*)this);   // ugh
+  
+  return ret;
+}
+
+void
+Line_of_score::do_print() const
+{
+  Spanner::do_print();
+}
+
+Interval
+Line_of_score::do_width() const
+{ 
+  return Spanner::do_width();
+}
+
+Link_array<Score_element>
+Line_of_score::get_extra_dependencies () const
+{
+  Link_array<Score_element> r;
+  for (int i=0; i < cols.size (); i++)
+    r.push (cols[i]);
+  return r;
+}
+
+void
+Line_of_score::do_unlink () 
+{
+  Spanner::do_unlink ();
+  for (int i=0; i < cols.size (); i++)
+    cols[i]->line_l_ =0;
+  cols.set_size (0);
+}
+
+
+void
+Line_of_score::do_junk_links () 
+{
+  cols.set_size (0);
+}
index 51c9a4b019274bb495fcd7368cb34a6f3bd0f501..bd7ec060e049239b06322958e4018f8400776c38 100644 (file)
@@ -3,16 +3,16 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996,  1997--1998 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 "super-element.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 "header.hh"
 #include "word-wrap.hh"
 #include "gourlay-breaking.hh"
-#include "outputter.hh"
+#include "tex-outputter.hh"
 #include "file-results.hh"
+#include "misc.hh"
+
 // sucking Cygnus egcs - w32
 #include "list.tcc"
 #include "cursor.tcc"
@@ -38,12 +40,12 @@ Paper_score::Paper_score ()
 Paper_score::~Paper_score ()
 {
   super_elem_l_->unlink_all ();
-  for (PCursor<Score_elem*> i(elem_p_list_.top()); i.ok(); i++)
+  for (PCursor<Score_element*> 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;
@@ -117,31 +119,41 @@ Paper_score::find_col (Paper_column const *c) const
 
 
 void
-Paper_score::set_breaking (Array<Col_hpositions> const &breaking)
+Paper_score::set_breaking (Array<Column_x_positions> 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 ())
+      if (span_p->broken_b ()
+         || !((Score_element*)span_p)->line_l ())
        {
          span_p->unlink ();
+#if 0
+         int sz = span_p->class_size();
+         set_frobnify (span_p,sz);
+#endif
          delete span_p;
-       }else
-         {
-           typeset_broken_spanner (span_p);
-         }
+       }
+      else 
+       {
+         typeset_broken_spanner (span_p);
+       }
     }
   for (iter (elem_p_list_.top (),i); i.ok  () ;)
     {
-      Item *i_l =i->item ();
+      Item *i_l =i->access_Item ();
       if (i_l && !i_l->line_l ())
        {
          i_l->unlink ();
-         delete i.remove_p ();
+         Score_element * item_p= i.remove_p ();
+#if 0
+         int sz = item_p->class_size ();
+         set_frobnify (item_p, sz);
+#endif
+         delete item_p;
        }
       else
        i++;
@@ -152,7 +164,7 @@ void
 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)
@@ -163,7 +175,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;
        }
     }
@@ -182,14 +194,15 @@ Paper_score::process ()
 {
   clean_cols ();
   print ();
-  *mlog << _("Preprocessing elements... ") <<flush;
+  *mlog << _ ("Preprocessing elements...") << " " << flush;
   super_elem_l_->breakable_col_processing ();
   super_elem_l_->pre_processing ();
   
-  *mlog << _("\nCalculating column positions ... ") <<flush;
+  *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
   super_elem_l_->space_processing ();
   calc_breaking ();
-  *mlog << _("\nPostprocessing elements...") << endl;
+  print ();
+  *mlog << _ ("Postprocessing elements...") << " " << endl;
   super_elem_l_->post_processing ();
   tex_output ();
 }
@@ -206,22 +219,31 @@ Paper_score::tex_output ()
       int def = paper_l_->get_next_default_count ();
       if (def)
        {
-         base_outname += "-" + String(def);
+         base_outname += "-" + to_str (def);
        }
     }
 
-  String outname = base_outname + ".tex";
+  String outname = base_outname;
+  if (outname != "-")
+     outname += ".tex";
   target_str_global_array.push (outname);
 
-  
-  *mlog << _("TeX output to ") <<  outname << " ...\n";
+  *mlog << _f ("TeX output to %s...", 
+    outname == "-" ? String ("<stdout>") : outname ) << endl;
 
   Tex_stream tex_out (outname);
   Tex_outputter interfees (&tex_out);
 
   outputter_l_ = &interfees;
 
-  tex_out << _("% outputting Score, defined at: ") << origin_str_ << "\n";
+  if (header_global_p)
+    {
+      tex_out << header_global_p->TeX_string ();
+    }
+    
+  
+  tex_out << _ ("% outputting Score, defined at: ") << origin_str_ << '\n';
+
   if (header_l_)
     {
       tex_out << header_l_->TeX_string();
@@ -231,6 +253,7 @@ Paper_score::tex_output ()
 
   if (experimental_features_global_b)
     tex_out << "\\turnOnExperimentalFeatures%\n";
+
   tex_out << "\\turnOnPostScript%\n";
   super_elem_l_->output_all ();
   tex_out << "\n\\EndLilyPondOutput";
@@ -239,7 +262,7 @@ Paper_score::tex_output ()
 
 /** 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;
 
@@ -258,6 +281,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
 {
@@ -284,10 +309,10 @@ Paper_score::broken_col_range (Item const*l_item_l, Item const*r_item_l) const
   Item const*r=r_item_l;
 
   while (! l->is_type_b(Paper_column::static_name ()))
-    l = l->axis_group_l_a_[X_AXIS]->item ();
+    l = l->axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ();
 
   while (! r->is_type_b(Paper_column::static_name ()))
-    r = r->axis_group_l_a_[X_AXIS]->item ();
+    r = r->axis_group_l_a_[X_AXIS]->access_Score_element ()->access_Item ();
 
   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 ());
diff --git a/lily/score-element.cc b/lily/score-element.cc
new file mode 100644 (file)
index 0000000..94b6da1
--- /dev/null
@@ -0,0 +1,406 @@
+/*
+  score-elem.cc -- implement Score_element
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+
+#include <string.h>
+
+#include "tex-outputter.hh"
+#include "p-score.hh"
+#include "paper-def.hh"
+#include "lookup.hh"
+#include "molecule.hh"
+#include "score-element.hh"
+#include "debug.hh"
+#include "tex.hh"
+#include "dimension.hh"
+#include "spanner.hh"
+#include "line-of-score.hh"
+#include "item.hh"
+#include "p-col.hh"
+#include "molecule.hh"
+#include "misc.hh"
+
+#define PARANOID
+
+Score_element::Score_element()
+{
+  transparent_b_ = false;
+  size_i_ = 0;
+  pscore_l_=0;
+  status_i_ = 0;
+}
+
+Score_element::Score_element (Score_element const&s)
+  :  Directed_graph_node (s), Graphical_element (s)
+{
+  /* called from derived ctor, so most info points to the same deps
+     as (Directed_graph_node&)s. Nobody points to us, so don't copy
+     dependents.      
+   */
+  copy_edges_out (s);
+  transparent_b_ = s.transparent_b_;
+  status_i_ = s.status_i_;
+  pscore_l_ = s.pscore_l_;
+  size_i_ = s.size_i_;
+}
+
+
+  
+
+Score_element::~Score_element()
+{
+  assert (status_i_ >=0);
+}
+
+Score_element*
+Score_element::dependency (int i) const
+{
+  return (Score_element*) get_out_edge_arr ()[i];
+}
+
+int
+Score_element::dependency_size () const
+{
+  return get_out_edge_arr ().size ();
+}
+
+Score_element*
+Score_element::dependent (int i) const
+{
+  return (Score_element*) get_in_edge_arr()[i];
+}
+
+int
+Score_element::dependent_size() const
+{
+  return get_in_edge_arr().size ();
+}
+
+
+
+Interval
+Score_element::do_width() const 
+{
+  Interval r;
+
+  Molecule*m = brew_molecule_p();
+  r = m->extent().x ();
+  delete m;
+  
+  return r;
+}
+
+Interval
+Score_element::do_height() const 
+{
+  Interval r;
+  Molecule*m = brew_molecule_p();
+  r = m->extent().y ();
+  delete m;
+  return r;
+}
+
+
+/*
+  STANDARD METHS
+ */
+void
+Score_element::print() const
+{
+#ifndef NPRINT
+  DOUT << name() << "{\n";
+  DOUT << "dets: " << dependent_size() << "dependencies: " << 
+    dependency_size();
+  Graphical_element::do_print ();
+  do_print();
+  
+  DOUT <<  "}\n";
+#endif
+}
+
+
+Paper_def*
+Score_element::paper()  const
+{
+  assert (pscore_l_);
+  return pscore_l_->paper_l_;
+}
+
+
+Lookup *
+Score_element::lookup_l () const
+{
+  return pscore_l_->paper_l_->lookup_l (size_i_);
+}
+
+void
+Score_element::add_processing()
+{
+  if (status_i_)
+    return;
+  status_i_ ++;
+  do_add_processing();
+}
+
+
+void
+Score_element::calcalute_dependencies (int final, int busy,
+                                   Score_element_method_pointer funcptr)
+{
+  if (status_i_ >= final)
+    return;
+
+  assert (status_i_!= busy);
+  status_i_= busy;
+
+  for (int i=0; i < dependency_size(); i++)
+    dependency (i)->calcalute_dependencies (final, busy, funcptr);
+
+  Link_array<Score_element> extra (get_extra_dependencies());
+  for (int i=0; i < extra.size(); i++)
+    extra[i]->calcalute_dependencies (final, busy, funcptr);
+  
+  invalidate_cache (X_AXIS);
+  invalidate_cache (Y_AXIS);
+  (this->*funcptr)();
+  status_i_= final;
+}
+
+void
+Score_element::do_brew_molecule () 
+{
+  if (transparent_b_)
+    return;
+  Molecule *output= brew_molecule_p ();
+  pscore_l_->outputter_l_->output_molecule (output, absolute_offset (), name());
+  delete output;
+}
+
+/*
+  
+  VIRTUAL STUBS
+
+ */
+
+void
+Score_element::do_break_processing()
+{
+  handle_broken_dependencies();
+}
+
+void
+Score_element::do_post_processing()
+{
+}
+
+void
+Score_element::do_breakable_col_processing()
+{
+  handle_prebroken_dependencies();
+}
+
+void
+Score_element::do_pre_processing()
+{
+}
+
+void
+Score_element::do_space_processing ()
+{
+}
+
+void
+Score_element::do_add_processing()
+{
+}
+
+void
+Score_element::do_substitute_dependency (Score_element*,Score_element*)
+{
+}
+void
+Score_element::do_substitute_dependent (Score_element*,Score_element*)
+{
+}
+
+void
+Score_element::do_unlink()
+{
+}
+
+void
+Score_element::do_junk_links()
+{
+}
+
+IMPLEMENT_IS_TYPE_B1(Score_element, Graphical_element);
+
+Molecule*
+Score_element::brew_molecule_p() const
+{
+  Atom a (lookup_l ()->fill (Box (Interval (0,0), Interval (0,0))));
+  return new Molecule (a);
+}
+
+
+Line_of_score *
+Score_element::line_l() const
+{
+  return 0;
+}
+
+/*
+  
+  DEPENDENCIES
+
+  */
+
+void
+Score_element::remove_dependency (Score_element*e)
+{
+  remove_edge_out (e);
+  substitute_dependency (e, 0);
+}
+
+void
+Score_element::add_dependency (Score_element*e)
+{
+  Directed_graph_node::add_edge (e);
+}
+void
+Score_element::substitute_dependency (Score_element* old, Score_element* new_l)
+{
+  do_substitute_dependency (old,new_l);
+  old->do_substitute_dependent (this, 0);
+}
+
+void
+Score_element::handle_broken_dependencies()
+{
+  Line_of_score *line  = line_l();
+  if (!line)
+    return;
+
+  Link_array<Score_element> remove_us_arr;
+  for (int i=0; i < dependency_size(); i++) 
+    {
+      Score_element * elt = dependency (i);
+      if (elt->line_l() != line)
+       {
+         if (elt->access_Spanner ()) 
+           {
+             Spanner * sp = elt->access_Spanner ();
+             Spanner * broken = sp->find_broken_piece (line);
+             substitute_dependency (sp, broken);
+
+             add_dependency (broken);
+           }
+         else if (elt->access_Item ())
+           {
+             Item * my_item = elt->access_Item ()->find_prebroken_piece (line);
+               
+             substitute_dependency (elt, my_item);
+             if (my_item)
+               add_dependency (my_item);
+           }
+         remove_us_arr.push (elt);
+       }
+    }
+
+  remove_us_arr.default_sort();
+  remove_us_arr.uniq();
+  for (int i=0;  i <remove_us_arr.size(); i++)
+    remove_dependency (remove_us_arr[i]);
+}
+
+/*
+  This sux.
+
+  unlike with spanners, the number of items can increase
+
+  span: item1
+
+  becomes
+
+  span: item1 item2 item3
+
+  How to let span (a derived class) know that this happened?
+ */
+void
+Score_element::handle_prebroken_dependencies()
+{
+  Link_array<Score_element> old_arr, new_arr;
+  
+  for (int i=0; i < dependency_size(); i++) 
+    {
+      Score_element * elt = dependency (i);
+      Item *it_l = elt->access_Item ();
+      if (it_l && it_l->breakable_b_)
+       if (access_Item ()) 
+         {
+           Score_element *new_l = it_l->find_prebroken_piece (access_Item ()->break_status_dir_);
+           if (new_l != elt) 
+             {
+               new_arr.push (new_l);
+               old_arr.push (elt);
+             }
+         }
+       else 
+         {
+           new_arr.push (it_l->broken_to_drul_[LEFT]);
+           old_arr.push (0);
+           old_arr.push (0);           
+           new_arr.push (it_l->broken_to_drul_[RIGHT]);                
+         }
+    }
+  
+  for (int i=0;  i < old_arr.size(); i++)
+    if (old_arr[i])
+      substitute_dependency (old_arr[i], new_arr[i]);
+}
+
+
+void
+Score_element::junk_links ()
+{
+  Directed_graph_node::junk_links();
+  Graphical_element::junk_links ();
+  do_junk_links();
+}
+
+void
+Score_element::unlink()
+{
+  do_unlink();
+  while (dependency_size()) 
+    {
+      do_substitute_dependency (dependency (0),0);
+      remove_edge_out_idx (0);
+    }
+  while  (dependent_size()) 
+    {
+      dependent (0)->remove_dependency (this);
+    }
+  Graphical_element::unlink ();
+}
+
+
+Link_array<Score_element>
+Score_element::get_extra_dependencies() const
+{
+  Link_array<Score_element> empty;
+  return empty;
+}
+
+bool
+Score_element::linked_b() const
+{
+  return get_extra_dependencies().size() || 
+    dependency_size();
+}
diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc
new file mode 100644 (file)
index 0000000..1df1ecd
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+  score-grav.cc -- implement Score_engraver
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#include "super-element.hh"
+#include "line-of-score.hh"
+#include "debug.hh"
+#include "item.hh"
+#include "score-engraver.hh"
+#include "p-score.hh"
+#include "musical-request.hh"
+#include "score-column.hh"
+#include "command-request.hh"
+#include "paper-def.hh"
+
+
+Score_engraver::Score_engraver()
+{
+  break_penalty_i_ = 0;
+  scoreline_l_ =0;
+  command_column_l_ =0;
+  musical_column_l_ =0;
+  breaks_i_ =0;
+  pscore_p_ = 0;
+}
+void
+Score_engraver::prepare (Moment w)
+{
+  Global_translator::prepare (w);
+  set_columns (new Score_column (w),  new Score_column (w));
+  
+  break_penalty_i_ = 0;
+  post_move_processing();
+}
+
+void
+Score_engraver::finish()
+{
+  if ((breaks_i_%8))
+    *mlog << "[" << breaks_i_ << "]" << flush;
+   
+  check_removal();
+  removal_processing();
+}
+
+void
+Score_engraver::do_creation_processing()
+{
+  scoreline_l_ = pscore_p_->super_elem_l_->line_of_score_l_;
+  scoreline_l_->set_bounds(LEFT,get_staff_info().command_pcol_l ());
+  command_column_l_->breakable_b_ = true;
+  Engraver_group_engraver::do_creation_processing();
+}
+
+void
+Score_engraver::do_removal_processing()
+{
+  Engraver_group_engraver::do_removal_processing();
+  scoreline_l_->set_bounds(RIGHT,get_staff_info().command_pcol_l ());
+  command_column_l_->breakable_b_ = true;
+
+  typeset_all ();
+  set_columns (0,0);
+}
+
+void
+Score_engraver::process()
+{
+  process_requests();
+  do_announces();
+  pre_move_processing();
+  check_removal();
+}
+
+void
+Score_engraver::announce_element (Score_element_info info)
+{
+  announce_info_arr_.push (info);
+  info.origin_grav_l_arr_.push (this);
+}
+
+void
+Score_engraver::do_announces()
+{
+  /* All elements are propagated to the top upon announcement. If
+     something was created during one run of
+     Engraver_group_engraver::do_announces, then
+     announce_info_arr_.size() will be nonzero again
+
+     */
+  while (announce_info_arr_.size()) 
+    {
+      for (int i=0; i < announce_info_arr_.size(); i++)
+       /*
+         TODO
+
+         More subtle spacing
+         */
+       if (announce_info_arr_[i].req_l_) 
+         {
+           Musical_req *m = announce_info_arr_[i].req_l_->access_Musical_req ();
+           if (m && m->access_Rhythmic_req ()) 
+             {
+               musical_column_l_->add_duration (m->duration());
+             }
+         }
+      Engraver_group_engraver::do_announces();
+    }
+}
+
+
+void
+Score_engraver::typeset_element (Score_element *elem_p)
+{
+  elem_p_arr_.push(elem_p);
+}
+
+void
+Score_engraver::typeset_all()
+{
+  for  (int i =0; i < elem_p_arr_.size(); i++) 
+    {
+      Score_element * elem_p = elem_p_arr_[i];
+      if (elem_p->access_Spanner ()) 
+       {
+         Spanner *s = elem_p->access_Spanner ();
+         pscore_p_->typeset_unbroken_spanner (s);
+
+
+
+                 /*
+           do something sensible if spanner not 
+           spanned on 2 items.
+          */
+         Direction d = LEFT;
+         do {
+           if (!s->spanned_drul_[d])
+             {
+               s->set_bounds(d, command_column_l_);
+               ::warning (_f ("Unbound spanner `%s\'", s->name ()));
+             }
+         } while (flip(&d) != LEFT);
+       }
+      else 
+       {
+         Item *item_p = elem_p->access_Item ();
+         pscore_p_->typeset_element (item_p);
+         if (!item_p->axis_group_l_a_[X_AXIS]) {
+           if (item_p->breakable_b_) 
+             command_column_l_->add_element(item_p);
+           else
+             musical_column_l_->add_element(item_p);
+         }
+       }
+      scoreline_l_->add_element (elem_p);
+    }
+  elem_p_arr_.clear();
+}
+
+void
+Score_engraver::do_pre_move_processing()
+{
+  if (break_penalty_i_ > Break_req::DISALLOW)
+    {
+      get_staff_info().command_pcol_l ()-> breakable_b_ = true;
+      breaks_i_ ++;
+      if (! (breaks_i_%8))
+       *mlog << "[" << breaks_i_ << "]" << flush;
+    }
+  // this generates all items.
+  Engraver_group_engraver::do_pre_move_processing();
+  
+  typeset_all();
+}
+
+void
+Score_engraver::set_columns (Score_column *new_command_l, 
+                            Score_column *new_musical_l)
+{
+  if (command_column_l_ && command_column_l_->linked_b()) 
+    {
+      pscore_p_->add_column (command_column_l_);
+      scoreline_l_->add_element (command_column_l_);
+    }
+  else 
+    {
+      delete command_column_l_ ;
+      command_column_l_ =0;
+    }
+  if (new_command_l) 
+    {
+      command_column_l_ = new_command_l;
+      command_column_l_->musical_b_ = false;
+    }
+  if (musical_column_l_ && musical_column_l_->linked_b()) 
+    {
+      pscore_p_->add_column (musical_column_l_);
+      scoreline_l_->add_element (musical_column_l_);
+    }
+  else 
+    {
+      delete musical_column_l_;
+      musical_column_l_ = 0;
+    }
+  
+  if (new_musical_l) 
+    {
+      musical_column_l_ = new_musical_l;
+      musical_column_l_->musical_b_ = true;
+    }
+}
+
+
+Staff_info
+Score_engraver::get_staff_info() const
+{
+  Staff_info inf = Engraver_group_engraver::get_staff_info();
+
+  inf.command_l_ = command_column_l_;
+  inf.musical_l_ = musical_column_l_;
+  
+  return inf;
+}
+
+
+
+Music_output*
+Score_engraver::get_output_p ()
+{
+  Music_output * o = pscore_p_;
+  pscore_p_=0;
+  return o;
+}
+
+bool
+Score_engraver::do_try_request (Request*r)
+{
+  bool gotcha = Engraver_group_engraver::do_try_request (r);  
+
+  if (gotcha || !r->access_Command_req ())
+    return gotcha;
+
+  Command_req * c = r->access_Command_req ();
+  if (c->access_Break_req ())
+    {
+      Break_req* b = (Break_req*)c->access_Break_req ();
+      if (b->penalty_i_ <= Break_req::DISALLOW)
+       break_penalty_i_ = b->penalty_i_;
+      else if (b->penalty_i_ >= Break_req::FORCE)
+       {
+         command_column_l_->break_penalty_i_ = b->penalty_i_;
+         gotcha = true;
+       }
+    }
+  return gotcha;
+}
+
+IMPLEMENT_IS_TYPE_B1(Score_engraver,Engraver_group_engraver);
+ADD_THIS_TRANSLATOR(Score_engraver);
+
+void
+Score_engraver::do_add_processing ()
+{
+  Translator_group::do_add_processing ();
+  assert (output_def_l_->is_type_b (Paper_def::static_name ()));
+  assert (!daddy_trans_l_);
+  pscore_p_ = new Paper_score;
+  pscore_p_->paper_l_ = (Paper_def*)output_def_l_;
+}
index ca153eb5dab06e99cce8517cf6d8dc547b52dd1a..fda20ea9eea3575a030a10816df14996ab0a42e6 100644 (file)
@@ -3,14 +3,14 @@
 
   source file of the LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "super-elem.hh"
-#include "scoreline.hh"
+#include "super-element.hh"
+#include "line-of-score.hh"
 #include "p-score.hh"
 #include "string.hh"
-#include "outputter.hh"
+#include "tex-outputter.hh"
 
 void
 Super_elem::handle_broken_dependencies()
@@ -22,10 +22,10 @@ Super_elem::handle_broken_dependencies()
   
 
 void
-Super_elem::do_substitute_dependency (Score_elem*o,Score_elem* n)
+Super_elem::do_substitute_dependency (Score_element*o,Score_element* n)
 {
-  if (line_of_score_l_ == o->spanner())
-    line_of_score_l_ = n? (Line_of_score*) n->spanner() : 0;
+  if (line_of_score_l_ == o->access_Spanner ())
+    line_of_score_l_ = n? (Line_of_score*) n->access_Spanner () : 0;
 }
 
 Super_elem::Super_elem()
@@ -40,13 +40,13 @@ Super_elem::do_add_processing()
   add_dependency (line_of_score_l_);
 }
 
-IMPLEMENT_IS_TYPE_B1(Super_elem,Score_elem);
+IMPLEMENT_IS_TYPE_B1(Super_elem,Score_element);
 
 
 /**
     for administration of what was done already
     */
-enum Score_elem_status {
+enum Score_element_status {
   ORPHAN=0,                    // not yet added to pstaff
   VIRGIN,                      // added to pstaff
   PREBROKEN,
@@ -66,34 +66,34 @@ enum Score_elem_status {
 void
 Super_elem::pre_processing ()
 {
-  calcalute_dependencies (PRECALCING, PRECALCED, &Score_elem::do_pre_processing);
+  calcalute_dependencies (PRECALCING, PRECALCED, &Score_element::do_pre_processing);
 }
 
 void
 Super_elem::space_processing ()
 {
-  calcalute_dependencies (SPACING, SPACED, &Score_elem::do_space_processing);
+  calcalute_dependencies (SPACING, SPACED, &Score_element::do_space_processing);
 }
 
 /* for break processing, use only one status, because copies have to
   have correct status. (Previously,
-  Score_elem::handle_[pre]broken_dependencies assigned to status_i_
+  Score_element::handle_[pre]broken_dependencies assigned to status_i_
   */
 void
 Super_elem::breakable_col_processing ()
 {
-  calcalute_dependencies (PREBROKEN, PREBROKEN, &Score_elem::do_breakable_col_processing);
+  calcalute_dependencies (PREBROKEN, PREBROKEN, &Score_element::do_breakable_col_processing);
 }
 
 void
 Super_elem::break_processing ()
 {
-  calcalute_dependencies (BROKEN, BROKEN, &Score_elem::do_break_processing);
+  calcalute_dependencies (BROKEN, BROKEN, &Score_element::do_break_processing);
 }
 void
 Super_elem::post_processing ()
 {
-  calcalute_dependencies (POSTCALCING, POSTCALCED, &Score_elem::do_post_processing);
+  calcalute_dependencies (POSTCALCING, POSTCALCED, &Score_element::do_post_processing);
 }
 
 void
@@ -102,7 +102,7 @@ Super_elem::output_all ()
   for (int i=0; i < lines_arr_.size(); i++)
     {
       pscore_l_->outputter_l_->start_line ();
-      lines_arr_[i]->calcalute_dependencies (BREWING, BREWED, &Score_elem::do_brew_molecule);
+      lines_arr_[i]->calcalute_dependencies (BREWING, BREWED, &Score_element::do_brew_molecule);
       pscore_l_->outputter_l_->stop_line ();
     }
 }
@@ -112,6 +112,6 @@ Super_elem::output_all ()
 void
 Super_elem::unlink_all ()
 {
-  calcalute_dependencies (UNLINKING, UNLINKED, &Score_elem::junk_links);
+  calcalute_dependencies (UNLINKING, UNLINKED, &Score_element::junk_links);
 }