2 note-spacing-engraver.cc -- implement Note_spacing_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2006--2007 Han-Wen Nienhuys <hanwen@lilypond.org>
10 #include "engraver.hh"
12 #include "grob-array.hh"
15 #include "pointer-group-interface.hh"
19 #include "translator.icc"
21 class Note_spacing_engraver : public Engraver
23 typedef map <Context*, Grob*> Last_spacing_map;
24 Last_spacing_map last_spacings_;
29 void add_spacing_item (Grob *);
30 TRANSLATOR_DECLARATIONS (Note_spacing_engraver);
33 DECLARE_ACKNOWLEDGER (rhythmic_grob);
34 DECLARE_ACKNOWLEDGER (note_column);
35 void stop_translation_timestep ();
36 virtual void finalize ();
37 virtual void derived_mark () const;
41 Note_spacing_engraver::derived_mark () const
43 for (Last_spacing_map::const_iterator i = last_spacings_.begin ();
44 i != last_spacings_.end (); i++)
45 scm_gc_mark (i->first->self_scm ());
48 Note_spacing_engraver::Note_spacing_engraver ()
55 Note_spacing_engraver::add_spacing_item (Grob *g)
59 spacing_ = make_item ("NoteSpacing", g->self_scm ());
64 Pointer_group_interface::add_grob (spacing_,
65 ly_symbol2scm ("left-items"),
69 Pointer_group_interface::add_grob (last_spacing_,
70 ly_symbol2scm ("right-items"),
77 Note_spacing_engraver::acknowledge_note_column (Grob_info gi)
79 add_spacing_item (gi.grob ());
83 Note_spacing_engraver::acknowledge_rhythmic_grob (Grob_info gi)
85 add_spacing_item (gi.grob ());
89 Note_spacing_engraver::finalize ()
91 Context *parent = context ()->get_parent_context ();
92 Grob *last_spacing = last_spacings_[parent];
95 && !unsmob_grob_array (last_spacing->get_object ("right-items")))
97 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
99 Pointer_group_interface::add_grob (last_spacing,
100 ly_symbol2scm ("right-items"),
106 Note_spacing_engraver::stop_translation_timestep ()
108 Context *parent = context ()->get_parent_context ();
109 Grob *last_spacing = last_spacings_[parent];
112 && to_boolean (get_property ("hasStaffSpacing")))
114 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
115 Pointer_group_interface::add_grob (last_spacing,
116 ly_symbol2scm ("right-items"),
122 last_spacings_[parent] = spacing_;
123 last_spacing_ = spacing_;
129 ADD_ACKNOWLEDGER (Note_spacing_engraver, note_column);
130 ADD_ACKNOWLEDGER (Note_spacing_engraver, rhythmic_grob);
132 ADD_TRANSLATOR (Note_spacing_engraver,
134 "Generate @code{NoteSpacing}, an object linking horizontal"
135 " lines for use in spacing.",