]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/separating-line-group-engraver.cc
Run grand-replace (issue 3765)
[lilypond.git] / lily / separating-line-group-engraver.cc
index 1db11947a38f1178335e160a88e282bc957c3a17..fba16bebb90e77ea730a180022673be4168adac1 100644 (file)
@@ -1,14 +1,24 @@
 /*
-  separating-line-group-engraver.cc -- implement Separating_line_group_engraver
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 1998--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 1998--2006 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 "separating-group-spanner.hh"
 #include "separation-item.hh"
 #include "paper-column.hh"
 #include "output-def.hh"
@@ -16,6 +26,7 @@
 #include "note-spacing.hh"
 #include "accidental-placement.hh"
 #include "context.hh"
+#include "spanner.hh"
 #include "grob-array.hh"
 #include "pointer-group-interface.hh"
 
@@ -24,7 +35,7 @@
 struct Spacings
 {
   Item *staff_spacing_;
-  Link_array<Item> note_spacings_;
+  vector<Item *> note_spacings_;
 
   Spacings ()
   {
@@ -45,77 +56,27 @@ struct Spacings
 class Separating_line_group_engraver : public Engraver
 {
 protected:
-  Item *break_item_;
-  Item *musical_item_;
-  Item *last_musical_item_;
-
   Spacings current_spacings_;
   Spacings last_spacings_;
 
-  Spanner *sep_span_;
-
   DECLARE_ACKNOWLEDGER (item);
-  void process_music ();
-  virtual void finalize ();
+  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_ = 0;
-  break_item_ = 0;
-  musical_item_ = 0;
-}
-
-void
-Separating_line_group_engraver::process_music ()
-{
-  if (!sep_span_)
-    {
-      sep_span_ = make_spanner ("SeparatingGroupSpanner", SCM_EOL);
-
-      sep_span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
-    }
-}
-void
-Separating_line_group_engraver::finalize ()
-{
-  if (!sep_span_)
-    return;
-
-  SCM ccol = get_property ("currentCommandColumn");
-  Grob *column = unsmob_grob (ccol);
-
-  sep_span_->set_bound (RIGHT, unsmob_grob (ccol));
-  sep_span_ = 0;
-
-  for (vsize i = 0; i < last_spacings_.note_spacings_.size (); i++)
-    {
-      Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
-                                        ly_symbol2scm ("right-items"),
-                                        column);
-    }
-
-  if (last_spacings_.staff_spacing_
-      && last_spacings_.staff_spacing_->get_column () == column)
-    last_spacings_.staff_spacing_->suicide ();
 }
 
 void
 Separating_line_group_engraver::acknowledge_item (Grob_info i)
 {
-  Item *it = dynamic_cast<Item *> (i.grob ());
-  if (!it)
-    return;
-  if (it->get_parent (X_AXIS)
-      && Axis_group_interface::has_axis (it->get_parent (X_AXIS), X_AXIS))
-    return;
-
-  if (to_boolean (it->get_property ("no-spacing-rods")))
-    return;
+  Item *it = i.item ();
 
   if (Note_spacing::has_interface (it))
     {
@@ -123,104 +84,88 @@ Separating_line_group_engraver::acknowledge_item (Grob_info i)
       return;
     }
 
-  bool ib = Item::is_breakable (it);
-  Item *&p_ref_ (ib ? break_item_
-                : musical_item_);
-
-  if (!p_ref_)
+  if (Item::is_non_musical (it)
+      && !current_spacings_.staff_spacing_
+      && to_boolean (get_property ("createSpacing")))
     {
-      p_ref_ = make_item ("SeparationItem", SCM_EOL);
-
-      if (ib)
-       {
-         p_ref_->set_property ("breakable", SCM_BOOL_T);
-         context ()->set_property ("breakableSeparationItem", p_ref_->self_scm ());
-       }
-
-      if (to_boolean (get_property ("createSpacing"))
-         && p_ref_ == break_item_)
-       {
-         Item *it = make_item ("StaffSpacing", SCM_EOL);
-         current_spacings_.staff_spacing_ = it;
-         Pointer_group_interface::add_grob (it, ly_symbol2scm ("left-items"),
-                                            break_item_);
-
-         if (int i = last_spacings_.note_spacings_.size ())
-           {
-             for (; i--;)
-               Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
-                                                  ly_symbol2scm ("right-items"),
-                                                  break_item_);
-           }
-         else if (last_spacings_.staff_spacing_)
-           {
-             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);
-               }
-
-             ga->clear ();
-             ga->add (break_item_);
-           }
-       }
+      Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
+
+      current_spacings_.staff_spacing_ = make_item ("StaffSpacing", SCM_EOL);
+      context ()->set_property ("hasStaffSpacing", SCM_BOOL_T);
+
+      Pointer_group_interface::add_grob (current_spacings_.staff_spacing_,
+                                         ly_symbol2scm ("left-items"),
+                                         col);
+
+      if (!last_spacings_.note_spacings_.size ()
+          && last_spacings_.staff_spacing_)
+        {
+          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);
+            }
+
+          ga->clear ();
+          ga->add (col);
+        }
     }
+}
 
-  if (Accidental_placement::has_interface (it))
-    Separation_item::add_conditional_item (p_ref_, it);
-  else
-    Separation_item::add_item (p_ref_, it);
+void
+Separating_line_group_engraver::acknowledge_break_aligned (Grob_info gi)
+{
+  break_aligned_.push_back (gi.grob ());
 }
 
 void
 Separating_line_group_engraver::start_translation_timestep ()
 {
-  if (break_item_)
-    {
-      context ()->unset_property (ly_symbol2scm ("breakableSeparationItem"));
-      break_item_ = 0;
-    }
+  context ()->unset_property (ly_symbol2scm ("hasStaffSpacing"));
 }
 
 void
 Separating_line_group_engraver::stop_translation_timestep ()
 {
-  if (break_item_)
-    Separating_group_spanner::add_spacing_unit (sep_span_, break_item_);
-
-  if (Item *sp = current_spacings_.staff_spacing_)
+  for (vsize i = 0; i < break_aligned_.size (); i++)
     {
-      /*
-       TODO: should really look at the left-items of following
-       note-spacing grobs.
-      */
-      if (musical_item_)
-       Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"),
-                                          musical_item_);
+      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_;
 
-  current_spacings_.clear ();
-
-  if (musical_item_)
-    Separating_group_spanner::add_spacing_unit (sep_span_, musical_item_);
+  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);
 
-  musical_item_ = 0;
+  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 */ "Generates objects for computing spacing parameters.",
-
-               /* create */
-               "SeparationItem "
-               "SeparatingGroupSpanner "
-               "StaffSpacing",
-               /* accept */ "",
-               /* read */ "createSpacing",
-               /* write */ "breakableSeparationItem");
+                /* doc */
+                "Generate objects for computing spacing parameters.",
+
+                /* create */
+                "StaffSpacing ",
+
+                /* read */
+                "createSpacing ",
+
+                /* write */
+                "hasStaffSpacing "
+               );