]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/note-spacing-engraver.cc
Imported Upstream version 2.14.2
[lilypond.git] / lily / note-spacing-engraver.cc
index 68593604de12420214b390b78adda3536567e10c..761e01aa0b8d38816f3368f3f4dd05399ee4f5f1 100644 (file)
@@ -1,10 +1,20 @@
-/* 
-  note-spacing-engraver.cc -- implement Note_spacing_engraver
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 2006--2007 Han-Wen Nienhuys <hanwen@lilypond.org>
-  
+/*
+  This file is part of LilyPond, the GNU music typesetter.
+
+  Copyright (C) 2006--2011 Han-Wen Nienhuys <hanwen@lilypond.org>
+
+  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 "item.hh"
 #include "pointer-group-interface.hh"
 
+#include <map>
+
 #include "translator.icc"
 
 class Note_spacing_engraver : public Engraver
 {
+  typedef map <Context*, Grob*> Last_spacing_map;
+  Last_spacing_map last_spacings_;
   Grob *last_spacing_;
-  Context *last_spacing_parent_context_;
   
   Grob *spacing_;
 
@@ -37,15 +50,15 @@ protected:
 void
 Note_spacing_engraver::derived_mark () const
 {
-  if (last_spacing_parent_context_)
-    scm_gc_mark (last_spacing_parent_context_->self_scm ());
+  for (Last_spacing_map::const_iterator i = last_spacings_.begin ();
+       i != last_spacings_.end (); i++)
+    scm_gc_mark (i->first->self_scm ());
 }
 
 Note_spacing_engraver::Note_spacing_engraver ()
 {
-  last_spacing_parent_context_ = 0;
-  last_spacing_ = 0;
   spacing_ = 0;
+  last_spacing_ = 0;
 }
 
 void
@@ -85,38 +98,39 @@ Note_spacing_engraver::acknowledge_rhythmic_grob (Grob_info gi)
 void
 Note_spacing_engraver::finalize ()
 {
-  if (last_spacing_
-      && last_spacing_parent_context_
-      && last_spacing_parent_context_ == context ()->get_parent_context ()
-      && !unsmob_grob_array (last_spacing_->get_object ("right-items")))
+  Context *parent = context ()->get_parent_context ();
+  Grob *last_spacing = last_spacings_[parent];
+
+  if (last_spacing
+      && !unsmob_grob_array (last_spacing->get_object ("right-items")))
     {
-      SCM ccol = get_property ("currentCommandColumn");
-      Grob *column = unsmob_grob (ccol);
+      Grob *col  = unsmob_grob (get_property ("currentCommandColumn"));
       
-      Pointer_group_interface::add_grob (last_spacing_,
+      Pointer_group_interface::add_grob (last_spacing,
                                         ly_symbol2scm ("right-items"),
-                                        column);
+                                        col);
     }
 }
 
 void
 Note_spacing_engraver::stop_translation_timestep ()
 {
-  if (last_spacing_
-      && last_spacing_parent_context_
-      && last_spacing_parent_context_ == context ()->get_parent_context ()
+  Context *parent = context ()->get_parent_context ();
+  Grob *last_spacing = last_spacings_[parent];
+
+  if (last_spacing
       && to_boolean (get_property ("hasStaffSpacing")))
     {
       Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
-      Pointer_group_interface::add_grob (last_spacing_,
+      Pointer_group_interface::add_grob (last_spacing,
                                         ly_symbol2scm ("right-items"),
                                         col);
     }
   
   if (spacing_)
     {
+      last_spacings_[parent] = spacing_;
       last_spacing_ = spacing_;
-      last_spacing_parent_context_ = context ()->get_parent_context ();
       spacing_ = 0;
     }
 
@@ -126,7 +140,16 @@ ADD_ACKNOWLEDGER (Note_spacing_engraver, note_column);
 ADD_ACKNOWLEDGER (Note_spacing_engraver, rhythmic_grob);
 
 ADD_TRANSLATOR (Note_spacing_engraver,
-               /* doc */ "Generates NoteSpacing, an object linking horizontal lines for use in spacing.",
-               /* create */ "NoteSpacing",
-               /* read */ "",
-               /* write */ "");
+               /* doc */
+               "Generate @code{NoteSpacing}, an object linking horizontal"
+               " lines for use in spacing.",
+
+               /* create */
+               "NoteSpacing ",
+
+               /* read */
+               "",
+
+               /* write */
+               ""
+               );