]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-score.cc
release: 1.3.40
[lilypond.git] / lily / paper-score.cc
index e51b01cef39b821803337c41b1a4760dd6d81650..247b5fecad48cc0d1b4c9cf2231d0e6cf4a2fd26 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996,  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1996--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "main.hh"
@@ -49,8 +49,8 @@ Paper_score::typeset_element (Score_element * elem_p)
 {
   elem_p->pscore_l_ = this;
 
-  SCM_CDR(element_smob_list_) = gh_cons (elem_p->self_scm_,
-                                        SCM_CDR (element_smob_list_));
+  gh_set_cdr_x(element_smob_list_,
+              gh_cons (elem_p->self_scm_, gh_cdr (element_smob_list_)));
   elem_p->set_elt_property ("full-name",
                            gh_str02scm((char*)elem_p->name()));
   
@@ -75,10 +75,10 @@ Paper_score::print () const
   DEBUG_OUT << "Paper_score { ";
   DEBUG_OUT << "\n elements: ";
 
-  for (SCM p = SCM_CDR (element_smob_list_);
+  for (SCM p = gh_cdr (element_smob_list_);
        p != SCM_EOL;
-       p = SCM_CDR(p))
-    gh_display (SCM_CAR(p));
+       p = gh_cdr(p))
+    gh_display (gh_car (p));
   DEBUG_OUT << "}\n";
 #endif
 }
@@ -110,21 +110,45 @@ Paper_score::calc_breaking ()
 void
 Paper_score::process ()
 {
-
   print ();
-  *mlog << _ ("Preprocessing elements...") << " " << flush;
-  line_l_->breakable_col_processing ();
-  line_l_->pre_processing ();
-  
-  *mlog << '\n' << _ ("Calculating column positions...") << " " << flush;
-  line_l_->space_processing ();
+  progress_indication (_ ("Preprocessing elements...") + " ");
 
-  Array<Column_x_positions> breaking = calc_breaking ();
 
+  /*
+    Be sure to set breakability on first & last column.
+   */
+  col_l_arr_[0]->set_elt_property ("breakable", SCM_BOOL_T);
+  col_l_arr_.top ()->set_elt_property ("breakable", SCM_BOOL_T);
+
+  for (SCM s = element_smob_list_; gh_pair_p (s); s = gh_cdr (s))
+    unsmob_element (gh_car (s))->do_breakable_col_processing ();
+
+  fixup_refpoints ();
+
+  for (SCM s = element_smob_list_; gh_pair_p (s); s = gh_cdr (s))
+    {
+      Score_element* sc = unsmob_element (gh_car (s));
+      sc->calculate_dependencies (PRECALCED, PRECALCING, &Score_element::before_line_breaking);
+    }
+
+  progress_indication ("\n" + _ ("Calculating column positions...") + " " );
+  for (SCM s = element_smob_list_; gh_pair_p (s); s = gh_cdr (s))
+    unsmob_element (gh_car (s))->do_space_processing ();
 
+  Array<Column_x_positions> breaking = calc_breaking ();
+  line_l_->break_into_pieces (breaking);
+
+  for (SCM s = element_smob_list_; gh_pair_p (s); s = gh_cdr (s))
+    {
+      unsmob_element (gh_car (s))->do_break_processing ();
+    }
+  for (SCM s = element_smob_list_; gh_pair_p (s); s = gh_cdr (s))
+    {
+      unsmob_element (gh_car (s))->handle_broken_dependencies ();
+    }
+  
   outputter_l_ = new Paper_outputter ;
   outputter_l_->output_header ();
-
   outputter_l_->output_version();
   
   if (header_global_p)
@@ -153,31 +177,15 @@ Paper_score::process ()
     
    */
   SCM before_output = outputter_l_->last_cons_;
-  
-  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_element (line_l);
-    }
-
+  fixup_refpoints ();
 
-  *mlog << "\n";
-  *mlog << _ ("Line ... ");
-  line_l_->break_processing ();
-  for (int i=0; i < lines.size (); i++)
-    {
-      *mlog << '[' << flush;
-      
-      Line_of_score *line_l = lines[i];
-
-      line_l->post_processing ();
-      *mlog << i << flush;
-      line_l->output_all (i + 1 == lines.size ());
-      *mlog << ']' << flush;
-    }
+  /*
+    TODO: change this, so that each element ouputs its molecules into
+    its line, and then output all lines one by one; then we can do
+    
+    foreach element: output
+  */
+  line_l_->output_lines ();
 
   SCM font_names = ly_quote_scm (all_fonts_global_p->font_descriptions ());
   gh_set_cdr_x (before_output,
@@ -188,9 +196,9 @@ Paper_score::process ()
   
   Paper_stream* psp = paper_l_->paper_stream_p ();
   outputter_l_->dump_onto (psp);
+
   // huh?
   delete outputter_l_;
-  
   outputter_l_ = 0;
   delete psp;
   
@@ -222,3 +230,23 @@ Paper_score::broken_col_range (Item const*l, Item const*r) const
 
   return ret;
 }
+
+
+void
+Paper_score::fixup_refpoints ()
+{
+  for (SCM s = element_smob_list_; gh_pair_p (s); s = gh_cdr (s))
+    {
+      SCM e = gh_car (s);
+      if (SMOB_IS_TYPE_B(Score_element, e))
+       {
+         Score_element * se = unsmob_element (e);
+         se->fixup_refpoint ();
+             
+         if (!dynamic_cast<Line_of_score*> (se) && !se->parent_l (Y_AXIS))
+           {
+             programming_error ("No parent!");
+           }
+       }
+    }
+}