2 separating-line-group-engraver.cc -- implement Separating_line_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 #include "separating-group-spanner.hh"
12 #include "separation-item.hh"
13 #include "paper-column.hh"
14 #include "output-def.hh"
15 #include "axis-group-interface.hh"
16 #include "note-spacing.hh"
17 #include "accidental-placement.hh"
19 #include "grob-array.hh"
20 #include "pointer-group-interface.hh"
22 #include "translator.icc"
27 vector<Item*> note_spacings_;
34 bool is_empty () const
36 return !staff_spacing_ && !note_spacings_.size ();
41 note_spacings_.clear ();
45 class Separating_line_group_engraver : public Engraver
50 Item *last_musical_item_;
52 Spacings current_spacings_;
53 Spacings last_spacings_;
57 DECLARE_ACKNOWLEDGER (item);
58 void process_music ();
59 virtual void finalize ();
60 void stop_translation_timestep ();
61 void start_translation_timestep ();
63 TRANSLATOR_DECLARATIONS (Separating_line_group_engraver);
66 Separating_line_group_engraver::Separating_line_group_engraver ()
74 Separating_line_group_engraver::process_music ()
78 sep_span_ = make_spanner ("SeparatingGroupSpanner", SCM_EOL);
80 sep_span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
84 Separating_line_group_engraver::finalize ()
89 SCM ccol = get_property ("currentCommandColumn");
90 Grob *column = unsmob_grob (ccol);
92 sep_span_->set_bound (RIGHT, unsmob_grob (ccol));
95 for (vsize i = 0; i < last_spacings_.note_spacings_.size (); i++)
97 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
98 ly_symbol2scm ("right-items"),
102 if (last_spacings_.staff_spacing_
103 && last_spacings_.staff_spacing_->get_column () == column)
104 last_spacings_.staff_spacing_->suicide ();
108 Separating_line_group_engraver::acknowledge_item (Grob_info i)
110 Item *it = dynamic_cast<Item *> (i.grob ());
113 if (it->get_parent (X_AXIS)
114 && Axis_group_interface::has_axis (it->get_parent (X_AXIS), X_AXIS))
117 if (to_boolean (it->get_property ("no-spacing-rods")))
120 if (Note_spacing::has_interface (it))
122 current_spacings_.note_spacings_.push_back (it);
126 bool ib = Item::is_non_musical (it);
127 Item *&p_ref_ (ib ? break_item_
132 p_ref_ = make_item ("SeparationItem", SCM_EOL);
136 p_ref_->set_property ("non-musical", SCM_BOOL_T);
137 context ()->set_property ("breakableSeparationItem", p_ref_->self_scm ());
140 if (to_boolean (get_property ("createSpacing"))
141 && p_ref_ == break_item_)
143 Item *it = make_item ("StaffSpacing", SCM_EOL);
144 current_spacings_.staff_spacing_ = it;
145 Pointer_group_interface::add_grob (it, ly_symbol2scm ("left-items"),
148 if (int i = last_spacings_.note_spacings_.size ())
151 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
152 ly_symbol2scm ("right-items"),
155 else if (last_spacings_.staff_spacing_)
157 SCM ri = last_spacings_.staff_spacing_->get_object ("right-items");
158 Grob_array *ga = unsmob_grob_array (ri);
161 SCM ga_scm = Grob_array::make_array ();
162 last_spacings_.staff_spacing_->set_object ("right-items", ga_scm);
163 ga = unsmob_grob_array (ga_scm);
167 ga->add (break_item_);
172 if (Accidental_placement::has_interface (it))
173 Separation_item::add_conditional_item (p_ref_, it);
175 Separation_item::add_item (p_ref_, it);
179 Separating_line_group_engraver::start_translation_timestep ()
183 context ()->unset_property (ly_symbol2scm ("breakableSeparationItem"));
189 Separating_line_group_engraver::stop_translation_timestep ()
192 Separating_group_spanner::add_spacing_unit (sep_span_, break_item_);
194 if (Item *sp = current_spacings_.staff_spacing_)
197 TODO: should really look at the left-items of following
201 Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"),
205 if (!current_spacings_.is_empty ())
206 last_spacings_ = current_spacings_;
208 current_spacings_.clear ();
211 Separating_group_spanner::add_spacing_unit (sep_span_, musical_item_);
216 ADD_ACKNOWLEDGER (Separating_line_group_engraver, item);
217 ADD_TRANSLATOR (Separating_line_group_engraver,
218 /* doc */ "Generates objects for computing spacing parameters.",
222 "SeparatingGroupSpanner "
225 /* read */ "createSpacing",
226 /* write */ "breakableSeparationItem");