]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/score-engraver.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / lily / score-engraver.cc
index 7596d9dd0c544c2ef4e656eb91c575ac3aa0aeaf..ce13f5ec447eee430d1a684c00f92d29a064aa66 100644 (file)
 /*
-  score-grav.cc -- implement Score_engraver
+  score-engraver.cc -- implement Score_engraver
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include "super-element.hh"
-#include "line-of-score.hh"
-#include "debug.hh"
+#include "all-font-metrics.hh"
+#include "afm.hh"
+#include "warn.hh"
+#include "main.hh"
+#include "system.hh"
 #include "item.hh"
 #include "score-engraver.hh"
-#include "p-score.hh"
-#include "musical-request.hh"
-#include "score-column.hh"
+#include "paper-score.hh"
+#include "paper-column.hh"
 #include "command-request.hh"
 #include "paper-def.hh"
+#include "axis-group-interface.hh"
+#include "translator-def.hh"
 
+#include "staff-spacing.hh"
+#include "note-spacing.hh"
 
+/*
+  TODO: the column creation logic is rather hairy. Revise it.
+ */
+Score_engraver::Score_engraver ()
+{
+  system_ =0;
+  command_column_ =0;
+  musical_column_ =0;
+  breaks_ =0;
+  pscore_ = 0;
+}
 
-Score_engraver::Score_engraver()
+void
+Score_engraver::make_columns ()
 {
-  break_penalty_i_ = 0;
-  scoreline_l_ =0;
-  command_column_l_ =0;
-  musical_column_l_ =0;
-  breaks_i_ =0;
-  pscore_p_ = 0;
+  /*
+    ugh.
+   */
+  if (!command_column_)
+    {
+      set_columns (new Paper_column (get_property ("NonMusicalPaperColumn")),
+                  new Paper_column (get_property ("PaperColumn")));
+  
+      command_column_->set_grob_property ("breakable", SCM_BOOL_T);
+
+
+      Grob_info i1 (command_column_);
+      i1.origin_trans_ = this;
+  
+      Grob_info i2 (musical_column_);
+      i2.origin_trans_ = this;
+
+      announce_grob (i1);
+      announce_grob (i2);
+    }
 }
+
 void
 Score_engraver::prepare (Moment w)
 {
   Global_translator::prepare (w);
-  set_columns (new Score_column (w),  new Score_column (w));
+
+  /*
+    TODO: don't make columns when skipTypesetting is true.
+   */
+  make_columns ();
   
-  break_penalty_i_ = 0;
-  post_move_processing();
+  command_column_->set_grob_property ("when", now_mom_.smobbed_copy ());
+  musical_column_->set_grob_property ("when", now_mom_.smobbed_copy ());
+
+  
+  Translator_group::start_translation_timestep();
 }
 
 void
-Score_engraver::finish()
+Score_engraver::finish ()
 {
-  if ((breaks_i_%8))
-    *mlog << "[" << breaks_i_ << "]" << flush;
+  if ((breaks_%8))
+    progress_indication ("[" + to_string (breaks_) + "]");
    
-  check_removal();
-  removal_processing();
-}
+  check_removal ();
+  removal_processing ();
 
-void
-Score_engraver::do_creation_processing()
-{
-  scoreline_l_ = pscore_p_->line_l_;
-  scoreline_l_->set_bounds(LEFT,get_staff_info().command_pcol_l ());
-  command_column_l_->breakable_b_ = true;
-  Engraver_group_engraver::do_creation_processing();
 }
 
+/*
+  use start/finish?
+ */
 void
-Score_engraver::do_removal_processing()
+Score_engraver::initialize ()
 {
-  Engraver_group_engraver::do_removal_processing();
-  scoreline_l_->set_bounds(RIGHT,get_staff_info().command_pcol_l ());
-  command_column_l_->breakable_b_ = true;
+  Font_metric *fm = all_fonts_global->find_afm("feta20");
+  if (!fm)
+    error (_f ("can't find `%s'", "feta20.afm")
+          + "\n" +_ ("Fonts have not been installed properly.  Aborting"));
+   
+  unsmob_translator_def (definition_)->apply_property_operations (this);
 
-  typeset_all ();
-  set_columns (0,0);
-}
+  assert (dynamic_cast<Paper_def *> (output_def_));
+  assert (!daddy_trans_);
+  pscore_ = new Paper_score;
+  pscore_->paper_ = dynamic_cast<Paper_def*> (output_def_);
 
-void
-Score_engraver::process()
-{
-  process_requests();
-  do_announces();
-  pre_move_processing();
-  check_removal();
+  SCM props = get_property ("System");
+
+  pscore_->typeset_line (new System (props));
+  
+  make_columns ();
+  system_ = pscore_->system_;
+  system_->set_bound (LEFT, command_column_);
+  command_column_->set_grob_property ("breakable", SCM_BOOL_T);
+
+  Engraver_group_engraver::initialize ();
 }
 
+
 void
-Score_engraver::announce_element (Score_element_info info)
+Score_engraver::finalize ()
 {
-  announce_info_arr_.push (info);
-  info.origin_grav_l_arr_.push (this);
+  Engraver_group_engraver::finalize ();
+
+  Grob * cc
+    = unsmob_grob (get_property ("currentCommandColumn"));
+  system_->set_bound (RIGHT, cc);
+  cc->set_grob_property ("breakable", SCM_BOOL_T);
+  
+  typeset_all ();
 }
 
 void
-Score_engraver::do_announces()
+Score_engraver::one_time_step ()
 {
-  /* 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()) 
+  if (!to_boolean (get_property ("skipTypesetting")))
     {
-      for (int i=0; i < announce_info_arr_.size(); i++)
-       /*
-         TODO
+      process_music ();
+      do_announces ();
+    }
+  
+  stop_translation_timestep ();
+  
+  apply_finalizations ();
+  check_removal ();
 
-         More subtle spacing
-         */
-       if (announce_info_arr_[i].req_l_) 
-         {
-           if (Rhythmic_req *rq = dynamic_cast <Rhythmic_req *> (announce_info_arr_[i].req_l_))
-             {
-               musical_column_l_->add_duration (rq->length_mom ());
-             }
-         }
-      Engraver_group_engraver::do_announces();
+
+  for (int i = announce_infos_.size(); i--;)
+    {
+      Grob *g = announce_infos_[i].grob_;
+      if (!dynamic_cast<Paper_column*> (g)) // ugh.
+       {
+      
+         String msg= "Grob "
+           + g->name()
+           + " was created too late!";
+         g->programming_error (msg);
+       }
     }
+  announce_infos_.clear ();
 }
 
-
 void
-Score_engraver::typeset_element (Score_element *elem_p)
+Score_engraver::announce_grob (Grob_info info)
 {
-  elem_p_arr_.push (elem_p);
+  announce_infos_.push (info);
+  pscore_->system_->typeset_grob (info.grob_);
 }
 
+void
+Score_engraver::typeset_grob (Grob *elem)
+{
+  if (!elem)
+    programming_error ("Score_engraver: empty elt\n");
+  else
+    elems_.push (elem);
+}
 
 void
-Score_engraver::typeset_all()
+Score_engraver::typeset_all ()
 {
-  for  (int i =0; i < elem_p_arr_.size(); i++) 
+  for (int i =0; i < elems_.size (); i++) 
     {
-      Score_element * elem_p = elem_p_arr_[i];
-      if (Spanner *s = dynamic_cast <Spanner *> (elem_p))
+      Grob * elem = elems_[i];
+      
+      if (Spanner *s = dynamic_cast <Spanner *> (elem))
        {
-         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])
+           if (!s->get_bound (d))
              {
-               s->set_bounds(d, command_column_l_);
-               ::warning (_f ("Unbound spanner `%s\'", classname(s)));
+               s->set_bound (d, command_column_);
+               /* don't warn for empty/suicided spanners,
+                  it makes real warningsinvisible.
+                  maybe should be junked earlier? */
+               if (!elem->live())
+                 ; // gdb hook
+               else
+                 elem->warning (_f ("unbound spanner `%s'", s->name ().to_str0 ()));
              }
-         } while (flip(&d) != LEFT);
+         }
+         while (flip (&d) != LEFT);
+
+         if (dynamic_cast<Item*> (s->get_parent (Y_AXIS)))
+           programming_error ("Spanner Y-parent is an item.");
        }
       else 
        {
-         Item *item_p = dynamic_cast <Item *> (elem_p);
-         pscore_p_->typeset_element (item_p);
-         if (!item_p->parent_l (X_AXIS))
+         if (!elem->get_parent (X_AXIS))
            {
-             if (item_p->breakable_b_) 
-               command_column_l_->add_element(item_p);
-             else
-               musical_column_l_->add_element(item_p);
+             bool br = to_boolean (elem->get_grob_property ("breakable"));
+             Axis_group_interface::add_element (br ? command_column_ : musical_column_, elem);
+
            }
        }
-      scoreline_l_->add_element (elem_p);
+      if (!elem->get_parent (Y_AXIS))
+       Axis_group_interface::add_element (system_, elem);
     }
-  elem_p_arr_.clear();
+  elems_.clear ();
 }
 
 void
-Score_engraver::do_pre_move_processing()
+Score_engraver::stop_translation_timestep ()
 {
-  if (break_penalty_i_ > Break_req::DISALLOW)
+  // this generates all items.
+  Engraver_group_engraver::stop_translation_timestep ();
+  
+  typeset_all ();
+  if (to_boolean (command_column_->get_grob_property ("breakable")))
     {
-      get_staff_info().command_pcol_l ()-> breakable_b_ = true;
-      breaks_i_ ++;
-      if (! (breaks_i_%8))
-       *mlog << "[" << breaks_i_ << "]" << flush;
+      breaks_ ++;
+      if (! (breaks_%8))
+       progress_indication ("[" + to_string (breaks_) + "]");
     }
-  // this generates all items.
-  Engraver_group_engraver::do_pre_move_processing();
+
+
+  system_->add_column (command_column_);
+  system_->add_column (musical_column_);
   
-  typeset_all();
+  command_column_ = 0;
+  musical_column_ = 0;
 }
 
 void
-Score_engraver::set_columns (Score_column *new_command_l
-                            Score_column *new_musical_l)
+Score_engraver::set_columns (Paper_column *new_command
+                            Paper_column *new_musical)
 {
-  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 
+  assert (!command_column_ && !musical_column_);
+
+  command_column_ = new_command;
+  musical_column_ = new_musical;
+  if (new_command)
     {
-      delete musical_column_l_;
-      musical_column_l_ = 0;
+      set_property ("currentCommandColumn", new_command->self_scm ());  
     }
   
-  if (new_musical_l) 
+  if (new_musical)
     {
-      musical_column_l_ = new_musical_l;
-      musical_column_l_->musical_b_ = true;
+      set_property ("currentMusicalColumn", new_musical->self_scm ());
     }
 }
 
-
-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 ()
+Score_engraver::get_output ()
 {
-  Music_output * o = pscore_p_;
-  pscore_p_=0;
+  Music_output * o = pscore_;
+  pscore_=0;
   return o;
 }
 
 bool
-Score_engraver::do_try_music (Music*r)
+Score_engraver::try_music (Music*r)
 {
-  bool gotcha = Engraver_group_engraver::do_try_music (r);  
+  bool gotcha = Engraver_group_engraver::try_music (r);  
 
   if (!gotcha)
     {
       if (Break_req* b = dynamic_cast<Break_req *> (r))
        {
-         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;
-           }
+         gotcha = true;
+
+
+         SCM pen = command_column_->get_grob_property ("penalty");
+         Real total_penalty = gh_number_p (pen)
+           ? gh_scm2double (pen)
+           : 0.0;
+
+         SCM rpen = b->get_mus_property ("penalty");
+         if (gh_number_p (rpen))
+           total_penalty +=  gh_scm2double (rpen);
+         
+         if (total_penalty > 10000.0) //  ugh. arbitrary.
+           forbid_breaks ();
+
+         command_column_->set_grob_property ("penalty",
+                                              gh_double2scm (total_penalty));
        }
     }
    return gotcha;
-
 }
 
-
-ADD_THIS_TRANSLATOR(Score_engraver);
-
+/*
+  TODO:  use property Score.breakForbidden = #t
+ */
+void
+Score_engraver::forbid_breaks ()
+{
+  /*
+    result is junked.
+   */
+  if (command_column_)
+    command_column_->set_grob_property ("breakable", SCM_EOL);
+}
+  
 void
-Score_engraver::do_add_processing ()
+Score_engraver::acknowledge_grob (Grob_info gi)
 {
-  Translator_group::do_add_processing ();
-  assert (dynamic_cast<Paper_def *> (output_def_l_));
-  assert (!daddy_trans_l_);
-  pscore_p_ = new Paper_score;
-  pscore_p_->paper_l_ = dynamic_cast<Paper_def*>(output_def_l_);
+  if (Staff_spacing::has_interface (gi.grob_))
+    {
+      Pointer_group_interface::add_grob (command_column_,
+                                        ly_symbol2scm ("spacing-wishes"),
+                                        gi.grob_);
+    }
+  if (Note_spacing::has_interface (gi.grob_))
+    {
+      Pointer_group_interface::add_grob (musical_column_,
+                                        ly_symbol2scm ("spacing-wishes"),
+                                        gi.grob_);
+    }
 }
+
+
+
+ENTER_DESCRIPTION(Score_engraver,
+/* descr */       "Top level engraver. Takes care of generating columns and the complete  system (ie. System)
+
+
+This engraver decides whether a column is breakable. The default is
+that a column is always breakable. However, when every Bar_engraver
+that does not have a barline at a certain point will call
+Score_engraver::forbid_breaks to stop linebreaks.  In practice, this
+means that you can make a breakpoint by creating a barline (assuming
+that there are no beams or notes that prevent a breakpoint.)
+
+
+",
+/* creats*/       "System PaperColumn NonMusicalPaperColumn",
+/* acks  */       "note-spacing-interface staff-spacing-interface",
+/* reads */       "currentMusicalColumn currentCommandColumn",
+/* write */       "");