2 axis-group-engraver.cc -- implement Axis_group_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "paper-column.hh"
11 #include "axis-group-interface.hh"
12 #include "engraver.hh"
13 #include "engraver-group-engraver.hh"
18 Put stuff in a Spanner with an Axis_group_interface.
19 Use as last element of a context.
21 class Axis_group_engraver : public Engraver
25 Link_array<Grob> elts_;
26 virtual void process_music ();
27 virtual void finalize ();
28 virtual void acknowledge_grob (Grob_info);
29 virtual void process_acknowledged_grobs ();
30 virtual Spanner* get_spanner () ;
31 virtual void add_element (Grob*) ;
33 TRANSLATOR_DECLARATIONS (Axis_group_engraver);
36 Axis_group_engraver::Axis_group_engraver ()
43 Axis_group_engraver::process_music ()
47 staffline_ = get_spanner ();
49 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
51 staffline_->set_bound (LEFT,it);
56 Axis_group_engraver::get_spanner ()
58 return make_spanner ("VerticalAxisGroup", SCM_EOL);
62 TODO: should we junk minimumVerticalExtent/extraVerticalExtent ?
66 Axis_group_engraver::finalize ()
71 String type = context ()->context_name ();
72 SCM dims = get_property ("verticalExtent");
74 if (is_number_pair (dims))
75 staffline_->set_extent (dims, Y_AXIS);
77 dims = get_property ("minimumVerticalExtent");
78 if (is_number_pair (dims) )
79 staffline_->set_property ("minimum-Y-extent", dims);
81 dims = get_property ("extraVerticalExtent");
82 if (is_number_pair (dims))
83 staffline_->set_property ("extra-Y-extent", dims);
85 Grob * it = unsmob_grob (get_property ("currentCommandColumn"));
87 staffline_->set_bound (RIGHT,it);
93 Axis_group_engraver::acknowledge_grob (Grob_info i)
99 maybe should check if our parent is set, because we now get a
100 cyclic parent relationship if we have two Axis_group_engravers in
103 Axis_group_engraver::process_acknowledged_grobs ()
108 for (int i=0; i < elts_.size (); i++)
110 Grob *par = elts_[i]->get_parent (Y_AXIS);
112 if (!par || !Axis_group_interface::has_interface (par))
114 if (staffline_->get_parent (Y_AXIS)
115 && staffline_->get_parent (Y_AXIS) == elts_[i])
117 String msg = _("Axis_group_engraver: vertical group already has a parent.\n"
118 "Do you have two Axis_group_engravers?\n"
119 "Killing this vertical group.");
120 staffline_->warning (msg);
121 staffline_->suicide ();
125 else if (elts_[i]->is_empty (Y_AXIS))
128 We have to do _something_, otherwise staff objects will
129 end up with System as parent.
132 elts_[i]->set_parent (staffline_, Y_AXIS);
135 add_element (elts_[i]);
142 Axis_group_engraver::add_element (Grob*e)
144 Axis_group_interface::add_element (staffline_, e);
147 /****************************************************************/
151 maybenot such a good idea after all., to put class declarations in
156 #include "hara-kiri-group-spanner.hh"
157 #include "rhythmic-head.hh"
159 class Hara_kiri_engraver : public Axis_group_engraver
162 virtual Spanner*get_spanner ();
163 virtual void acknowledge_grob (Grob_info);
164 virtual void add_element (Grob *e);
166 TRANSLATOR_DECLARATIONS (Hara_kiri_engraver);
170 Hara_kiri_engraver::add_element (Grob*e)
172 Hara_kiri_group_spanner::add_element (staffline_, e);
177 Hara_kiri_engraver::get_spanner ()
179 Spanner * sp = make_spanner ("RemoveEmptyVerticalGroup", SCM_EOL);
185 Hara_kiri_engraver::acknowledge_grob (Grob_info i)
187 Axis_group_engraver::acknowledge_grob (i);
189 && (i.grob_->internal_has_interface (ly_symbol2scm ("rhythmic-grob-interface"))
190 || i.grob_->internal_has_interface (ly_symbol2scm ("lyric-interface")))
193 Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob_);
198 Hara_kiri_engraver::Hara_kiri_engraver ()
202 ENTER_DESCRIPTION (Hara_kiri_engraver,
203 /* descr */ "Like Axis_group_engraver, but make a hara-kiri spanner, and add "
204 "interesting items (ie. note heads, lyric syllables and normal rests) ",
205 /* creats*/ "RemoveEmptyVerticalGroup",
207 /* acks */ "grob-interface",
211 ENTER_DESCRIPTION (Axis_group_engraver,
212 /* descr */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
213 /* creats*/ "VerticalAxisGroup",
215 /* acks */ "grob-interface",
216 /* reads */ "verticalExtent minimumVerticalExtent extraVerticalExtent",