]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/separating-line-group-engraver.cc
Cleanup beam scoring code.
[lilypond.git] / lily / separating-line-group-engraver.cc
index a46608d0ab18c928013f5706acdde44f98473830..86c45fb55a0bc1fe4792f7d56d1516b147e8f668 100644 (file)
-/*   
-  separating-line-group-grav.cc --  implement Separating_line_group_engraver
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
-
-#include "separating-line-group-engraver.hh"
-#include "separating-group-spanner.hh"
-#include "single-malt-grouping-item.hh"
+/*
+  This file is part of LilyPond, the GNU music typesetter.
+
+  Copyright (C) 1998--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "engraver.hh"
+
+#include "separation-item.hh"
 #include "paper-column.hh"
-#include "paper-def.hh"
+#include "output-def.hh"
+#include "axis-group-interface.hh"
+#include "note-spacing.hh"
+#include "accidental-placement.hh"
+#include "context.hh"
+#include "spanner.hh"
+#include "grob-array.hh"
+#include "pointer-group-interface.hh"
 
-Separating_line_group_engraver::Separating_line_group_engraver ()
+#include "translator.icc"
+
+struct Spacings
 {
-  sep_span_p_ = 0;
-  break_malt_p_ = 0;
-  nobreak_malt_p_ =0;
-}
+  Item *staff_spacing_;
+  vector<Item*> note_spacings_;
 
-void
-Separating_line_group_engraver::do_creation_processing ()
+  Spacings ()
+  {
+    staff_spacing_ = 0;
+  }
+
+  bool is_empty () const
+  {
+    return !staff_spacing_ && !note_spacings_.size ();
+  }
+  void clear ()
+  {
+    staff_spacing_ = 0;
+    note_spacings_.clear ();
+  }
+};
+
+class Separating_line_group_engraver : public Engraver
 {
-  sep_span_p_ = new Separating_group_spanner (SCM_EOL);
-  announce_element (Score_element_info (sep_span_p_, 0));
-  sep_span_p_->set_bound (LEFT, unsmob_element (get_property ("currentCommandColumn")));
-}
+protected:
+  Spacings current_spacings_;
+  Spacings last_spacings_;
 
-void
-Separating_line_group_engraver::do_removal_processing ()
+  DECLARE_ACKNOWLEDGER (item);
+  DECLARE_ACKNOWLEDGER (break_aligned);
+  void stop_translation_timestep ();
+  void start_translation_timestep ();
+
+  vector<Grob*> break_aligned_;
+public:
+  TRANSLATOR_DECLARATIONS (Separating_line_group_engraver);
+};
+
+Separating_line_group_engraver::Separating_line_group_engraver ()
 {
-  sep_span_p_->set_bound (RIGHT, unsmob_element (get_property ("currentCommandColumn")));
-  typeset_element (sep_span_p_);
-  sep_span_p_ =0;
 }
 
 void
-Separating_line_group_engraver::acknowledge_element (Score_element_info i)
+Separating_line_group_engraver::acknowledge_item (Grob_info i)
 {
-  Item * it = dynamic_cast <Item *> (i.elem_l_);
-  if (it && !it->parent_l (X_AXIS))
+  Item *it = i.item ();
+
+  if (Note_spacing::has_interface (it))
+    {
+      current_spacings_.note_spacings_.push_back (it);
+      return;
+    }
+
+  if (Item::is_non_musical (it)
+      && !current_spacings_.staff_spacing_
+      && to_boolean (get_property ("createSpacing")))
     {
-      bool ib =it->breakable_b ();
-      Single_malt_grouping_item *&p_ref_ (ib ? break_malt_p_
-                                         : nobreak_malt_p_);
+      Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
+
+      current_spacings_.staff_spacing_ = make_item ("StaffSpacing", SCM_EOL);
+      context ()->set_property ("hasStaffSpacing", SCM_BOOL_T);
 
-      if (!p_ref_)
+      Pointer_group_interface::add_grob (current_spacings_.staff_spacing_,
+                                        ly_symbol2scm ("left-items"),
+                                        col);
+      
+      if (!last_spacings_.note_spacings_.size ()
+         && last_spacings_.staff_spacing_)
        {
-         p_ref_
-           = new Single_malt_grouping_item
-           (get_property ("basicSingleMaltGroupingItemProperties"));
+         SCM ri = last_spacings_.staff_spacing_->get_object ("right-items");
+         Grob_array *ga = unsmob_grob_array (ri);
+         if (!ga)
+           {
+             SCM ga_scm = Grob_array::make_array ();
+             last_spacings_.staff_spacing_->set_object ("right-items", ga_scm);
+             ga = unsmob_grob_array (ga_scm);
+           }
          
-         if (ib)
-           p_ref_->set_elt_property ("breakable", SCM_BOOL_T);
-         announce_element (Score_element_info (p_ref_, 0));
+         ga->clear ();
+         ga->add (col);
        }
-      p_ref_->add_item (it);
     }
 }
 
 void
-Separating_line_group_engraver::do_pre_move_processing ()
+Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi)
 {
-  if (break_malt_p_)
-    {
-      sep_span_p_->add_spacing_unit (break_malt_p_);
-      
-      typeset_element (break_malt_p_);
-      break_malt_p_ =0;
-    }
-  if (nobreak_malt_p_)
+  break_aligned_.push_back (gi.grob ());
+}
+
+void
+Separating_line_group_engraver::start_translation_timestep ()
+{
+  context ()->unset_property (ly_symbol2scm ("hasStaffSpacing"));
+}
+
+void
+Separating_line_group_engraver::stop_translation_timestep ()
+{
+  for (vsize i = 0; i < break_aligned_.size (); i++)
     {
-      sep_span_p_->add_spacing_unit (nobreak_malt_p_);
-      typeset_element (nobreak_malt_p_);
-      nobreak_malt_p_ =0;
+      SCM smob = break_aligned_[i]->self_scm ();
+
+      if (Item *sp = current_spacings_.staff_spacing_)
+       Pointer_group_interface::add_grob (sp, ly_symbol2scm ("left-break-aligned"), smob);
+
+      for (vsize j = 0; j < last_spacings_.note_spacings_.size (); j++)
+       Pointer_group_interface::add_grob (last_spacings_.note_spacings_[j],
+                                          ly_symbol2scm ("right-break-aligned"), smob);
     }
+
+  if (!current_spacings_.is_empty ())
+    last_spacings_ = current_spacings_;
+
+  if (Item *sp = current_spacings_.staff_spacing_)
+    if (Grob *col = unsmob_grob (get_property ("currentMusicalColumn")))
+      Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"), col);
+
+  current_spacings_.clear ();
+  break_aligned_.clear ();
 }
 
+ADD_ACKNOWLEDGER (Separating_line_group_engraver, item);
+ADD_ACKNOWLEDGER (Separating_line_group_engraver, break_aligned);
+
+ADD_TRANSLATOR (Separating_line_group_engraver,
+               /* doc */
+               "Generate objects for computing spacing parameters.",
 
+               /* create */
+               "StaffSpacing ",
 
-ADD_THIS_TRANSLATOR( Separating_line_group_engraver);
+               /* read */
+               "createSpacing ",
 
+               /* write */
+               "hasStaffSpacing "
+               );