*** empty log message ***
[lilypond.git] / lily / separating-line-group-engraver.cc
blob6fefed83d44df7cb8eea19511a09e1b12b0e6c62
1 /*
2 ' separating-line-group-engraver.cc -- implement Separating_line_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "separating-group-spanner.hh"
11 #include "separation-item.hh"
12 #include "paper-column.hh"
13 #include "paper-def.hh"
14 #include "engraver.hh"
15 #include "axis-group-interface.hh"
16 #include "note-spacing.hh"
17 #include "group-interface.hh"
18 #include "accidental-placement.hh"
20 struct Spacings
22 Item * staff_spacing_;
23 Link_array<Item> note_spacings_;
25 Spacings ()
27 staff_spacing_ = 0;
30 bool empty( )const
32 return !staff_spacing_ && !note_spacings_.size ();
34 void clear () {
35 staff_spacing_ = 0;
36 note_spacings_.clear();
40 class Separating_line_group_engraver : public Engraver
42 protected:
43 Item * break_malt_;
44 Item * musical_malt_;
45 Item * last_musical_malt_;
47 Spacings current_spacings_;
48 Spacings last_spacings_;
50 Spanner * sep_span_;
52 virtual void acknowledge_grob (Grob_info);
53 virtual void initialize ();
54 virtual void finalize ();
55 virtual void stop_translation_timestep ();
56 virtual void start_translation_timestep ();
57 public:
58 TRANSLATOR_DECLARATIONS(Separating_line_group_engraver);
61 Separating_line_group_engraver::Separating_line_group_engraver ()
63 sep_span_ = 0;
64 break_malt_ = 0;
65 musical_malt_ =0;
68 void
69 Separating_line_group_engraver::initialize ()
71 sep_span_ = new Spanner (get_property ("SeparatingGroupSpanner"));
73 announce_grob(sep_span_, SCM_EOL);
74 sep_span_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn")));
77 void
78 Separating_line_group_engraver::finalize ()
80 SCM ccol = get_property ("currentCommandColumn");
81 Grob *column = unsmob_grob (ccol);
83 sep_span_->set_bound (RIGHT, unsmob_grob (ccol));
84 typeset_grob (sep_span_);
85 sep_span_ =0;
87 for (int i= 0 ; i < last_spacings_.note_spacings_.size(); i++)
89 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
90 ly_symbol2scm ("right-items" ),
91 column);
94 if(last_spacings_.staff_spacing_
95 && last_spacings_.staff_spacing_->get_column () == column)
97 last_spacings_.staff_spacing_->suicide ();
101 void
102 Separating_line_group_engraver::acknowledge_grob (Grob_info i)
104 Item * it = dynamic_cast <Item *> (i.grob_);
105 if (!it)
106 return;
107 if (it->get_parent (X_AXIS)
108 && it->get_parent (X_AXIS)
109 ->has_extent_callback_b(Axis_group_interface::group_extent_callback_proc, X_AXIS))
110 return;
113 if (to_boolean (it->get_grob_property ("no-spacing-rods")))
114 return ;
116 if (Note_spacing::has_interface (it))
118 current_spacings_.note_spacings_.push (it);
119 return ;
122 bool ib =Item::breakable_b (it);
123 Item *&p_ref_ (ib ? break_malt_
124 : musical_malt_);
126 if (!p_ref_)
128 p_ref_ = new Item (get_property ("SeparationItem"));
130 if (ib)
131 p_ref_->set_grob_property ("breakable", SCM_BOOL_T);
132 announce_grob(p_ref_, SCM_EOL);
134 if (p_ref_ == break_malt_)
136 Item *it = new Item (get_property ("StaffSpacing"));
137 current_spacings_.staff_spacing_ = it;
138 it->set_grob_property ("left-items", gh_cons (break_malt_->self_scm (), SCM_EOL));
140 announce_grob(it, SCM_EOL);
142 if (int i = last_spacings_.note_spacings_.size ())
144 for (; i--;)
145 Pointer_group_interface::add_grob (last_spacings_.note_spacings_[i],
146 ly_symbol2scm ("right-items"),
147 break_malt_);
150 else if (last_spacings_.staff_spacing_)
153 last_spacings_.staff_spacing_->set_grob_property ("right-items",
154 gh_cons (break_malt_->self_scm(), SCM_EOL));
159 if (Accidental_placement::has_interface (it))
160 Separation_item::add_conditional_item (p_ref_, it);
161 else
162 Separation_item::add_item (p_ref_,it);
165 void
166 Separating_line_group_engraver::start_translation_timestep ()
171 void
172 Separating_line_group_engraver::stop_translation_timestep ()
174 if (break_malt_)
176 Separating_group_spanner::add_spacing_unit (sep_span_, break_malt_);
177 typeset_grob (break_malt_);
179 break_malt_ =0;
182 if (Item * sp = current_spacings_.staff_spacing_)
185 TODO: should really look at the left-items of following
186 note-spacing grobs.
188 if (musical_malt_)
189 Pointer_group_interface::add_grob (sp, ly_symbol2scm ("right-items"),
190 musical_malt_);
192 typeset_grob (sp);
196 if (!current_spacings_.empty ())
198 last_spacings_ = current_spacings_;
201 current_spacings_.clear ();
203 if (musical_malt_)
205 Separating_group_spanner::add_spacing_unit (sep_span_, musical_malt_);
206 typeset_grob (musical_malt_);
209 musical_malt_ =0;
213 ENTER_DESCRIPTION(Separating_line_group_engraver,
214 /* descr */ "Generates objects for computing spacing parameters.",
215 /* creats*/ "SeparationItem SeparatingGroupSpanner",
216 /* accepts */ "",
217 /* acks */ "item-interface",
218 /* reads */ "",
219 /* write */ "");