2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2014 Han-Wen Nienhuys <hanwen@lilypond.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "engraver.hh"
22 #include "grob-array.hh"
25 #include "pointer-group-interface.hh"
29 #include "translator.icc"
31 class Note_spacing_engraver : public Engraver
33 typedef map <Context *, Grob *> Last_spacing_map;
34 Last_spacing_map last_spacings_;
39 void add_spacing_item (Grob *);
40 TRANSLATOR_DECLARATIONS (Note_spacing_engraver);
43 DECLARE_ACKNOWLEDGER (rhythmic_grob);
44 DECLARE_ACKNOWLEDGER (note_column);
45 void stop_translation_timestep ();
46 virtual void finalize ();
47 virtual void derived_mark () const;
51 Note_spacing_engraver::derived_mark () const
53 for (Last_spacing_map::const_iterator i = last_spacings_.begin ();
54 i != last_spacings_.end (); i++)
55 scm_gc_mark (i->first->self_scm ());
58 Note_spacing_engraver::Note_spacing_engraver ()
65 Note_spacing_engraver::add_spacing_item (Grob *g)
69 spacing_ = make_item ("NoteSpacing", g->self_scm ());
74 Pointer_group_interface::add_grob (spacing_,
75 ly_symbol2scm ("left-items"),
79 Pointer_group_interface::add_grob (last_spacing_,
80 ly_symbol2scm ("right-items"),
86 Note_spacing_engraver::acknowledge_note_column (Grob_info gi)
88 add_spacing_item (gi.grob ());
92 Note_spacing_engraver::acknowledge_rhythmic_grob (Grob_info gi)
94 add_spacing_item (gi.grob ());
98 Note_spacing_engraver::finalize ()
100 Context *parent = context ()->get_parent_context ();
101 Grob *last_spacing = last_spacings_[parent];
104 && !Grob_array::unsmob (last_spacing->get_object ("right-items")))
106 Grob *col = Grob::unsmob (get_property ("currentCommandColumn"));
108 Pointer_group_interface::add_grob (last_spacing,
109 ly_symbol2scm ("right-items"),
115 Note_spacing_engraver::stop_translation_timestep ()
117 Context *parent = context ()->get_parent_context ();
118 Grob *last_spacing = last_spacings_[parent];
121 && to_boolean (get_property ("hasStaffSpacing")))
123 Grob *col = Grob::unsmob (get_property ("currentCommandColumn"));
124 Pointer_group_interface::add_grob (last_spacing,
125 ly_symbol2scm ("right-items"),
131 last_spacings_[parent] = spacing_;
132 last_spacing_ = spacing_;
138 ADD_ACKNOWLEDGER (Note_spacing_engraver, note_column);
139 ADD_ACKNOWLEDGER (Note_spacing_engraver, rhythmic_grob);
141 ADD_TRANSLATOR (Note_spacing_engraver,
143 "Generate @code{NoteSpacing}, an object linking horizontal"
144 " lines for use in spacing.",