X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fnote-spacing-engraver.cc;h=653aa8db023f80ad804cae7c4d2ab235cbd38e51;hb=8659a99f233f5c4684292728e7ad4206669b35b0;hp=8772ceec7b0daea9b8604cae5c56ee57fe7df129;hpb=1c4458de37e468a5d4fe023a34a5bcb05bf24aad;p=lilypond.git diff --git a/lily/note-spacing-engraver.cc b/lily/note-spacing-engraver.cc index 8772ceec7b..653aa8db02 100644 --- a/lily/note-spacing-engraver.cc +++ b/lily/note-spacing-engraver.cc @@ -1,10 +1,20 @@ -/* - note-spacing-engraver.cc -- implement Note_spacing_engraver - - source file of the GNU LilyPond music typesetter - - (c) 2006 Han-Wen Nienhuys - +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2006--2015 Han-Wen Nienhuys + + 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 . */ #include "engraver.hh" @@ -14,21 +24,24 @@ #include "item.hh" #include "pointer-group-interface.hh" +#include + #include "translator.icc" class Note_spacing_engraver : public Engraver { + typedef map Last_spacing_map; + Last_spacing_map last_spacings_; Grob *last_spacing_; - Context *last_spacing_parent_context_; - + Grob *spacing_; void add_spacing_item (Grob *); TRANSLATOR_DECLARATIONS (Note_spacing_engraver); protected: - DECLARE_ACKNOWLEDGER (rhythmic_grob); - DECLARE_ACKNOWLEDGER (note_column); + void acknowledge_rhythmic_grob (Grob_info); + void acknowledge_note_column (Grob_info); void stop_translation_timestep (); virtual void finalize (); virtual void derived_mark () const; @@ -37,15 +50,16 @@ 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 () +Note_spacing_engraver::Note_spacing_engraver (Context *c) + : Engraver (c) { - last_spacing_parent_context_ = 0; - last_spacing_ = 0; spacing_ = 0; + last_spacing_ = 0; } void @@ -55,21 +69,20 @@ Note_spacing_engraver::add_spacing_item (Grob *g) { spacing_ = make_item ("NoteSpacing", g->self_scm ()); } - + if (spacing_) { Pointer_group_interface::add_grob (spacing_, - ly_symbol2scm ("left-items"), - g); + ly_symbol2scm ("left-items"), + g); if (last_spacing_) - Pointer_group_interface::add_grob (last_spacing_, - ly_symbol2scm ("right-items"), - g); + Pointer_group_interface::add_grob (last_spacing_, + ly_symbol2scm ("right-items"), + g); } } - void Note_spacing_engraver::acknowledge_note_column (Grob_info gi) { @@ -85,48 +98,63 @@ 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 (last_spacing->get_object ("right-items"))) { - SCM ccol = get_property ("currentCommandColumn"); - Grob *column = unsmob_grob (ccol); - - Pointer_group_interface::add_grob (last_spacing_, - ly_symbol2scm ("right-items"), - column); + Grob *col = unsmob (get_property ("currentCommandColumn")); + + Pointer_group_interface::add_grob (last_spacing, + ly_symbol2scm ("right-items"), + 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 *sep = unsmob_grob (get_property ("breakableSeparationItem")); - if (sep) - Pointer_group_interface::add_grob (last_spacing_, - ly_symbol2scm ("right-items"), - sep); + Grob *col = unsmob (get_property ("currentCommandColumn")); + 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; } } -ADD_ACKNOWLEDGER (Note_spacing_engraver, note_column); -ADD_ACKNOWLEDGER (Note_spacing_engraver, rhythmic_grob); + +void +Note_spacing_engraver::boot () +{ + 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 */ + "" + );